PyPortfolioOpt — Portfolio Optimization
A Python library implementing classical and modern portfolio optimization: efficient frontier, Black-Litterman, HRP, and advanced risk models.
PyPortfolioOpt
PyPortfolioOpt is a popular Python library for financial portfolio optimization and risk management. It implements the full workflow — from expected-returns and covariance estimation through mean-variance optimization — giving quants and researchers a clean, well-documented toolkit for constructing risk-aware portfolios.
Key features
- Classical efficient-frontier (mean-variance) optimization with custom constraints
- Robust covariance/risk models: Ledoit-Wolf shrinkage, semicovariance, EWMA
- Black-Litterman allocation blending investor views with market equilibrium
- Hierarchical Risk Parity (HRP) and CVaR/CDaR objective functions
- Post-processing to convert continuous weights into discrete share allocations
A typical flow estimates expected_returns and a risk_model, then uses EfficientFrontier to maximize Sharpe or minimize volatility subject to constraints, returning portfolio weights ready to trade or analyze.
Curated mirror of the open-source PyPortfolioOpt (MIT). Get it from the source.
Compromise signals — malicious or tampered code (leaked secrets, backdoors, a dropped executable) — reduce the score, and known dependency CVEs carry a bounded penalty (they warrant review but never QUARANTINE — update the dependency to clear). Other dangerous-by-capability traits are risk surface, expected for some capabilities. Every finding is mapped to its OWASP control below.
Findings mapped to the OWASP Top 10 for LLM Applications (2025) and the OWASP Machine Learning Security Top 10. Expand any flagged control for the exact findings — compromise reduces the score; expected/risk-surface do not, except a known CVE, which carries a small bounded penalty (high/critical → Review).
The same gate an agent runs before installing (POST /api/v1/trust/pyportfolioopt-portfolio-optimization/check). Click a policy:
Consume PyPortfolioOpt — Portfolio Optimization programmatically. Authenticate with an API key or session — see Authorize an agent.
# Agents: CHECK BEFORE YOU INSTALL (no auth) — score, grade, level, capability manifest
curl https://ai-supply.store/api/v1/trust/pyportfolioopt-portfolio-optimization
# Gate against your org policy (returns { pass, violations })
curl -X POST https://ai-supply.store/api/v1/trust/pyportfolioopt-portfolio-optimization/check \
-H "Content-Type: application/json" \
-d '{"minGrade":"B","denyPermissions":["shell"],"denyUnknownEgress":true}'
# CLI
npx ai-supply add pyportfolioopt-portfolio-optimization
# REST (install → download)
curl -X POST https://ai-supply.store/api/v1/listings/pyportfolioopt-portfolio-optimization/install \
-H "Authorization: Bearer $AIM_KEY"
# MCP tool
install_listing({ "slug": "pyportfolioopt-portfolio-optimization" })OpenAPI spec →Curated mirror — latest upstream source. See the repository for tagged releases.