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-libimport 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)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
Design and backtest in AlgoGP
Describe the idea to the copilot and backtest it on AlgoGP’s normalized history.
- 2
Add any bridge to get the adapter core
Adding a bridged framework (for example Backtrader) writes
frameworks/algogp_bridge.py, whoseStrategyBridge.on_bar()returns the orders the strategy wants. - 3
Call it from Riskfolio-Lib
Feed Riskfolio-Lib’s bars to
StrategyBridge, place the returned orders with Riskfolio-Lib, and report fills back withsync().
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
- PyPortfolioOptPythonPortfolio optimization in Python: mean-variance, Black-Litterman, hierarchical risk parity, efficient frontiers and discrete allocation.
- QuantStatsPythonPortfolio analytics for quants: Sharpe, Sortino, drawdowns, monthly returns and full HTML tear sheets from a returns series in one line.
- btPythonFlexible Python framework for portfolio-level backtests built from composable algos: select, weigh and rebalance on a schedule.
- QlibPythonMicrosoft’s AI-oriented quant platform: data processing, alpha factor research, ML models (LightGBM to Transformers), backtesting and RD-Agent.
Independent guide. AlgoGP is not affiliated with Riskfolio-Lib. Features, licenses and maintenance change; check the official documentation. Nothing here is investment advice.