Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
optimalportfolios - portfolio construction and rolling backtesting
optimalportfolios - portfolio construction and rolling backtesting

Start here

  • Installation
  • Quickstart
  • Conventions, notation and glossary
  • Analytics gallery
  • Examples and recipes

Data and estimation grids

  • Mixed-frequency data
  • Incomplete histories and frozen positions
  • Universe data and appraisal unsmoothing

Risk models

  • Covariance estimators
  • Factor covariance with HCGL
  • Rolling factor risk model from CSV
  • Ex-ante risk contributions, betas and the qis risk model

Expected returns and signals

  • Alpha signals
  • Signal diagnostics and alpha-rank portfolios

Portfolio objectives

  • Choosing an objective: dispatch, configuration and results
  • Risk budgeting
  • Implied risk budgets from target weights
  • Hierarchical risk parity and cluster risk budgets
  • Maximum diversification
  • Minimum variance, quadratic utility and maximum Sharpe
  • Strategic allocation: target return and target volatility
  • CARA utility under Gaussian mixtures
  • Minimum tracking error
  • Tactical allocation: alpha over tracking error and yield targets
  • Overlay optimisation with a fixed core and linear side constraints

Constraints and solving

  • Portfolio constraints
  • Covariance factorisation, solver outcomes and constraint residuals

Backtesting and costs

  • Rolling portfolio backtests
  • Turnover and transaction costs

Applications

  • Strategic and tactical allocation with HCGL covariance (ROSAA)
  • Cryptocurrencies in diversified portfolios
  • From capital market assumptions to strategic allocation (MATF-CMA)
  • Stress testing with options and FCGL clusters

