Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Implements portfolio optimization in Python, covering mean-variance, Black-Litterman, CVaR, risk parity, HRP and CLA methods.
78% 96%+17 ptsof test cases passed
Passed 22 of 23 test cases with the skill, and 18 of 23 without it.
What is the preferred package manager installation command for installing PyPortfolioOpt?
The installation command specifies uv pip install PyPortfolioOpt.
3 of 3 safety checks passed
PyPortfolioOpt implements mean-variance optimization, Black-Litterman, CVaR optimization, risk parity, Hierarchical Risk Parity (HRP), and CLA. Handles asset allocation with factor models and ex-ante risk decomposition.
uv pip install PyPortfolioOpt
import yfinance as yf
from pypfopt import EfficientFrontier, risk_models, expected_returns
prices = yf.download(["AAPL", "MSFT", "GOOGL"], start="2022-01-01")["Close"]
mu = expected_returns.mean_historical_return(prices)
S = risk_models.sample_cov(prices)
ef = EfficientFrontier(mu, S)
weights = ef.max_sharpe()
print(ef.clean_weights())
perf = ef.portfolio_performance()
print(f"Return: {perf[0]:.2%}, Vol: {perf[1]:.2%}, Sharpe: {perf[2]:.2f}")
from pypfopt import HRPOpt
returns = prices.pct_change().dropna()
hrp = HRPOpt(returns)
weights = hrp.optimize()
Skills that do similar work, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.