Every allocation method answers the same question: given assets, which weight vector with should we hold? They differ in the risk they measure, the estimates they trust, and the constraints they respect. Those differences are larger in practice than in the textbook, because every method is fed estimates, and estimates are noisy.
Cutup is a Rust library that implements thirteen of these methods and solves the optimization problems among them with its own solvers, with no external dependency. The engineering story of its 1.0 release is on my personal blog. This post covers the mathematics: the programs behind each method, how the library solves them, and what one small dataset shows about how far apart the answers can land.
Let be the vector of asset returns in period . Nearly every method starts from two estimates: a vector of expected returns and a covariance matrix . The sample versions are
Both are poor estimators in the settings practitioners care about. has free parameters estimated from numbers, so when is not much larger than its smallest eigenvalues are biased toward zero and its inverse is unstable. When , is singular. Optimizers that invert put the most weight exactly where the estimate is worst. Michaud (1989) showed that mean-variance optimization tends to maximize the effects of errors in its inputs, and the sample mean is the worst of them: its standard error is , which for a year of daily equity returns is larger than the mean itself.
Cutup offers the standard corrections, selected per method.
Covariance shrinkage. The estimate is a convex combination of the sample covariance and a structured target :
With set to the average variance times the identity, this is the Ledoit and Wolf (2004a) well-conditioned estimator. With set to each asset's own variance and the average pairwise correlation, it is their constant-correlation estimator (Ledoit and Wolf, 2004b). In both, the intensity can be fixed or estimated from the data as the value that minimizes the expected Frobenius loss. Exponentially weighted and downside (semi)covariances are available as alternatives to , and any externally estimated matrix, such as one from a factor model, can be passed in after a check that it is symmetric and positive semidefinite.
Mean shrinkage. The James-Stein estimator pulls each sample mean toward the cross-sectional average, and the Bayes-Stein estimator of Jorion (1986) pulls it toward the return of the minimum-variance portfolio:
The intensity is estimated from how far apart the means are relative to their noise: the less the data separates them, the more they are shrunk. CAPM expected returns, , and Black-Litterman posteriors (below) are the other alternatives to the sample mean.
The global minimum-variance portfolio needs no expected returns at all:
Without bounds it has the closed form . When is diagonal this reduces to inverse-variance weighting, , so any gap between the two measures the effect of the correlations.
Real mandates add bounds and group limits , such as a cap on one sector or one ad platform. These turn the problem into a convex quadratic program with no closed form. Its Karush-Kuhn-Tucker conditions are worth reading closely, because they have a clean financial meaning. With multiplier on the budget constraint and no groups,
is half the marginal contribution of asset to portfolio variance, . At the optimum, every asset held strictly between its bounds has the same marginal risk. An asset pinned at its floor already has marginal risk at or above that common level, so moving weight into it from the others would raise the variance. An asset pinned at its cap has marginal risk at or below it: you would hold more of it if the cap allowed.
Cutup solves this program with a primal active-set method (Nocedal and Wright, 2006, ch. 16). It guesses which bounds bind, solves the equality-constrained problem on the free assets by the null-space method, and then either steps toward that solution until a new bound binds or releases a bound whose multiplier has the wrong sign. Because binding bounds are fixed rather than approached, long-only weights come out at exactly zero instead of , and binding caps hold exactly.
Markowitz (1952) mean-variance adds expected returns with a risk aversion :
Two other forms of the question are common. Minimizing variance subject to is again a quadratic program, and sweeping the target traces the efficient frontier. Maximizing return subject to has a quadratic constraint instead. With bounds, cutup solves it by bisecting along the frontier of target-return programs, since the answer is the frontier portfolio at that volatility.
Rebalancing from current weights adds a cost to trading away from them. Proportional transaction costs and a cap on turnover are not differentiable. The standard reformulation splits each trade into buys and sells, with , which turns the costs into a linear term in the objective and the cap into a linear constraint. A quadratic penalty adds a multiple of the identity to the Hessian. In every case the problem remains a convex quadratic program.
The tangency portfolio maximizes , a ratio that is not concave in . Because the ratio is invariant to positive scaling of , and provided some portfolio has a positive excess return, the substitution , a variant of the Charnes-Cooper transformation for fractional programs, turns the long-only problem into a convex quadratic program (CornuΓ©jols and TΓΌtΓΌncΓΌ, 2007, Β§8.2):
Maximum diversification (Choueifaty and Coignard, 2008), which maximizes with the vector of asset volatilities, is the same problem with in place of the excess returns. Both run on the active-set solver.
Risk-based methods use no expected returns and target how risk is distributed rather than how much of it there is. Write the risk contribution of asset as . By Euler's theorem the contributions sum to the portfolio variance.
Risk parity, or equal risk contribution (Maillard, Roncalli and TeΓ―letche, 2010), asks for for all . Risk budgeting generalizes this to for budgets . As a system of equations in this is nonconvex, but it has convex formulations. Maillard, Roncalli and TeΓ―letche showed that the ERC weights are the solution of subject to , rescaled to sum to one. Spinu (2013) gave an unconstrained form, which is the one cutup uses:
Setting the gradient to zero gives , which is the budget condition up to scale. Cutup minimizes this function with Newton's method and a backtracking line search, working on the correlation matrix to make the iteration independent of the scale of the returns. The log terms make the objective strictly convex, so its minimizer is unique when it exists, and it exists whenever every long-only portfolio has positive variance.
Hierarchical risk parity (LΓ³pez de Prado, 2016) never inverts , which makes it a natural choice when is short relative to . It works in two stages:
The first half receives of the parent's weight and the second receives .
The midpoint split makes the result depend on column order, because reordering the input can move a cut between two correlated assets. Hierarchical equal risk contribution (Raffinot, 2018) instead cuts the dendrogram into clusters, chosen by a gap statistic, splits weight at the tree's actual branches, and shares weight by inverse variance within each cluster. Cutup implements both. Its HRP matches PyPortfolioOpt's HRPOpt, down to the clustering's tie-breaking rule, and its HERC matches Riskfolio-Lib's HCPortfolio.
Variance penalizes upside and downside deviations alike and summarizes a distribution by its second moment. Three methods in cutup instead measure risk directly on the historical scenarios. All three are linear programs, which cutup solves with a bounded two-phase revised simplex method.
The CVaR, or expected shortfall, at confidence is the average loss over the worst of outcomes. Rockafellar and Uryasev (2000) showed that minimizing it over is a linear program in , an auxiliary threshold (at the optimum, a value at risk), and one excess-loss variable per scenario:
Because the objective looks at the losses themselves, the method responds to skew and fat tails that a covariance cannot see. The cost is data: at , scenarios leave a tail of a single observation.
Konno and Yamazaki (1991) replaced variance with the mean absolute deviation of portfolio returns, . The absolute value becomes linear by bounding it above and below with . Large deviations count linearly rather than quadratically, so a few outliers move the answer less. The downside variant counts only shortfalls below a fixed threshold , .
With the sample estimators, every method so far treats the periods as an unordered sample: shuffle the rows and the weights do not change. Drawdown does not have that property. Let be the cumulative (summed, not compounded) portfolio return with , and define the drawdown
CDaR (Chekhlov, Uryasev and Zabarankin, 2005) is the CVaR of the drawdowns : the average of the worst of them. As it becomes the maximum drawdown. It is a natural measure for a mandate that must not fall far behind its own high-water mark, whether that is a fund with a drawdown limit or a marketing budget whose results arrive in streaks.
The linear program has a running-maximum variable and constraints for every period, and at the direct formulation takes over a minute on the library's simplex solver. Cutup solves it instead with Kelley's cutting-plane method. It starts from a small master program and adds one cut per round, each a linear lower bound on CDaR, until the bound meets the best portfolio found. Each round's simplex starts where the last one ended, and in-out stabilization (Ben-Ameur and Neto, 2007) places each cut between the master's minimizer and the best point so far, which roughly halves the number of rounds at 500 assets. The same problem at with 20 assets then solves in a few milliseconds.
Black and Litterman (1992) start from the expected returns implied by market weights under the assumption that the market portfolio is mean-variance optimal for risk aversion , . They then treat as a prior for the expected returns , with uncertainty , and blend in views of the form , with :
The posterior covariance of returns is , where is what remains of the prior's uncertainty after the views. Each view's uncertainty can be given directly as a variance or through Idzorek's (2007) intuitive confidence level. Black-Litterman produces inputs rather than weights. Its posterior mean and covariance feed mean-variance or maximum Sharpe.
The library ships an example that runs every method on the same short price history of four assets, twelve periods in all. Twelve periods is far too few to support any investment conclusion. The point is to see how the methods behave relative to one another when they are given identical, and noisy, inputs.
| Method | Asset 0 | Asset 1 | Asset 2 | Asset 3 |
|---|---|---|---|---|
| Equal weight | 0.250 | 0.250 | 0.250 | 0.250 |
| Inverse variance | 0.089 | 0.554 | 0.201 | 0.156 |
| Min variance, long-short | 0.260 | 0.611 | β0.009 | 0.137 |
| Min variance, long-only | 0.259 | 0.602 | 0.000 | 0.140 |
| Min variance, long-short, 20% shrinkage | 0.243 | 0.416 | 0.132 | 0.210 |
| Min variance, β€ 30% each | 0.244 | 0.300 | 0.195 | 0.260 |
| Max Sharpe, | 0.259 | 0.592 | 0.005 | 0.145 |
| Mean-variance, | 0.219 | 0.060 | 0.375 | 0.345 |
| Risk parity | 0.246 | 0.514 | 0.071 | 0.168 |
| HRP | 0.150 | 0.431 | 0.156 | 0.263 |
| Min CVaR, worst 25% | 0.253 | 0.555 | 0.061 | 0.131 |
| Min MAD | 0.261 | 0.623 | 0.000 | 0.116 |
| Min CDaR, worst 25% | 0.000 | 0.000 | 0.410 | 0.590 |
A few things stand out.
The correlations matter. Inverse variance and minimum variance would agree if the assets were uncorrelated. Here assets 0 and 1 have a sample correlation of β0.88, so asset 0, the most volatile of the four, is a strong hedge for asset 1. Minimum variance nearly triples asset 0's weight relative to inverse variance, from 8.9% to 26%. It also goes slightly short asset 2, which is positively correlated (0.41) with asset 1, the largest holding.
The KKT conditions are visible. Requiring long-only weights moves asset 2 from β0.9% to exactly zero. Its marginal variance at the long-only optimum is above the common level , so it sits at its bound, and the other weights adjust to restore equal marginal risk among the assets still held.
Shrinkage and caps are regularizers. Shrinking the covariance 20% toward a scaled identity and capping each weight at 30% both pull the portfolio toward equal weight, reducing the concentration in asset 1 from about 60% to 42% and 30% respectively. Jagannathan and Ma (2003) showed that weight constraints act as an implicit form of covariance shrinkage, which is why the two adjustments move in the same direction.
Inverting amplifies its smallest eigenvalue. Maximum Sharpe lands almost on top of minimum variance even though the sample means differ by nearly a factor of two. The reason is the spectrum of the sample covariance. Its smallest eigenvalue, , is about 19 times smaller than the next, and its eigenvector, normalized to sum to one, is roughly . Both and are dominated by the term along that direction, so both optimizers find the same nearly riskless combination. Twelve observations cannot tell a genuine hedge from a sampling accident, and the optimizers trust it completely. This is the failure mode that shrinkage, and HRP's refusal to invert , exist to guard against.
Mean-variance is driven by the means. Per-period variances are of order , so at the variance penalty is small next to expected returns of about 1% per period. The optimizer moves out of asset 1, which has the lowest sample mean, cutting it from about 60% to 6%, and into assets 2 and 3, which have the highest. Yet those means are not reliably different. Asset 2's sample mean exceeds asset 1's by 0.54% per period, with a t-statistic of about 1.3 over twelve periods. The optimizer bets heavily on a difference the data cannot confirm, which is Michaud's point in a single row.
Linear programs can have many optima. Minimum CDaR puts all of its weight in assets 2 and 3, unlike every other method. The reason is not a deep insight about drawdowns. In twelve periods, equal weight, inverse variance and long-only minimum variance also never fall below their running high, so they too have a CDaR of exactly zero. The optimum is a whole set of portfolios, and the simplex method returns one vertex of it. The result is correct: no portfolio has a lower CDaR. But it is not unique, so the weights alone mean nothing without the objective value next to them. For the same reason, cutup's reference tests compare objective values rather than weights for its linear programs. With realistic history the drawdown tail is not empty, and the method separates assets that lose in streaks from those whose losses are spread out.
For allocation research, the solver is part of the model. A general-purpose numerical optimizer that stops at a tolerance can return weights of instead of zero, or let a 40% cap read as 40.0001%. None of that matters for a single backtest. It does matter for audit trails, for compliance checks against hard limits, and for reproducing a past decision.
Cutup's solvers stop at a combinatorial certificate of optimality instead: an active set for quadratic programs, an optimal simplex basis for linear programs, and a finite set of cuts for CDaR. Binding bounds then hold exactly, and the optimality conditions hold to floating-point rounding. Each method is checked against an independent reference: closed forms and support enumeration in NumPy, SciPy's HiGHS for the linear programs, and PyPortfolioOpt, Riskfolio-Lib and scikit-learn where they implement the same estimator. The reference values are committed alongside the code, so these checks run without Python.
The library is MIT-licensed and available on crates.io, with full documentation on docs.rs. It also compiles to WebAssembly, so the same optimizer runs on a server or in the browser.