Implementation and reference

  • Software design and boundaries
  • Choosing a portfolio optimization library
  • Research papers and replication
  • API reference
    • optimalportfolios.UniverseData
    • optimalportfolios.MetadataField
    • optimalportfolios.copy_universe_data_with_unsmoothed_prices
    • optimalportfolios.compute_returns_from_prices
    • optimalportfolios.EwmaCovarEstimator
    • optimalportfolios.estimate_current_ewma_covar
    • optimalportfolios.FactorCovarEstimator
    • optimalportfolios.estimate_lasso_factor_covar_data
    • optimalportfolios.plot_current_covar_data
    • optimalportfolios.plot_hcgl_covar_data
    • optimalportfolios.run_rolling_covar_report
    • optimalportfolios.build_risk_model
    • optimalportfolios.compute_portfolio_variance
    • optimalportfolios.compute_portfolio_vol
    • optimalportfolios.compute_portfolio_risk_contribution_outputs
    • optimalportfolios.compute_benchmark_beta_loadings
    • optimalportfolios.compute_benchmark_beta_loadings_from_covar
    • optimalportfolios.compute_benchmark_beta_loadings_ts
    • optimalportfolios.compute_ex_ante_beta_ts
    • optimalportfolios.AlphasData
    • optimalportfolios.compute_momentum_alpha
    • optimalportfolios.compute_momentum_cluster_alpha
    • optimalportfolios.compute_classic_momentum_from_returns
    • optimalportfolios.compute_classic_momentum_alpha
    • optimalportfolios.compute_classic_momentum_cluster_alpha
    • optimalportfolios.compute_low_beta_alpha
    • optimalportfolios.compute_low_beta_cluster_alpha
    • optimalportfolios.compute_residual_momentum_alpha
    • optimalportfolios.compute_residual_momentum_cluster_alpha
    • optimalportfolios.compute_residual_reversal_alpha
    • optimalportfolios.compute_residual_reversal_cluster_alpha
    • optimalportfolios.compute_ra_carry_alphas
    • optimalportfolios.compute_managers_alpha
    • optimalportfolios.extract_rolling_clusters
    • optimalportfolios.align_rolling_clusters
    • optimalportfolios.score_within_clusters
    • optimalportfolios.ProfileSignal
    • optimalportfolios.profile_momentum
    • optimalportfolios.profile_classic_momentum
    • optimalportfolios.profile_low_beta
    • optimalportfolios.profile_residual_momentum
    • optimalportfolios.profile_carry
    • optimalportfolios.profile_alpha_signals
    • optimalportfolios.generate_alpha_profile_report
    • optimalportfolios.backtest_alpha_rank_portfolio
    • optimalportfolios.compute_top_quantile_equal_weights
    • optimalportfolios.compute_alpha_rank_analysis_table
    • optimalportfolios.signal_diagnostics_panel
    • optimalportfolios.run_signal_diagnostics
    • optimalportfolios.run_signal_diagnostics_per_component
    • optimalportfolios.compare_signal_diagnostics
    • optimalportfolios.PortfolioObjective
    • optimalportfolios.OptimiserConfig
    • optimalportfolios.compute_rolling_optimal_weights
    • optimalportfolios.PortfolioOptimisationResult
    • optimalportfolios.rolling_risk_budgeting
    • optimalportfolios.wrapper_risk_budgeting
    • optimalportfolios.opt_risk_budgeting
    • optimalportfolios.solve_for_risk_budgets_from_given_weights
    • optimalportfolios.average_rolling_weights
    • optimalportfolios.compute_hierarchical_risk_parity_weights
    • optimalportfolios.compute_group_risk_budgets
    • optimalportfolios.rolling_maximise_diversification
    • optimalportfolios.wrapper_maximise_diversification
    • optimalportfolios.opt_maximise_diversification
    • optimalportfolios.calculate_diversification_ratio
    • optimalportfolios.rolling_quadratic_optimisation
    • optimalportfolios.wrapper_quadratic_optimisation
    • optimalportfolios.cvx_quadratic_optimisation
    • optimalportfolios.rolling_maximize_portfolio_sharpe
    • optimalportfolios.wrapper_maximize_portfolio_sharpe
    • optimalportfolios.cvx_maximize_portfolio_sharpe
    • optimalportfolios.solve_analytic_log_opt
    • optimalportfolios.estimate_rolling_ewma_means
    • optimalportfolios.plot_efficient_frontier
    • optimalportfolios.rolling_min_variance_target_return
    • optimalportfolios.wrapper_min_variance_target_return
    • optimalportfolios.cvx_min_variance_target_return
    • optimalportfolios.cvx_min_variance_target_return_utility
    • optimalportfolios.rolling_max_return_target_vol
    • optimalportfolios.wrapper_max_return_target_vol
    • optimalportfolios.cvx_max_return_target_vol
    • optimalportfolios.cvx_max_return_target_vol_utility
    • optimalportfolios.rolling_maximize_cara_mixture
    • optimalportfolios.wrapper_maximize_cara_mixture
    • optimalportfolios.opt_maximize_cara_mixture
    • optimalportfolios.opt_maximize_cara
    • optimalportfolios.fit_gaussian_mixture
    • optimalportfolios.rolling_minimise_tracking_error
    • optimalportfolios.wrapper_minimise_tracking_error
    • optimalportfolios.cvx_minimise_tracking_error
    • optimalportfolios.rolling_maximise_alpha_over_tre
    • optimalportfolios.wrapper_maximise_alpha_over_tre
    • optimalportfolios.cvx_maximise_alpha_over_tre
    • optimalportfolios.cvx_maximise_tre_utility
    • optimalportfolios.rolling_maximise_alpha_with_target_return
    • optimalportfolios.wrapper_maximise_alpha_with_target_return
    • optimalportfolios.cvx_maximise_alpha_with_target_return
    • optimalportfolios.Constraints
    • optimalportfolios.ConstraintEnforcementType
    • optimalportfolios.GroupLowerUpperConstraints
    • optimalportfolios.GroupTrackingErrorConstraint
    • optimalportfolios.GroupTurnoverConstraint
    • optimalportfolios.compute_eligible_rebalancing_bounds
    • optimalportfolios.merge_group_lower_upper_constraints
    • optimalportfolios.CovarianceFactorization
    • optimalportfolios.factorize_covariance
    • optimalportfolios.filter_covar_and_vectors_for_nans
    • optimalportfolios.OptimizationOutcome
    • optimalportfolios.ConstraintResidual
    • optimalportfolios.evaluate_constraint_residuals
    • optimalportfolios.backtest_rolling_optimal_portfolio
    • optimalportfolios.apply_drift_to_weights_0
    • optimalportfolios.round_weights_to_pct
    • optimalportfolios.compute_tre_turnover_stats
    • optimalportfolios.ClusterSmootherType
    • optimalportfolios.DependenceMeasure
    • optimalportfolios.DistanceTransform
    • optimalportfolios.LassoModel
    • optimalportfolios.LassoModelType
    • optimalportfolios.CurrentFactorCovarData
    • optimalportfolios.RollingFactorCovarData
    • optimalportfolios.RollingClusterData
    • optimalportfolios.VarianceColumns
    • optimalportfolios.apply_partition_distance_bonus
    • optimalportfolios.compute_rolling_smoothed_clusters
    • optimalportfolios.compute_dependence_matrix
    • optimalportfolios.compute_gerber_matrix
    • optimalportfolios.smooth_similarity_ewma
    • optimalportfolios.estimate_rolling_ewma_covar
    • optimalportfolios.alphas
    • optimalportfolios.config
    • optimalportfolios.covar_estimation
    • optimalportfolios.local_path
    • optimalportfolios.optimization
    • optimalportfolios.reports
    • optimalportfolios.universe
    • optimalportfolios.utils
  • Documentation standard
Back to top
View this page
Edit this page

Analytics gallery¶

Author: Artur Sepp / First recorded: 2026-09-14

Examples from OptimalPortfolios. Software citation: CITATION.cff.

