dcajasn / Riskfolio-Lib

Portfolio Optimization and Quantitative Strategic Asset Allocation in Python

Home Page:https://riskfolio-lib.readthedocs.io/en/latest/examples.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Riskfolio-Lib

Quantitative Strategic Asset Allocation, Easy for Everyone.

Buy Me a Coffee at ko-fi.com

GitHub stars Downloads Documentation Status GitHub license Binder

Star History Chart

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.

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
Semi Kurtosis (SKT) 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**
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 are included. In the case of integer programming graph theory constraints, 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.

Dependencies

Riskfolio-Lib supports Python 3.8|.

Installation requires:

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 (6.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.

About

Portfolio Optimization and Quantitative Strategic Asset Allocation in Python

https://riskfolio-lib.readthedocs.io/en/latest/examples.html

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:C++ 80.8%Language:Fortran 8.3%Language:Python 4.6%Language:C 2.6%Language:CMake 2.3%Language:Cuda 1.0%Language:Shell 0.2%Language:HTML 0.1%Language:JavaScript 0.1%Language:XSLT 0.0%Language:CSS 0.0%Language:R 0.0%Language:Makefile 0.0%