optimalportfolios¶
Author: Artur Sepp / First recorded: 2026-08-09
OptimalPortfolios is a Python library for multi-asset portfolio construction and rolling backtesting. At each rebalancing date it turns dated risk estimates, expected returns and constraints into target weights under a chosen objective: risk budgets, maximum diversification, minimum variance, maximum Sharpe, tracking error against a benchmark, or expected utility under fat-tailed returns. Holdings simulation, transaction costs and reporting belong to qis, and sparse factor estimation to FactorLasso; optimalportfolios is the reference implementation of the ROSAA framework of Sepp, Ossa and Kastenholz (2026).
Software citation: CITATION.cff.
Start here¶
Install optimalportfolios and choose its optional features. The core installation command is
python -m pip install optimalportfolios.Run the offline quickstart: EWMA covariance, constrained minimum-variance weights and a qis backtest with explicit trade timing and costs, on a fixture shipped in the wheel.
Keep the conventions and glossary at hand. Return basis, estimation and rebalancing grids, covariance units, weight states, notation and solver defaults are defined there once for every page.
Browse the analytics gallery for reproducible exhibits, or the examples guide for complete workflows and their data requirements.
The portfolio in one picture¶
At each rebalancing date \(t\), optimalportfolios chooses the target weights
Here \(U\) is the objective, \(\mathcal C_t\) the set of admissible weights, \(\hat\mu_t\) the expected returns or alphas where the objective uses them, \(w^{\mathrm{bm}}\) a benchmark and \(w_{t^-}\) the current holdings drifted to \(t\). The covariance \(\hat\Sigma_t\) is either an EWMA estimate or the factor model on the right, with loadings \(\beta_t\), factor covariance \(\Sigma_{F,t}\) and residual covariance \(D_t\). The construction runs through the steps below.
flowchart TB
subgraph estimate ["Estimate at each rebalancing date"]
direction LR
A["Prices and<br/>metadata"] --> B["Estimation grid<br/>cadences, ragged histories"]
B --> C["Risk model<br/>EWMA or factor covariance"]
B --> D["Expected returns<br/>signals and CMAs"]
end
subgraph construct ["Construct and simulate"]
direction LR
E["Objective and<br/>constraints"] --> F["Solve and check<br/>the outcome"] --> G["Dated target<br/>weights"] --> H["qis backtest<br/>drift, lag and costs"]
end
estimate --> construct
In words: prices are sampled on an estimation grid that respects each asset’s cadence and history; a risk model and, for the objectives that need them, expected returns are estimated from information available at the rebalancing date; the objective is solved under the constraints and its outcome checked; and the dated target weights are passed to qis, which simulates the holdings with price drift, implementation lag and transaction costs.
Step of the diagram |
Pages |
|---|---|
Estimation grid |
Mixed-frequency data, incomplete histories, universe data and unsmoothing |
Risk model |
Covariance estimators, factor covariance with HCGL, rolling factor risk model from CSV, ex-ante risk contributions and betas |
Expected returns |
|
Objective and constraints |
Choosing an objective, risk budgeting, implied risk budgets, hierarchical risk parity and cluster budgets, maximum diversification, mean-variance objectives, target return and target volatility, CARA utility under Gaussian mixtures, minimum tracking error, alpha over tracking error, overlay tail floor, constraints |
Solve and check the outcome |
Choosing an objective, constraints, solver numerics and outcomes |
Dated target weights and qis backtest |
|
The whole pipeline, applied |
ROSAA, cryptocurrencies in diversified portfolios, capital market assumptions to strategic allocation, stress testing with options |
Data and estimation grids¶
Mixed-frequency data: assets observed at different cadences, their EWMA spans and signal horizons, and when each observation becomes available.
Incomplete histories and frozen positions: eligibility, warmup, frozen target weights and missing prices in rolling workflows and in the qis backtester.
Universe data and appraisal unsmoothing: the
UniverseDatacontainer, its group loadings and identifiers, and unsmoothing an appraisal-smoothed private-asset series before estimation.
Risk models¶
Covariance estimators: EWMA covariance and the estimator contract shared with the factor model: return conventions, spans against half-lives, annualisation and point-in-time inputs.
Factor covariance with HCGL: the factor covariance with sparse HCGL loadings, orthogonal and empirical residuals, cadence penalties and the point-in-time contract.
Rolling factor risk model from CSV: rebuild a rolling factor risk model from six CSV inputs and connect it to the qis risk model.
Ex-ante risk contributions, betas and the qis risk model: Euler risk contributions, benchmark betas and the hand-off to
qis.RiskModel.
Expected returns and signals¶
Alpha signals: momentum, low beta, residual momentum and reversal, carry and managers’ alpha, with cross-sectional and within-cluster scoring.
Signal diagnostics and alpha-rank portfolios: the rank information coefficient and its stability, quantile portfolios, per-component diagnostics and the rank profiler.
Portfolio objectives¶
Choosing an objective: which objective fits which inputs, the rolling dispatcher, solver configuration, return types and solver outcomes.
Risk budgeting: Euler risk contributions, target budgets and the allocation when a weight bound binds.
Implied risk budgets from target weights: the budgets that reproduce a target allocation, the hold rule for hedging assets, and one budget vector fitted to a rolling path.
Hierarchical risk parity and cluster risk budgets: recursive bisection over a linkage, group budgets split within groups, and how both compare with equal risk contribution.
Maximum diversification: the diversification ratio, why the solution is the minimum-variance portfolio of the correlation matrix, and the equal-correlation property of the assets it holds.
Minimum variance, quadratic utility and maximum Sharpe: the closed forms, the two-fund mix of utility portfolios on the frontier, and the Charnes–Cooper route for maximum Sharpe.
Strategic allocation: target return and target volatility: minimum variance at a return target and maximum return at a volatility target, their hard and utility forms, and the frontier duality between them.
CARA utility under Gaussian mixtures: expected exponential utility under a fitted mixture, its reduction to mean-variance with one component, and what a crash component does to the allocation.
Minimum tracking error: the allocation closest in risk to a supplied benchmark under the constraints.
Tactical allocation: alpha over tracking error and yield targets: the closed-form active weights under a tracking-error budget, the utility form, group limits and the yield-target variant.
Overlay optimisation with a fixed core: a fixed core exposure and an optimised sleeve under a linear downside floor.
Constraints and solving¶
Portfolio constraints: exposure, box, tracking-error, turnover, group and beta limits, hard against utility enforcement, units and backend coverage.
Covariance factorisation, solver outcomes and constraint residuals: the eigenvalue floor, outcome acceptance, fallbacks and residuals.
Backtesting and costs¶
Rolling portfolio backtests: estimation and decision dates, drifted holdings, implementation lag and the qis holdings simulation.
Turnover and transaction costs: turnover limits and penalties at construction, executed notional and cash costs in the backtest.
Applications¶
Case studies report the evidence of the research papers in context: the study design, the configuration in package terms, the paper’s results, and what the study does and does not show.
Strategic and tactical allocation with HCGL covariance (ROSAA): the three layers of the framework in The Journal of Portfolio Management, its study design and results, and the same configuration run offline.
Cryptocurrencies in diversified portfolios: the four allocation methods of the cryptocurrency paper in Risk, its study design and results, and the current API on the frozen 2023 panel, ETF-derived columns only.
From capital market assumptions to strategic allocation (MATF-CMA): CMAs and covariance from one loading matrix, and a strategic allocation by alpha over tracking error against mandate benchmarks, on synthetic inputs.
Stress testing with options and FCGL clusters: factor scenarios and option repricing for a stock-and-option portfolio. It needs network data and local prerequisites, and it does not optimise the positions.
Implementation and reference¶
Software design and boundaries: component responsibilities, solver backends, result contracts, and the division of work with qis and FactorLasso.
Choosing a portfolio optimisation library: a dated comparison of portfolio-library capabilities.
Research papers and replication: the papers behind the methods, the pages that use each one, and what a public checkout can reproduce.
API reference: every public object, grouped by the page that explains it, and the configuration fields of the main dataclasses with their defaults.
Documentation standard: page forms, notation, citations, executable examples and exhibit provenance.
Research papers¶
The methods are described in the following papers. The research papers page lists which page uses which paper and how to reproduce each one.
Sepp, A., Ossa, I. and Kastenholz, M. (2026). Robust Optimization of Strategic and Tactical Asset Allocation for Multi-Asset Portfolios. The Journal of Portfolio Management, 52(4), 86–120.
Sepp, A. (2023). Optimal Allocation to Cryptocurrencies in Diversified Portfolios. Risk, October 2023; SSRN 4217841.
Sepp, A., Hansen, E. and Kastenholz, M. (2026). Capital Market Assumptions and Strategic Asset Allocation Using Multi-Asset Tradable Factors. Working paper, SSRN 6785958.
Cite a paper for its method, and the software records for the packages an implementation uses: optimalportfolios, qis and FactorLasso.
Project resources¶
PyPI and the rendered documentation.