The gallery has six previews and 25 teaching exhibits. The previews connect portfolio construction to risk and performance analytics on one synthetic portfolio: OptimalPortfolios estimates risk and constructs targets, qis simulates holdings and computes analytics, and factorlasso fits the sparse factor models. Each teaching exhibit is drawn by the canonical script of its article and illustrates one result of it.

All inputs are synthetic or fixed, except the cryptocurrency exhibit, which is derived from the tracked price panel of its paper. The figures illustrate calculations and implementation conventions; they do not establish historical performance or recommend an allocation or estimator. The previews’ shared provenance record identifies the effective source, inputs, parameters, actual software environment, generation time and visual review; the teaching exhibits have their own manifest. A fixed sample ending in 2025 is separate from the date the image was generated.

Choose an exhibit¶

The six previews simulate one synthetic portfolio end to end:

Question

Exhibit

How do growth and drawdowns compare with a synthetic benchmark?

Performance

What are the final targets and their estimated risk contributions?

Allocation and risk

How do decided allocations and realized trading costs evolve?

Allocation through time

How does covariance smoothing affect this example?

Span sensitivity

How do three objectives behave with common risk inputs?

Objective comparison

How do estimates compare with a known simulated covariance?

Covariance estimators

The 25 teaching exhibits each illustrate one article, in the order of the sidebar:

Question

Exhibit

Which observations enter each asset’s classic momentum when monthly and quarterly assets share a formation date, and how is a quarterly signal carried between quarter ends?

Mixed-frequency data

What happens to NAV and holdings when a price is missing between rebalancings, on a rebalance date, and at the opening trade?

Incomplete histories

How much autocorrelation and volatility does unsmoothing restore to an appraisal-smoothed private-asset series?

Universe data and unsmoothing

Do both residual types give each asset the same variance, and how much residual variance does a portfolio of assets sharing an unspanned shock collect under each?

Factor covariance with HCGL

How do capital weights and risk shares differ across equal weight, minimum variance, equal risk contribution and maximum diversification on one covariance?

Ex-ante risk contributions

How does scoring one signal within clusters change the ranking of assets compared with scoring it across the whole cross-section?

Alpha signals

Does the signal rank returns, and how stable is its IC?

Signal diagnostics

Are the risk budgets met when a weight bound binds?

Risk budgeting

What static risk budgets reproduce a target allocation on average, and how far do the weights they imply drift from it date by date?

Implied risk budgets

How do HRP, equal risk contribution and equal cluster budgets divide capital and risk among the blocks of one universe?

Hierarchical risk parity

Is the maximum diversification portfolio the minimum-variance portfolio of the correlation matrix, rescaled by inverse volatility, and do its held assets share one correlation with it?

Maximum diversification

Where do minimum variance, utility and maximum Sharpe sit on the frontier?

Mean-variance objectives

Do the target-return and target-volatility solvers trace the same frontier, hard and soft?

Target return and target volatility

How do risk aversion and a crash component change the allocation?

CARA utility under Gaussian mixtures

What does each added constraint cost in ex-ante tracking error against the benchmark?

Minimum tracking error

Do active weights follow the closed form, and how does IR scale with the TE budget?

Alpha over tracking error

How do the overlay sleeve and the portfolio’s model risk and return change as the linear tail floor tightens from non-binding to near its reachable maximum?

Overlay tail floor

What changes when a tracking-error limit becomes a penalty: how far does the solve exceed the limit, and what active return does that buy, as the penalty weight grows?

Portfolio constraints

What does the eigenvalue floor change as two proxies become collinear?

Solver numerics and outcomes

How far do held weights drift from target weights between quarterly rebalancings?

Rolling backtests

How does raising turnover_utility_weight trade turnover against ex-ante tracking error, and at what weight does trading stop?

Turnover and transaction costs

How do risk budgets translate into strategic weights, and do the tactical tilts spend the tracking-error budget in the direction of the alphas?

ROSAA layers

How much does each method allocate to the crypto asset?

Cryptocurrency allocation

How do factor premia and residual adjustments build the CMAs, and what allocation do they imply?

Capital market assumptions

How do factor shocks and option repricing combine in a portfolio stress test?

Stress testing with options

Select a preview to open its full-resolution image. The offline quickstart provides a smaller executable introduction, and the examples guide maps broader workflows and their data requirements.

Samples and conventions¶

The first five previews use six assets from the fixed qis synthetic-universe generator: US and European equity, Treasuries, investment-grade bonds, gold and commodities. Seed 20260725 and clean mode (apply_quirks=False) select complete business-day observations from 4 January 2010 to 31 December 2025. Early history supplies estimation warmup; the displayed performance window is 1 April 2015 to 31 December 2025.

The sixth preview, covariance estimators, uses the repository’s known-factor simulator, seed 42: four factors, eight assets and 783 business-day observations from 2 January 2023 to 31 December 2025. Its displayed backtest starts on 3 January 2024 after weekly estimation warmup.

Convention

Applied in the six previews

Estimation returns

Weekly Wednesday log returns, with trailing EWMA demeaning

