https://github.com/factorpricingmodel/factor-pricing-model-risk-model
Package to build risk model for factor pricing model
https://github.com/factorpricingmodel/factor-pricing-model-risk-model
factor-model quantitative-finance risk-model risk-models
Last synced: 5 months ago
JSON representation
Package to build risk model for factor pricing model
- Host: GitHub
- URL: https://github.com/factorpricingmodel/factor-pricing-model-risk-model
- Owner: factorpricingmodel
- License: mit
- Created: 2022-11-24T11:16:20.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-26T08:31:50.000Z (almost 2 years ago)
- Last Synced: 2025-11-09T05:19:39.281Z (7 months ago)
- Topics: factor-model, quantitative-finance, risk-model, risk-models
- Language: Python
- Homepage: https://factor-pricing-model-risk-model.readthedocs.io/en/latest/index.html
- Size: 45.6 MB
- Stars: 27
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Factor Pricing Model Risk Model
Package to build risk model for factor pricing model. For further details, please refer
to the [documentation](https://factor-pricing-model-risk-model.readthedocs.io/en/latest/)
## Installation
Install this via pip (or your favourite package manager):
`pip install factor-pricing-model-risk-model`
## Usage
The library contains the pipelines to build the risk model. You can
run the pipelines interactively in Jupyter Notebook.
```python
import fpm_risk_model
```
## Objective
The project provides frameworks to create multi-factor risk
model on an "enterprise-like" level.
The target audiences are researchers, developers and fund
management looking for flexibility in creating risk models.
## Examples
For end-to-end examples, please refer to [examples](https://github.com/factorpricingmodel/factor-pricing-model-risk-model/tree/main/examples) for the below notebooks
- [Cryptocurrency Statistical Risk Model](https://colab.research.google.com/github/factorpricingmodel/factor-pricing-model-risk-model/blob/main/examples/notebook/crypto_statistical_risk_model.ipynb)
- [NumPy Backend Engine](https://colab.research.google.com/github/factorpricingmodel/factor-pricing-model-risk-model/blob/main/examples/notebook/numpy_backend_engine.ipynb)
- [Empirical Analysis of Alpha Sizing Rules in Cryptocurrency](https://colab.research.google.com/github/factorpricingmodel/factor-pricing-model-risk-model/blob/main/examples/notebook/crypto_empirical_analysis_alpha_sizing_rules.ipynb)
## Features
Basically, there are three major features provided in the library
- Factor risk model creation
- Covariance estimator
- Tracking risk model accuracy
## Factor risk model
The factor risk model is created by fitting instrument returns (which
could be weekly, daily, or even higher granularity) and other related
parameters into the model, and its products are factor exposures,
factor returns, factor covariance, and residual returns (idiosyncratic
returns).
For example, to create a simple statistical PCA risk model,
```
from fpm_risk_model.statistics import PCA
risk_model = PCA(n_components=5)
risk_model.fit(X=returns)
# Get fitted factor exposures
risk_model.factor_exposures
```
Then, the risk model can be transformed by the returns of a
larger homogeneous universe.
```
risk_model.transform(y=model_returns)
```
For further details, please refer to the [section](https://factor-pricing-model-risk-model.readthedocs.io/en/latest/risk_model/factor_risk_model.html) in the documentation.
## Covariance estimation
Currently, covariance estimation is supported in factor risk model,
and the estimation depends on the fitted results.
For example, a risk model transformed by model universe returns can
derive the pairwise covariance and correlation for the model universe.
```
risk_model.transform(y=model_returns)
cov = risk_model.cov()
corr = risk_model.corr()
```
Alternatively, covariance estimator `CovarianceEstimator`
(or `RollingCovarianceEstimator` in a rolling basis) provides advanced
features, including covariance shrinkage and variance adjustment.
The following shrinkage methods are supported
- Constant
- Ledoit Wolf shrinkage (Q3 2023)
- Oracle Approximating shrinkage (Q3 2023)
For example, to construct a rolling covariance estimator with constant
shrinkage delta 0.2,
```
from fpm_risk_model import RollingCovarianceEstimator
estimator = RollingCovarianceEstimator(
rolling_risk_model,
shrinkage_method="constant",
delta=0.2
)
```
then the covariance can be computed with the rolling risk model and
volatilities with better forecasting accuracy
```
estimator.cov(volatility=another_estimated_vol)
```
For further details, please refer to the [section](https://factor-pricing-model-risk-model.readthedocs.io/en/latest/risk_model/covariance.html) in the documentation.
## Tracking risk model accuracy
The library also focuses on the predictability interpretation of the risk
model, and provides a few benchmarks to examine the following metrics
- [Bias](https://factor-pricing-model-risk-model.readthedocs.io/en/latest/accuracy/bias.html)
- [Value at Risk (VaR)](https://factor-pricing-model-risk-model.readthedocs.io/en/latest/accuracy/value_at_risk.html)
For example, to examine the bias statistics of a risk model regarding
an equally weighted portfolio (of which its weights are denoted as `weights`),
pass the instrument observed returns (denoted as `returns`), and either
a rolling risk model (to compute the volatility forecast) or a time series
of volatility forecasts.
```
from fpm_risk_model.accuracy import compute_bias_statistics
compute_bias_statistics(
X=returns,
weights=weights,
window=window
...
)
```
## Roadmap
The following major features will be enhanced
- Factor exposures computation from factor returns (Q3 2023)
- Shrinking covariance (Q3 2023)
- Multi-asset class factor model (Q4 2023)
- Fundamental type risk model (Q4 2023)
## Contribution
All levels of contributions are welcomed. Please refer to the [contributing](https://factor-pricing-model-risk-model.readthedocs.io/en/latest/contributing.html)
section for development and release guidelines.