dcajasn/Riskfolio-Lib 是一个托管在 GitHub 上的开源项目,主要使用 C++ 编写,采用 BSD 3-Clause "New" or "Revised" License 许可证,目前获得 4.6k 个 Star、714 次 Fork。
仓库全名
dcajasn/Riskfolio-Lib
开源许可证
BSD 3-Clause "New" or "Revised" License
Star 数
4.6k
Fork 数
714
未关闭 Issue
9
README 摘要
Riskfolio-Lib Portfolio Optimization in Python, Easy for Everyone. Description Riskfolio-Lib is a library for making 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…
Portfolio Optimization in Python, Easy for Everyone.
Description
Riskfolio-Lib is a library for making 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 26 convex risk measures:
Dispersion Risk Measures:
Standard Deviation.
Square Root Kurtosis.
p-th Root Even Moment of order 2p.
Mean Absolute Deviation (MAD).
Gini Mean Difference (GMD).
Conditional Value at Risk Range.
Tail Gini Range.
Entropic Value at Risk Range.
Relativistic Value at Risk Range.
Range.
Downside Risk Measures:
Semi Standard Deviation.
Square Root Semi Kurtosis.
p-th Root Even Semi Moment of order 2p.
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 22 convex risk measures:
Dispersion Risk Measures:
Standard Deviation.
Square Root Kurtosis.
p-th Root Even Moment of order 2p.
Mean Absolute Deviation (MAD).
Gini Mean Difference (GMD).
Conditional Value at Risk Range.
Tail Gini Range.
Entropic Value at Risk Range.
Relativistic Value at Risk Range.
Downside Risk Measures:
Semi Standard Deviation.
Square Root Semi Kurtosis.
p-th Root Even Semi Moment of order 2p.
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 37 risk measures using naive risk parity:
Dispersion Risk Measures:
Standard Deviation.
Variance.
Square Root Kurtosis.
2p-th Root of Even Moment of Order 2p.
Mean Absolute Deviation (MAD).
Gini Mean Difference (GMD).
Value at Risk Range.
Conditional Value at Risk Range.
Tail Gini Range.
Entropic Value at Risk Range.
Relativistic Value at Risk Range.
Range.
Downside Risk Measures:
Semi Standard Deviation.
Fourth Root Semi Kurtosis.
2p-th Root Even Semi Moment of order 2p.
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:
The docs include a tutorial
with examples that shows the capacities of Riskfolio-Lib.
Choosing a Solver
Due to Riskfolio-Lib is based on CVXPY, Riskfolio-Lib can use the same solvers available for CVXPY. The list of solvers compatible with CVXPY is available in Choosing a solver section of CVXPY’s documentation. However, to select an adequate solver for each risk measure we can use the following table that specifies which type of programming technique is used to model each risk measure.
Risk Measure
LP
QP
SOCP
SDP
EXP
POW
Variance (MV)
X
X*
Mean Absolute Deviation (MAD)
X
Gini Mean Difference (GMD)
X**
Semi Variance (MSV)
X
Kurtosis (KT)
X
Even Moment (EM)
X**
Semi Kurtosis (SKT)
X
Even Semi Moment (ESM)
X**
First Lower Partial Moment (FLPM)
X
Second Lower Partial Moment (SLPM)
X
Conditional Value at Risk (CVaR)
X
Tail Gini (TG)
X**
Entropic Value at Risk (EVaR)
X**
Relativistic Value at Risk (RLVaR)
X**
Worst Realization (WR)
X
CVaR Range (CVRG)
X
Tail Gini Range (TGRG)
X**
EVaR Range (EVRG)
X**
RLVaR Range (RVRG)
X**
Range (RG)
X
Average Drawdown (ADD)
X
Ulcer Index (UCI)
X
Conditional Drawdown at Risk (CDaR)
X
Entropic Drawdown at Risk (EDaR)
X**
Relativistic Drawdown at Risk (RLDaR)
X**
Maximum Drawdown (MDD)
X
(*) When SDP graph theory constraints or risk contribution constraints are included. In the case integer programming graph theory constraints are included, the model assume the SOCP formulation.
(**) For these models is highly recommended to use MOSEK as solver, due to in some cases CLARABEL cannot find a solution and SCS takes too much time to solve them.
LP - Linear Programming refers to problems with a linear objective function and linear constraints.
QP - Quadratic Programming refers to problems with a quadratic objective function and linear constraints.
SOCP - Second Order Cone Programming refers to problems with second-order cone constraints.
SDP - Semidefinite Programming refers to problems with positive semidefinite constraints.
EXP - refers to problems with exponential cone constraints.
POW - refers to problems with 3-dimensional power cone constraints.
The latest stable release (and older versions) can be installed from PyPI:
pip install riskfolio-lib
Contributing
Contributions of all kinds are welcome and greatly appreciated. Riskfolio-Lib is an
independent open-source project, and community support plays a vital role in its
continued development, maintenance, and growth.
Financial Support
If you would like to support the long-term sustainability of Riskfolio-Lib, you can
contribute financially in any of the following ways:
Hire me for consulting services through my LinkedIn or contact me by Email.
Other Ways to Contribute
You can also contribute directly to the project by:
Improve and expand the documentation.
Enhance the performance and efficiency of existing code.
Implement new optimization objectives, risk measures, robust estimation techniques, and
other portfolio optimization features.
Develop additional examples and tutorials using Jupyter notebooks.
Help expand the test suite by writing and improving tests with pytest.
Suggest journal articles, research papers, blog posts, or other resources related to
portfolio optimization, quantitative finance, machine learning or econometrics that
could inspire new features or improvements in Riskfolio-Lib.
Whether you contribute code, documentation, examples, tests, ideas, feedback, financial
support, or simply help spread the word about Riskfolio-Lib, your support helps make the
project a better tool for the quantitative finance community.
Citing
If you use Riskfolio-Lib for published work, please use the following BibTeX entry:
@misc{riskfolio,
author = {Dany Cajas},
title = {Riskfolio-Lib (7.4)},
year = {2026},
url = {https://github.com/dcajasn/Riskfolio-Lib},
}
RoadMap
The plan for this module is to add more functions that will be very useful
to asset managers.
评论