Covariance units

Annualized using 52 weekly observations per year

Construction

Fully invested, long-only target weights; 35% cap per asset

Decision and execution

Quarterly schedules mapped to observed Wednesdays; targets trade one business-day observation later

Holdings

qis holds units between trades, so realized weights drift

Trading costs

10 basis points of gross traded notional, including entry

Other costs

No funding or management fees

Displayed growth

Portfolio NAV after costs; the 60/40 reference in the first panel is explicitly gross

The last target decision is 1 October 2025. That target snapshot differs from holdings at the sample end. Cost bars sum daily cash cost divided by that day’s NAV, expressed in basis points; they measure cost incidence rather than compounded performance drag. The refresh specification records detailed conventions, solver acceptance and independent numerical checks.

Portfolio performance¶

The maximum-diversification portfolio is compared with the fixture’s daily-rebalanced gross 60/40 benchmark. Both series are displayed as growth of 100; drawdown measures the fall from each series’ running peak over the report window.

Synthetic maximum-diversification growth and drawdowns against a gross 60/40 benchmark

Sample: 1 April 2015–31 December 2025. The portfolio is net of 10 bp trading costs; the benchmark is gross. This illustrative comparison does not isolate an allocation advantage. Producer: portfolio reports. Related methodology: rolling backtests.

Allocation and risk¶

The upper panel shows decided maximum-diversification weights. The lower panel shows each asset’s contribution to estimated annualized portfolio volatility using the same decision’s covariance. Contributions are measured in volatility percentage points, not portfolio weights.

Synthetic target weights and contributions to annualized portfolio volatility

Decision: 1 October 2025. Weekly log returns, EWMA span 52, annualization factor 52. The 35% asset cap can bind. The estimate describes targets and ex-ante risk, rather than end-of-sample holdings or realized future volatility. Producer: portfolio reports. Related methodology: covariance estimators.

Allocation through time¶

The stacked panel extends each decided target until the following decision for display. It does not plot drifted holdings. The lower panel aggregates realized trading costs by calendar quarter, including the initial allocation.

Synthetic decided allocations through time and quarterly sums of trading costs

Sample: 1 April 2015–31 December 2025. Extending the last target to the report end adds neither a new decision nor a trade. Quarterly cost sums use each day’s NAV denominator. Producer: portfolio reports. Related methodology: turnover and transaction costs.

Covariance span sensitivity¶

Five maximum-diversification backtests vary the EWMA span across 5, 13, 26, 52 and 104 weekly observations. Each span affects both trailing demeaning and covariance smoothing. A span is an EWMA parameter, not a half-life or a finite estimation window.

Synthetic net maximum-diversification growth and total trading costs across five EWMA spans

Sample: 1 April 2015–31 December 2025. Assets, constraints, costs and implementation dates are shared. The lower panel sums daily cost/NAV over that common report period. This fixed path illustrates parameter sensitivity; it does not select a preferred span. Producer: span sensitivity.

Portfolio objectives¶

Minimum variance, maximum diversification and equal risk budgets use the same covariance, assets, weight constraints and trade dates. Expected-return estimation is outside this comparison; it covers three objectives driven by covariance.

Synthetic net growth and trading costs for minimum variance, maximum diversification and equal risk budgets

Sample: 1 April 2015–31 December 2025. The 35% cap can prevent equal target risk budgets from producing equal risk contributions at the decision date. Cost sums include entry. This single synthetic path is not evidence of an objective’s expected market performance. Producer: optimiser comparison. Related methodology: optimization guide and risk budgeting.

Covariance estimators¶

Six estimates feed a common minimum-variance construction: EWMA, Lasso and Group Lasso, each with its specified volatility-normalized variant. EWMA normalization acts on asset-return covariance; factor variants normalize factor covariance only. Group Lasso uses four fixed asset pairs, not clusters inferred from the known loadings.

Synthetic minimum-variance backtests and last-decision covariance errors for six estimators

Backtest: 3 January 2024–31 December 2025. Error snapshot: 1 October 2025. The lower panel measures relative Frobenius error against the known simulated covariance: the Euclidean size of all estimation errors divided by the size of the true matrix. Estimated weekly covariance is annualized by 52; simulated daily truth by 260. Known truth is used for descriptive evaluation and never supplied to portfolio estimation.

All cases fit only data available at their shared decision dates. The simulation has constant loadings/covariance, no return premium and one fixed path. Closely overlapping performance curves and one-date covariance errors do not establish an estimator ranking. Producer: covariance comparison. Configuration: analytics registry.

Mixed-frequency data¶

A teaching exhibit of the mixed-frequency data page. At one formation date, the monthly assets’ classic momentum uses 12 monthly returns ending one month earlier, and the quarterly asset uses 4 quarterly returns ending one quarter earlier; the quarterly signal is carried unchanged between quarter ends.

Left: the observations in each asset's classic momentum window at 31 December 2023. Right: raw classic momentum, with the quarterly asset flat between quarter ends.

