Portfolio Optimization and Quantitative Strategic Asset Allocation in Python
Project description
Riskfolio-Lib
Quantitative Strategic Asset Allocation, Easy for Everyone.
Description
Riskfolio-Lib is a library for making quantitative strategic asset allocation or portfolio optimization in Python made in Peru 🇵🇪. Its objective is to help students, academics and practitioners to build investment portfolios based on mathematically complex models with low effort. It is built on top of cvxpy and closely integrated with pandas data structures.
Some of key functionalities that Riskfolio-Lib offers:
-
Mean Risk and Logarithmic Mean Risk (Kelly Criterion) Portfolio Optimization with 4 objective functions:
- Minimum Risk.
- Maximum Return.
- Maximum Utility Function.
- Maximum Risk Adjusted Return Ratio.
-
Mean Risk and Logarithmic Mean Risk (Kelly Criterion) Portfolio Optimization with 22 convex risk measures:
Dispersion Risk Measures:
- Standard Deviation.
- Square Root Kurtosis.
- Mean Absolute Deviation (MAD).
- Gini Mean Difference (GMD).
- Conditional Value at Risk Range.
- Tail Gini Range.
- Range.
Downside Risk Measures:
- Semi Standard Deviation.
- Square Root Semi Kurtosis.
- First Lower Partial Moment (Omega Ratio).
- Second Lower Partial Moment (Sortino Ratio).
- Conditional Value at Risk (CVaR).
- Tail Gini.
- Entropic Value at Risk (EVaR).
- Relativistic Value at Risk (RLVaR).
- Worst Case Realization (Minimax).
Drawdown Risk Measures:
- Average Drawdown for uncompounded cumulative returns.
- Ulcer Index for uncompounded cumulative returns.
- Conditional Drawdown at Risk (CDaR) for uncompounded cumulative returns.
- Entropic Drawdown at Risk (EDaR) for uncompounded cumulative returns.
- Relativistic Drawdown at Risk (RLDaR) for uncompounded cumulative returns.
- Maximum Drawdown (Calmar Ratio) for uncompounded cumulative returns.
-
Risk Parity Portfolio Optimization with 18 convex risk measures:
Dispersion Risk Measures:
- Standard Deviation.
- Square Root Kurtosis.
- Mean Absolute Deviation (MAD).
- Gini Mean Difference (GMD).
- Conditional Value at Risk Range.
- Tail Gini Range.
Downside Risk Measures:
- Semi Standard Deviation.
- Square Root Semi Kurtosis.
- First Lower Partial Moment (Omega Ratio)
- Second Lower Partial Moment (Sortino Ratio)
- Conditional Value at Risk (CVaR).
- Tail Gini.
- Entropic Value at Risk (EVaR).
- Relativistic Value at Risk (RLVaR).
Drawdown Risk Measures:
- Ulcer Index for uncompounded cumulative returns.
- Conditional Drawdown at Risk (CDaR) for uncompounded cumulative returns.
- Entropic Drawdown at Risk (EDaR) for uncompounded cumulative returns.
- Relativistic Drawdown at Risk (RLDaR) for uncompounded cumulative returns.
-
Hierarchical Clustering Portfolio Optimization: Hierarchical Risk Parity (HRP) and Hierarchical Equal Risk Contribution (HERC) with 24 risk measures using naive risk parity:
Dispersion Risk Measures:
- Standard Deviation.
- Variance.
- Fourth Root Kurtosis.
- Mean Absolute Deviation (MAD).
- Range.
- Conditional Value at Risk Range.
- Tail Gini Range.
Downside Risk Measures:
- Semi Standard Deviation.
- Fourth Root Semi Kurtosis.
- First Lower Partial Moment (Omega Ratio).
- Second Lower Partial Moment (Sortino Ratio).
- Value at Risk (VaR).
- Conditional Value at Risk (CVaR).
- Tail Gini.
- Entropic Value at Risk (EVaR).
- Relativistic Value at Risk (RLVaR).
- Worst Case Realization (Minimax).
Drawdown Risk Measures:
- Average Drawdown for compounded and uncompounded cumulative returns.
- Ulcer Index for compounded and uncompounded cumulative returns.
- Drawdown at Risk (DaR) for compounded and uncompounded cumulative returns.
- Conditional Drawdown at Risk (CDaR) for compounded and uncompounded cumulative returns.
- Entropic Drawdown at Risk (EDaR) for compounded and uncompounded cumulative returns.
- Relativistic Drawdown at Risk (RLDaR) for compounded and uncompounded cumulative returns.
- Maximum Drawdown (Calmar Ratio) for compounded and uncompounded cumulative returns.
-
Nested Clustered Optimization (NCO) with four objective functions and the available risk measures to each objective:
- Minimum Risk.
- Maximum Return.
- Maximum Utility Function.
- Equal Risk Contribution.
-
Worst Case Mean Variance Portfolio Optimization.
-
Relaxed Risk Parity Portfolio Optimization.
-
Ordered Weighted Averaging (OWA) Portfolio Optimization.
-
Portfolio optimization with Black Litterman model.
-
Portfolio optimization with Risk Factors model.
-
Portfolio optimization with Black Litterman Bayesian model.
-
Portfolio optimization with Augmented Black Litterman model.
-
Portfolio optimization with constraints on tracking error and turnover.
-
Portfolio optimization with short positions and leveraged portfolios.
-
Portfolio optimization with constraints on number of assets and number of effective assets.
-
Portfolio optimization with constraints based on graph information.
-
Tools to build efficient frontier for 22 convex risk measures.
-
Tools to build linear constraints on assets, asset classes and risk factors.
-
Tools to build views on assets and asset classes.
-
Tools to build views on risk factors.
-
Tools to build risk contribution constraints per asset classes.
-
Tools to build bounds constraints for Hierarchical Clustering Portfolios.
-
Tools to calculate risk measures.
-
Tools to calculate risk contributions per asset.
-
Tools to calculate uncertainty sets for mean vector and covariance matrix.
-
Tools to calculate assets clusters based on codependence metrics.
-
Tools to estimate loadings matrix (Stepwise Regression and Principal Components Regression).
-
Tools to visualizing portfolio properties and risk measures.
-
Tools to build reports on Jupyter Notebook and Excel.
-
Option to use commercial optimization solver like MOSEK or GUROBI for large scale problems.
Documentation
Online documentation is available at Documentation.
The docs include a tutorial with examples that shows the capacities of Riskfolio-Lib.
Dependencies
Riskfolio-Lib supports Python 3.7+.
Installation requires:
- numpy >= 1.17.0
- scipy >= 1.1.0
- pandas >= 1.0.0
- matplotlib >= 3.3.0
- clarabel >= 0.6.0
- cvxpy >= 1.0.15
- scikit-learn >= 1.0.0
- statsmodels >= 0.10.1
- arch >= 4.15
- xlsxwriter >= 1.3.7
- networkx >= 2.5.1
- astropy >= 4.3.1
- pybind11 >= 2.10.1
Installation
The latest stable release (and older versions) can be installed from PyPI:
pip install riskfolio-lib
Citing
If you use Riskfolio-Lib for published work, please use the following BibTeX entry:
@misc{riskfolio,
author = {Dany Cajas},
title = {Riskfolio-Lib (5.0.0)},
year = {2024},
url = {https://github.com/dcajasn/Riskfolio-Lib},
}
Development
Riskfolio-Lib development takes place on Github: https://github.com/dcajasn/Riskfolio-Lib
Consulting Fees
Riskfolio-Lib is an open-source project, however due it's a project that is not financed for any institution, I started charging for consultancies that are not related to errors in source code. Our fees are as follows:
- $ 25 USD (United States Dollars) per question that doesn't require to check code.
- $ 50 USD to check a small size script or code (less than 200 lines of code). The fee of the solution depends on the complexity of the solution:
- $ 50 USD for simple errors in scripts (modify less than 10 lines of code).
- For most complex errors the fee depends on the complexity of the solution but the fee is $ 150 USD per hour.
- $ 100 USD to check a medium size script or code (between 201 and 600 lines of code). The fee of the solution depends on the complexity of the solution:
- $ 50 USD for simple errors in scripts (modify less than 10 lines of code).
- For most complex errors the fee depends on the complexity of the solution but the fee is $ 150 USD per hour.
- For large size script or code (more than 600 lines of code) the fee is variable depending on the size of the code. The fee of the solution depends on the complexity of the solution:
- $ 50 USD for simple errors in scripts (modify less than 10 lines of code).
- For most complex errors the fee depends on the complexity of the solution but the fee is $ 150 USD per hour.
All consulting must be paid in advance.
You can contact me through:
You can pay using one of the following channels:
RoadMap
The plan for this module is to add more functions that will be very useful to asset managers.
- Add more functions based on suggestion of users.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for Riskfolio_Lib-5.0.1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0392e838150a3f307ce3d55414dcb01d61ac1833b617ec893df86468fb55500e |
|
MD5 | 535187f546b6be54af859dee89003934 |
|
BLAKE2b-256 | 7c384f29d121d7358c68d96da153fdd5b351c9fa00b3d8c5af14c9b4009f8250 |
Hashes for Riskfolio_Lib-5.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7eebca130ebefe34897dd5806ae1bd77d1a9183b52131a27eaf8887037573aa9 |
|
MD5 | b421a8c6079e015e93b10b04fd388307 |
|
BLAKE2b-256 | 1a0015247ac574ad9b19558e77b98e5b8fabe208b8d25550052546050fcc6174 |
Hashes for Riskfolio_Lib-5.0.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43caff762b87cc9bf334b371c03797492cca5e90f2ac884e00e94a61122f129f |
|
MD5 | 28d921c4ea0e46cfdfa207dd484cdd2b |
|
BLAKE2b-256 | a8bf059806651254552b5dd85cfb50a7217292d03cf1c6b8d0d00ecf9adcba69 |
Hashes for Riskfolio_Lib-5.0.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ea79ca95040b2e31995b2f7267fb9b8ef6e980ac4666f2b7ef4f3e366abb215 |
|
MD5 | 888e33d59fca5c6ff0cbb3847f4df81e |
|
BLAKE2b-256 | 283c4f220c8e847b99610b102d96dbacadcfc09fc8ccf30a0a1fe1593d0bc9a1 |
Hashes for Riskfolio_Lib-5.0.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3de4cbab076c8b56bbb2dbd22c871c0f97a9d09640bc225b1072195605322367 |
|
MD5 | 883fcbcd6f5df706459cebd69e94a101 |
|
BLAKE2b-256 | a92b351dd44748be87dab7679db6f6684671c39a2bd7133d36f8c7e1e593ca7b |
Hashes for Riskfolio_Lib-5.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e318b3d5dfbd5eb994a0285539ba9422134b54bef1936b04b8b0c6e0a76782c |
|
MD5 | ab365fecba11570bbae7d3a96bfe533e |
|
BLAKE2b-256 | 80b71ad629ada8361a2070b3739cfc7f49c51a2a36fba1e3726bc4c53a0d7ae7 |
Hashes for Riskfolio_Lib-5.0.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2aea2916c035da9189947e8e40601178c81391863607e0efa6c3aaf8a0229a30 |
|
MD5 | 53982c16f4389c57bd1a55a1880c14b3 |
|
BLAKE2b-256 | 9c03186cdf44168d3904e9bb36a6a9b8630df35c59775ebfa88a78860cdd0435 |
Hashes for Riskfolio_Lib-5.0.1-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fae7ff15563957d9cf6ffe9a5ea378c0b317f0583b31446a79caac6baf6e9b05 |
|
MD5 | e2d6ede0c6b23c5c6120cf10f7f7a11f |
|
BLAKE2b-256 | 01a871d794b9f89211153c6afa53c936e34e15f0973fa8feff5dedcf98f7eabc |
Hashes for Riskfolio_Lib-5.0.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 044cdf85abf30519a9a244c174bf10063d4fbb405d2ae01c0eeb9b7ea5727ed6 |
|
MD5 | 9f78b929591a0447ab3bf37a01da856c |
|
BLAKE2b-256 | 7441db7eaf4b31c3ef5c678f0fa3232b26c57c3105c13015b9fbb60f6768142a |
Hashes for Riskfolio_Lib-5.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00961ea7c1bda58f4ad29b280d78ba7af633ef864ba0020a56862af207de03a7 |
|
MD5 | 6cc85e607cbd8a5cbba12442e6139cb4 |
|
BLAKE2b-256 | ae82a8ac02d0839f8a42cc5d64377f168ad6a65417cf0afc758f592b0d6b9ac2 |
Hashes for Riskfolio_Lib-5.0.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ae588327d61d872d2d6e5d183c00da1b3820148db52ced0a22d4a4997f82ee1 |
|
MD5 | 9b67e43eaa62462e8b47ce417fb7603a |
|
BLAKE2b-256 | 03effab1eec0124de56ba8ea46e902bd2e0fced2269cd2de39a8a391e939944d |
Hashes for Riskfolio_Lib-5.0.1-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f636a0cb86ea2bb6e0af41571ef7e621ae0da39e68ceec3713726949258b12d |
|
MD5 | 0f532a66c4201919c4e338c93f7481de |
|
BLAKE2b-256 | fd479e867e59fbbd51742d2cfbdd193ea0b8dbf6dd73c610b6d84cffc407d6ee |
Hashes for Riskfolio_Lib-5.0.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccc78c5664ff2cfa6bdb66617e811d7562f9850edd9dde600d42203f36d5fb6a |
|
MD5 | afe7eb3622b8bda3f1aa280df1c7bb60 |
|
BLAKE2b-256 | b466c0a19d7e15f490c99d1711ccda31463df34a021482e8b2829f71cb9e59bc |
Hashes for Riskfolio_Lib-5.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32d27ba02dae5fd7339999b1399238d8f7a44f7ae1b501c890bd3d21cd92347c |
|
MD5 | 504b02f1f21f99226afc7d3069cdd323 |
|
BLAKE2b-256 | 1613c87a596d2399f6534162ab9ad2bb2a89dd1445ccb58ceeba15977d2b5d26 |
Hashes for Riskfolio_Lib-5.0.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e76c4183a3f19427e3869be4277ab0288bfdaede48f48707ebf205970973b7d5 |
|
MD5 | 800e5f22348562aa698fcecbead9d9f4 |
|
BLAKE2b-256 | 1f2bc9b907483a563b4de6234de39e94a3d139bacfa6805ca24a7158ed1c68bc |
Hashes for Riskfolio_Lib-5.0.1-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbd7659ebdbca64669f1b768121a1437e9f7ad094b9ab334c1ed8b61d5a7734a |
|
MD5 | 3409789c8a4306ee9fbf4f9eb33646ef |
|
BLAKE2b-256 | 20ac024d55c460cc0af52c26a18fe6af88d08febc75e20f4df94846c1a604e5a |
Hashes for Riskfolio_Lib-5.0.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2d5262bd8aa3a67e101ed4a59102dac383575b62a55338ef81dd5f7248f8ede |
|
MD5 | 7e21582253add7f3cce683dfdfa24788 |
|
BLAKE2b-256 | 8f750ebe05df7770a28470cc21796d50680edcb257101f403d6386e07c48c163 |
Hashes for Riskfolio_Lib-5.0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91a46de1caee9028db2c1ac2af5d49b617b6ecc55ab674fa96a26d0ad811fab1 |
|
MD5 | 69a37ef42e61d2e431fb05e66475bdd3 |
|
BLAKE2b-256 | be5b1a7ede2833a29dda962cd366a70789ddb90ad8506f4f652d17476bbcc61b |
Hashes for Riskfolio_Lib-5.0.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5882c068350309e9c80ee8ca5c172ce97befda3499fb534c30194c56eac9629c |
|
MD5 | ed066ae3ca183c3bc22066a916344b3b |
|
BLAKE2b-256 | 9feeea2d3ea485c3765eeeff2f4d15c1d20935a96d494575f8f90c31a9312082 |