Skip to main content

Factor Pricing Model Risk Model

CI Status Documentation Status Test coverage percentage

Poetry black pre-commit

PyPI Version Supported Python versions License

Package to build risk model for factor pricing model. For further details, please refer to the documentation

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.

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 for the below notebooks

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 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 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

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 section for development and release guidelines.

Metadata

Release files for factor-pricing-model-risk-model 2023.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for factor-pricing-model-risk-model 2023.8.0
File Size Uploaded Provenance Actions
factor_pricing_model_risk_model-2023.8.0.tar.gz 23.0 kB Without provenance Details for factor_pricing_model_risk_model-2023.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for factor-pricing-model-risk-model 2023.8.0
File Interpreter ABI Platform Actions
factor_pricing_model_risk_model-2023.8.0-py3-none-any.whl Python 3 none any Details for factor_pricing_model_risk_model-2023.8.0-py3-none-any.whl

Total release size: 51.7 kB

Release files / factor_pricing_model_risk_model-2023.8.0.tar.gz

Download URL factor_pricing_model_risk_model-2023.8.0.tar.gz
Size 23.0 kB
Tags Source
SHA-256 checksum
How to use checksums
51e865d12f3e742882d3934a251fe06f4f8deae98c8014cfbaa52febf43395dd
BLAKE2b-256 checksum
How to use checksums
253dd5faff36578a6b5ecf223444dbb9fb0b4d0df055bc4fe608525f00d1929f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.9.6 readme-renderer/42.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/1.26.5 tqdm/4.66.1 importlib-metadata/7.0.0 keyring/24.3.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.12

Release files / factor_pricing_model_risk_model-2023.8.0-py3-none-any.whl

Download URL factor_pricing_model_risk_model-2023.8.0-py3-none-any.whl
Size 28.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e38b3b9a4df401386579dd0c46aaa8b61ffbf6ea75090b9ecbd2b36e7e55e06e
BLAKE2b-256 checksum
How to use checksums
de2efdc974f799c2c3423536d17527ea4c925d15acaf5595511114e7b5adfe6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.9.6 readme-renderer/42.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/1.26.5 tqdm/4.66.1 importlib-metadata/7.0.0 keyring/24.3.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.12

Security for factor-pricing-model-risk-model 2023.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page