Sample: deterministic synthetic panel of two monthly series and quarter-end NAVs, December 2018 to December 2024; no simulation. Producer: the exhibit function of examples/docs/mixed_frequency_data.py. Configuration: teaching registry.

Incomplete histories¶

A teaching exhibit of the incomplete histories page. A price missing between rebalancings lowers NAV only until the price returns; the same gap on a rebalance date clears the held units without proceeds; a missing opening price leaves that allocation in cash.

Left: NAV of the hold-through-gap, rebalance-on-gap and missing-opening-price paths over four business days. Right: the rebalance-on-gap path's holdings, with the gapped position replaced by cash.

Sample: two synthetic assets over four business days in January 2024, with one missing price; no simulation. Producer: the exhibit function of examples/docs/incomplete_histories.py. Configuration: teaching registry.

Universe data and unsmoothing¶

A teaching exhibit of the universe data and unsmoothing page. Appraisal smoothing with a weight of 0.6 on the previous reported return halves the reported volatility of private equity and makes its returns autocorrelated. Unsmoothing lowers the lag-1 autocorrelation from 0.61 to -0.04, against -0.02 for the true returns, and raises the annualised volatility from 10.2% to 20.5%, against 20.4%.

Left: cumulative log returns of reported, unsmoothed and simulated true private equity. Middle:their lag-1 autocorrelations. Right: their annualised volatilities.

Sample: a seeded synthetic quarterly panel of four assets from December 1989 to December 2024, seed 19, whose private-equity column is appraisal-smoothed; the simulated true returns are known. Producer: the exhibit function of examples/docs/universe_data_and_unsmoothing.py. Configuration: teaching registry.

Factor covariance with HCGL¶

A teaching exhibit of the factor covariance with HCGL page. Orthogonal and empirical residuals give every asset the same systematic and residual variance; they differ in the residual covariances. Three private assets share a shock that the factors do not span, and an equal-weight portfolio of them has a residual variance of 0.00019 with orthogonal residuals and 0.00040 when the empirical residual correlations enter with full weight.

Left: stacked bars of systematic and residual annual variance for eight assets, identical underorthogonal and empirical residuals. Right: residual variance of equal weights in the three privateassets, rising from 0.00019 with orthogonal residuals to 0.00040 as residual covariances areadded.

Sample: synthetic month ends from December 2004 to December 2024, seed 5: four factors, five monthly and three quarterly assets with known loadings and a shock common to the private assets; HCGL fit at 31 December 2023. Producer: the exhibit function of examples/docs/factor_covariance_hcgl.py. Configuration: teaching registry.

Ex-ante risk contributions¶

A teaching exhibit of the ex-ante risk contributions page. On one covariance, equal weights put 42% of the risk in emerging-market equity; minimum variance has risk shares equal to its weights; equal risk contribution gives each asset 20% of the risk with 45% of the capital in government bonds; maximum diversification holds 67% of the capital in government bonds and 41% of the risk.

Left: stacked capital weights of equal weight, minimum variance, equal risk contribution andmaximum diversification on one five-asset covariance. Right: the Euler risk shares of the sameportfolios.

Sample: the page’s fixed five-asset, three-factor covariance snapshot; no simulation. Producer: the exhibit function of examples/docs/portfolio_risk_analytics.py. Configuration: teaching registry.

Alpha signals¶

A teaching exhibit of the alpha signals page. Scored across all nine assets, twelve-month momentum ranks the equity-like assets first; scored within each cluster, each group is centred on its own mean, so the strongest bond-like asset rises from fifth to second and the weakest equity-like asset falls to last.

Left: cross-sectional momentum scores of nine assets, with each cluster's mean. Right: the same signal scored within each cluster, with the rank of each asset.

Sample: nine synthetic month-end price paths with constant log drifts, five equity-like and four bond-like, October 2023 to December 2024; no simulation. Producer: the exhibit function of examples/docs/alphas_module_readme.py. Configuration: teaching registry.

Signal diagnostics¶

A teaching exhibit of the signal diagnostics and alpha-rank portfolios page. A synthetic score whose population rank information coefficient is 0.0955 sorts 500 assets into quintile portfolios whose values fan out in rank order, while the monthly rank IC scatters widely around its population value.

Left: the values of the five quintile portfolios sorted by the score, on a log scale. Right: themonthly rank IC with its 12-month mean and the population value.

Sample: 500 synthetic assets with 240 month-end returns from January 2006 to December 2025, seed 11. Producer: the exhibit function of examples/docs/signal_diagnostics_and_profiling.py. Configuration: teaching registry.

Risk budgeting¶

A teaching exhibit of the risk budgeting page. With slack caps, each asset’s share of portfolio risk equals its budget of 50%, 30% or 20%; capping Equity at 25% leaves no asset at its budget, and the released risk goes to the free assets in proportion to their capital weights, not their budgets.

