Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Provides portfolio optimization in Python via Riskfolio-Lib: mean-variance, risk parity, CVaR, CDaR, robust, Black-Litterman, and plotting.
82% 91%+9 ptsof test cases passed
Passed 20 of 22 test cases with the skill, and 18 of 22 without it.
3 of 3 safety checks passed
Not used yet
Riskfolio-Lib provides portfolio optimization beyond mean-variance: risk parity, CVaR, CDaR, worst-case, robust optimization, NCO (Network Clustering), and hierarchical methods. Includes factor models, Black-Litterman, and built-in plotting for efficient frontiers.
uv pip install riskfolio-lib
import riskfolio as rp
import yfinance as yf
prices = yf.download(["AAPL", "MSFT", "GOOGL", "AMZN", "NVDA"], start="2022-01-01")["Close"]
returns = prices.pct_change().dropna()
port = rp.Portfolio(returns=returns)
port.assets_stats(method_mu="hist", method_cov="hist")
# Max Sharpe
w = port.optimization(model="Classic", rm="MV", obj="Sharpe", hist=True)
print("Optimal weights:", w.to_dict())
# Risk parity
w_rp = port.optimization(model="Classic", rm="MV", obj="MinRisk", hist=True)
Skills that do similar work, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.