Package: factor-pricing-model-risk-model
Factor Pricing Model Risk ModelPackage to build risk model for factor pricing model. For further details, please refer
to thedocumentationInstallationInstall this via pip (or your favourite package manager):pip install factor-pricing-model-risk-modelUsageThe library contains the pipelines to build the risk model. You can
run the pipelines interactively in Jupyter Notebook.importfpm_risk_modelObjectiveThe 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.ExamplesFor end-to-end examples, please refer toexamplesfor the below notebooksCryptocurrency Statistical Risk ModelNumPy Backend EngineFeaturesBasically, there are three major features provided in the libraryFactor risk model creationCovariance estimatorTracking risk model accuracyFactor risk modelThe 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_exposuresThen, 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 thesectionin the documentation.Covariance estimationCurrently, 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 estimatorCovarianceEstimator(orRollingCovarianceEstimatorin a rolling basis) provides advanced
features, including covariance shrinkage and variance adjustment.
The following shrinkage methods are supportedConstantLedoit 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 accuracyestimator.cov(volatility=another_estimated_vol)For further details, please refer to thesectionin the documentation.Tracking risk model accuracyThe library also focuses on the predictability interpretation of the risk
model, and provides a few benchmarks to examine the following metricsBiasValue at Risk (VaR)For example, to examine the bias statistics of a risk model regarding
an equally weighted portfolio (of which its weights are denoted asweights),
pass the instrument observed returns (denoted asreturns), 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
  ...
)RoadmapThe following major features will be enhancedFactor exposures computation from factor returns (Q3 2023)Shrinking covariance (Q3 2023)Multi-asset class factor model (Q4 2023)Fundamental type risk model (Q4 2023)ContributionAll levels of contributions are welcomed. Please refer to thecontributingsection for development and release guidelines.