Left: target budgets and achieved risk shares with slack caps and with Equity capped at 25%. Right: the capital weights of both solves.

Sample: the page’s fixed three-asset covariance, solved with slack 80% caps and with Equity capped at 25%; no simulation. Producer: the exhibit function of examples/docs/risk_budgeting.py. Configuration: teaching registry.

Implied risk budgets¶

A teaching exhibit of the implied risk budgets page. As the stock-bond correlation drifts from -0.7 to 0.4 over twelve quarter ends, the implied risk budget of Bonds in a 40/45/15 target rises from -8% to 25%; on the first two dates Bonds hedge the portfolio and no non-negative budget reproduces the target. One static budget vector of about 70.6%, 14.5% and 14.9% reproduces the target only on average: its forward weight in Bonds moves from 59% to 32%.

Left: the implied risk budgets of the target at each quarter end, with the fitted static budgetsdashed and the dates of negative Bonds budgets shaded. Right: the forward weights under the fittedbudgets, their running averages and the target weights.

Sample: three assets with fixed volatilities and a stock-bond correlation drifting from -0.7 to 0.4 over twelve quarter ends from 31 March 2023; no simulation. Producer: the exhibit function of examples/docs/implied_risk_budgets.py. Configuration: teaching registry.

Hierarchical risk parity¶

A teaching exhibit of the hierarchical risk parity and cluster risk budgets page. On a universe of four government bonds, two equity markets and two real assets, HRP puts 91% of the capital and 90% of the risk in the bonds; equal risk contribution puts 76% of the capital there for 50% of the risk, and equal cluster budgets 69% of the capital for a third.

Left: the single-linkage tree of the eight assets, with the first HRP split between the bondsand the rest. Right: capital and risk shares by block for HRP, equal risk contribution and equalcluster budgets.

Sample: a fixed eight-asset universe of four government bonds, two equity markets and two real assets with block correlations; no simulation. Producer: the exhibit function of examples/docs/hierarchical_risk_parity_and_cluster_budgets.py. Configuration: teaching registry.

Maximum diversification¶

A teaching exhibit of the maximum diversification page. The SLSQP weights of the package and the minimum-variance weights of the correlation matrix, rescaled by inverse volatility and computed by CVXPY, agree for a stylised six-asset universe; every held asset has correlation 0.570 with the portfolio, the inverse of its diversification ratio, and the excluded credit asset has 0.70.

Left: SLSQP and CVXPY routes give the same weights for six assets, with government bonds at 72% and credit not held. Right: held assets have correlation 0.570 with the portfolio; excluded credit has 0.70.

Sample: fixed volatilities and correlations; no simulation. Producer: the exhibit function of examples/docs/maximum_diversification.py, run by the teaching-exhibit tool. Configuration: teaching registry.

Mean-variance objectives¶

A teaching exhibit of the mean-variance objectives page. With a full-investment budget, minimum variance, quadratic utility and maximum Sharpe lie on one frontier: the utility portfolio mixes the minimum-variance and tangency portfolios, and a risk aversion of 6.96 returns the tangency portfolio, whose Sharpe ratio is 0.416.

Left: expected excess return against volatility, with the frontier, the minimum-variance andmaximum-Sharpe portfolios and utility portfolios at four risk aversions. Right: the weights of theminimum-variance, maximum-Sharpe and utility portfolios.

Sample: fixed expected excess returns, volatilities and correlations of five assets; no simulation. Producer: the exhibit function of examples/docs/mean_variance_objectives.py. Configuration: teaching registry.

Target return and target volatility¶

A teaching exhibit of the strategic allocation page. Minimum variance at a target return, maximum return at a target volatility and the utility form at a penalty weight trace one frontier: a 5% volatility target, a 4.81% return target and a penalty weight of 4.46 return the same portfolio.

Left: expected return against volatility, with the frontier and the solutions of the threeroutes. Right: the volatility of the utility solution against the penalty weight, crossing the 5%target at the shadow price.

Sample: the packaged 19-instrument monthly fixture, with an EWMA covariance (span 36) at 31 December 2025 and equal-Sharpe expected returns; no simulation. Producer: the exhibit function of examples/docs/strategic_allocation_targets.py. Configuration: teaching registry.

CARA utility under Gaussian mixtures¶

A teaching exhibit of the CARA utility under Gaussian mixtures page. A crash component lowers the allocation to crypto at every risk aversion: at a risk aversion of 5, the three-component mixture holds 6.3% in crypto against 7.2% for the Gaussian with the mixture’s own mean and covariance.

Left: the weight of crypto against risk aversion for one and three mixture components. Right:the weights of bonds, equities and crypto at a risk aversion of 5.

Sample: fixed annual parameters of a stylised three-asset, three-component mixture; no simulation. Producer: the exhibit function of examples/docs/cara_gaussian_mixture.py. Configuration: teaching registry.

Minimum tracking error¶

