Actively developed

Riskfolio-Lib guide

Riskfolio-Lib is the most comprehensive open-source toolbox for portfolio optimization in Python.

Last reviewed

Quick answer

Riskfolio-Lib is a Python library for strategic asset allocation built on CVXPY. It supports mean-risk optimization with more than 20 convex risk measures (variance, CVaR, CDaR, EVaR, drawdown measures), risk parity, hierarchical methods (HRP, HERC, NCO), Black-Litterman variants, constraints and detailed plots.

Riskfolio-Lib at a glance

Category
Portfolio optimization & analytics
Language
Python
License
BSD-3-Clause
Does
Performance analytics, Optimization
Markets
Stocks, ETFs, Crypto
Best for
Allocation problems that need tail-risk or drawdown-aware objectives and real constraints.
In AlgoGP
Use the exported strategy object from your own code

Pick it if

Allocation problems that need tail-risk or drawdown-aware objectives and real constraints.

Watch out for

Steeper learning curve.

Riskfolio-Lib strengths and limitations

Strengths

  • Many risk measures and models.
  • Constraints on assets, groups and factors.
  • Rich visualization.

Limitations

  • Steeper learning curve.
  • Requires a good solver for larger problems.

Riskfolio-Lib example

pip install riskfolio-lib
Install
import riskfolio as rp
port = rp.Portfolio(returns=returns)
port.assets_stats(method_mu="hist", method_cov="hist")
w = port.optimization(model="Classic", rm="CVaR", obj="MinRisk")
print(w.T)
Minimum-CVaR portfolio.

Use Riskfolio-Lib with AlgoGP

AlgoGP does not add Riskfolio-Lib to projects automatically yet, but nothing stops you using them together. Every AlgoGP project exports plain Python with a framework-neutral strategy object, so you can call it from Riskfolio-Lib yourself.

  1. 1

    Design and backtest in AlgoGP

    Describe the idea to the copilot and backtest it on AlgoGP’s normalized history.

  2. 2

    Add any bridge to get the adapter core

    Adding a bridged framework (for example Backtrader) writes frameworks/algogp_bridge.py, whose StrategyBridge.on_bar() returns the orders the strategy wants.

  3. 3

    Call it from Riskfolio-Lib

    Feed Riskfolio-Lib’s bars to StrategyBridge, place the returned orders with Riskfolio-Lib, and report fills back with sync().

Riskfolio-Lib: frequently asked questions

What is CDaR?

Conditional drawdown at risk: the average of the worst drawdowns beyond a confidence level.

Riskfolio-Lib alternatives

Independent guide. AlgoGP is not affiliated with Riskfolio-Lib. Features, licenses and maintenance change; check the official documentation. Nothing here is investment advice.

Build a strategy