A teaching exhibit of the minimum tracking error page. Starting from the benchmark itself, excluding one asset, capping another, limiting a group and limiting turnover each add ex-ante tracking error, from 0% to 2.06% a year; the right panel shows where the covariance sends the displaced weight at two of the steps.

Left: ex-ante tracking error after each cumulative constraint. Right: active weights at the exclusion step and the turnover step.

Sample: fixed volatilities and correlations of a stylised five-asset universe with a 60/40 benchmark and fixed current holdings; no simulation. Producer: the exhibit function of examples/docs/minimum_tracking_error.py. Configuration: teaching registry.

Alpha over tracking error¶

A teaching exhibit of the alpha over tracking error page. Under a 2% tracking-error budget the long-only active weights equal the closed form, and the information ratio stays at 0.336 until a weight bound binds at a 3.82% budget; without weight bounds it does not fall.

Left: long-only active weights at a 2% budget against the closed form. Right: the informationratio against the tracking-error budget, with and without long-only bounds.

Sample: fixed volatilities, correlations, benchmark and alphas of a stylised six-asset universe; no simulation. Producer: the exhibit function of examples/docs/alpha_over_tracking_error.py. Configuration: teaching registry.

Overlay tail floor¶

A teaching exhibit of the overlay tail floor page. A floor changes nothing until it exceeds the unconstrained sleeve’s floor exposure; tighter floors bind at equality, move the sleeve from the carry overlays to the defensive ones, and near the reachable maximum leave it all in one defensive overlay, at a lower model return.

Left: the overlay sleeve by floor level, stacked by overlay. Right: the portfolio's model volatility and expected excess return against the floor.

Sample: the page’s synthetic core and four overlays, solved at 90 floors from -0.08 to 0.009; no simulation. Producer: the exhibit function of examples/docs/overlay_tail_floor.py. Configuration: teaching registry.

Portfolio constraints¶

A teaching exhibit of the portfolio constraints page. A hard 2% tracking-error row holds the solve at the limit; the same limit as a penalty lets tracking error exceed it by an amount that shrinks as the penalty weight grows, and only the row’s shadow price, 3.33 here, reproduces the forced solve.

Left: ex-ante tracking error against the 2% limit for six penalty weights and for the hard row. Right: the active expected return of the same solves.

Sample: the page’s synthetic three-asset example with a 45/40/15 benchmark, solved with a hard tracking-error row and at six penalty weights; no simulation. Producer: the exhibit function of examples/docs/constraints.py. Configuration: teaching registry.

Solver numerics and outcomes¶

A teaching exhibit of the solver numerics and outcomes page. As two private proxies approach collinearity, the smallest eigenvalue of the covariance falls toward zero and the condition number grows as the inverse of the correlation gap. The eigenvalue floor raises only the smallest eigenvalue, to 1e-10, and caps the condition number at the largest eigenvalue over the floor; the other five eigenvalues are unchanged.

Left: the six eigenvalues of the covariance with the private pair nearly collinear, on a logscale, with the smallest raised to the floor. Right: the condition number against one minus thecorrelation of the pair, before and after the floor.

Sample: fixed volatilities and correlations of a six-asset universe whose private pair approaches a duplicate proxy; no simulation. Producer: the exhibit function of examples/docs/solver_numerics_and_outcomes.py. Configuration: teaching registry.

Rolling backtests¶

A teaching exhibit of the rolling backtests page. Between quarterly trades, held weights drift with prices away from the targets in force; each trade, one observation after its decision date, resets them, and the gap peaks the day before a trade.

Left: target and held weights of three assets through 2020 and 2021, with the quarterly trades. Right: the sum of absolute differences between held and target weights.

Sample: a seeded synthetic business-day panel of three assets with weekly EWMA covariances, minimum-variance targets capped at 60% and eight quarterly trades. Producer: the exhibit function of examples/docs/rolling_backtests.py. Configuration: teaching registry.

Turnover and transaction costs¶

A teaching exhibit of the turnover and transaction costs page. Raising turnover_utility_weight moves the solution along a frontier from the benchmark, with 30% turnover, to the current holdings, with none; trading stops at a finite weight, 0.3851 in this example, given by the spread of the marginal active risks.

Left: full L1 turnover against ex-ante tracking error, one point per labelled penalty weight. Right: turnover against the penalty weight, with the no-trade threshold.

Sample: a synthetic four-asset problem with a 50/20/25/5 benchmark and 40/25/20/15 holdings, solved at 51 penalty weights; no simulation. Producer: the exhibit function of examples/docs/turnover_and_transaction_costs.py. Configuration: teaching registry.

ROSAA layers¶

A teaching exhibit of the ROSAA case study. On a synthetic panel with known factor loadings, the strategic allocation meets its risk budgets with capital weights that differ from them, and the tactical tilts against it follow the alphas at a 3% ex-ante tracking error at every quarter end.

Left: risk budgets and the strategic weights that meet them for eight asset classes. Right: tactical active weights against alpha scores at 43 quarter ends.

Sample: synthetic monthly panel of three factors and eight asset classes, December 2004 to June 2025, seed 11; quarter ends from December 2014. Producer: the exhibit function of examples/docs/app_rosaa_multi_asset_allocation.py. Configuration: teaching registry.

Cryptocurrency allocation¶

A paper-derived exhibit of the cryptocurrencies in diversified portfolios case study, run with the current API on the frozen 2023 panel of the paper. In the all-alternatives template with BTC, the median BTC weight is 5.3% under equal risk contribution, 6.3% under maximum diversification and 10.9% under maximum Sharpe, and CARA utility with three mixture components holds the most.

Two panels of BTC weights at each quarter end from March 2016 to June 2023 for four methods,with the median marked, in the all-alternatives and the balanced templates.

Sample: the tracked price panel of the cryptocurrency paper, ETF-derived columns only (BTC, private equity, real estate, commodities, gold and a 60/40 proxy), monthly log returns and 30 quarter ends from 31 March 2016 to 30 June 2023. Producer: the exhibit function of examples/docs/app_crypto_allocation.py. Configuration: teaching registry.

Capital market assumptions¶

A teaching exhibit of the capital market assumptions to strategic allocation case study. One loading matrix gives the factor-implied part of each CMA; two one-point residual adjustments, small beside the factor parts, turn a sold-out hedge-fund position into a 3.4-point overweight at a 1% tracking-error budget.

Left: the factor-implied and residual parts of eight synthetic CMAs. Right: active weights againstthe benchmark with and without the residual adjustments.

Sample: fixed synthetic loadings, factor premia and residual adjustments of eight asset classes and four factors; no simulation. Producer: the exhibit function of examples/docs/app_cma_strategic_allocation.py. Configuration: teaching registry.

Stress testing with options¶

A teaching exhibit of the stress testing with options page. For a book of stocks with short calls and puts, each Equity scenario’s P&L splits into a delta part, linear in the moves, and a gamma part from full option repricing; the short options lose against their delta line in both directions.

Left: delta part, gamma part and total P&L of the book for Equity moves of -30% to +30%. Right: the short options' full-repricing P&L against their delta line, with the gamma gap shaded.

Sample: an offline three-stock book with a fixed three-factor model and conditionally completed Equity moves; no simulation. Producer: the exhibit function of examples/docs/stress_testing_with_options.py. Configuration: teaching registry.

Reproduce and update¶

From a source checkout with the documented contributor environment and C-local setup, one command regenerates all six previews and their supporting tables:

python -m tools.docs_analytics.run --all --output-root <new-C-local-bundle>

Use a new directory below AGENT_LOCAL_ROOT, outside OneDrive and the source tree. The runner executes offline and records the imported environment and effective source bytes. Regeneration retains the fixed sample and seed; it does not fetch current market prices. Distribution versions alone cannot identify uncommitted source edits.

Follow the generation and publication workflow to compare repeated runs, validate the bundle, review each preview at full resolution and article width, and publish the six images with their shared provenance record. Full tables and intermediate output remain C-local. Preview paths are stable; the provenance file identifies their reviewed generation.

Teaching exhibits are drawn by the canonical scripts of their pages and have their own manifest, which records the script, parameters, checks and software versions of each image:

python -m tools.docs_analytics.teaching --all --output-root <new-C-local-bundle>
python -m tools.docs_analytics.teaching --verify

See also¶

  • Documentation standard: conventions, producer details and refresh workflow.

  • Constraints: units, alignment and backend support.

  • Software design: construction, estimation and analytics ownership.

References¶

  • OptimalPortfolios software citation.

  • qis software citation, for simulation, performance and risk analytics.

  • factorlasso software citation, for sparse factor-model fitting.

Next
Examples and recipes
Previous
Conventions, notation and glossary
Copyright © 2026, Artur Sepp
Made with Sphinx and @pradyunsg's Furo
Built from optimalportfolios 7.9.1 with qis 5.31.0, factorlasso 0.19.0, CVXPY 1.9.2, NumPy 2.5.2, pandas 3.0.5 and SciPy 1.18.0.
On this page
  • Analytics gallery
    • Choose an exhibit
    • Samples and conventions
    • Portfolio performance
    • Allocation and risk
    • Allocation through time
    • Covariance span sensitivity
    • Portfolio objectives
    • Covariance estimators
    • Mixed-frequency data
    • Incomplete histories
    • Universe data and unsmoothing
    • Factor covariance with HCGL
    • Ex-ante risk contributions
    • Alpha signals
    • Signal diagnostics
    • Risk budgeting
    • Implied risk budgets
    • Hierarchical risk parity
    • 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
    • Portfolio constraints
    • Solver numerics and outcomes
    • Rolling backtests
    • Turnover and transaction costs
    • ROSAA layers
    • Cryptocurrency allocation
    • Capital market assumptions
    • Stress testing with options
    • Reproduce and update
    • See also
    • References