Building a Factor Risk Model: The Optimizer

financerisk-modelsfactor-risk-model
Factor Risk Models · Part 5 of 5

Building a Factor Risk Model: The Optimizer

The last post ended by calling this one an open question, and by then the model no longer needed it: was assembled, and it priced any portfolio’s risk in one pass over the holdings. What no post has done is put one of those prices at risk. Every check the series has run compared the model to the same 572 weeks that built it, and the one headline forecast (17.5% annualized volatility for the cap-weighted universe) was made on the sample’s final week, where nothing exists to grade it against.

A forecast earns trust only on data its maker never saw, and the standard way to arrange that is to hide some. This post rolls the clock back two years: the whole model is re-estimated as if the date were April 2022, a random 30-stock portfolio is drawn on that date, an optimizer reshapes it three different ways, and every predicted number is graded against the 104 weeks that follow. The deliverable is the grade.

Rolling Back the Clock

Call the panel date 104 weeks before the end of the sample the formation date: April 29, 2022. The 572-week panel splits there into the 468 weeks the model may see and the 104 it may not (468 + 104 = 572). Everything the optimizer touches is estimated from the first piece, and everything it is graded on comes from the second.

The split is less mechanical than it sounds, because the panel’s timing convention makes look-ahead easy to commit by accident. A row dated records the return realized over the week after , and the factor return and residuals dated come out of the regression at , which explains those forward returns. On the formation date itself, the factor return dated April 29 has not happened yet. is therefore estimated from factor returns dated strictly before formation, from residuals dated strictly before it, and the holdout is the 104 forward returns dated formation onward. Nothing the optimizer sees postdates the weights it chooses.

One bias is accepted rather than avoided, and it cuts two ways. The draw universe is the 2,193 tickers with a panel row on every one of the 104 holding dates, because each of those rows supplies one week the portfolios must be graded on. A name that delisted in month eight was never a candidate, which is survivorship: every return level below is biased upward. Comparing the draw against its optimized variants shares that bias, since every variant reweights the same thirty names. No such symmetry protects the predicted-against-realized comparison. Holding a panel row means passing the panel’s investability screens through the weeks being graded, so the weeks that would have spiked realized volatility are the likeliest ones missing, and realized volatility prints low against the forecast.

A Portfolio Nobody Chose

Any portfolio picked for a demonstration smuggles in a story, if only the author’s hindsight about which names would make the charts persuasive. A random one has no story to smuggle. The draw is 30 names sampled uniformly from the 2,193, with weights drawn uniformly from all fully-invested long-only weightings (a flat Dirichlet). Equal weights would read as an index. These read as an account someone owns, a few positions of conviction and a tail of small ones.

The randomness is seeded, so a portfolio here is a number. The lab below opens on seed 1, and typing the same seed on any machine replays the same thirty names with the same weights. Every measured claim in this post names its seed or its seed range.

The Optimizer

The last post refused to materialize , because at universe scale it is doubles answering questions nobody asked. The optimizer asks. Over thirty drawn names, is a matrix (900 entries, priced by the same 210-number and thirty entries of ), small enough to build explicitly and hand to a solver.

Everything we ask of that solver is one problem with different inputs:

Where is the vector of thirty weights, is a per-name reward (zero when only risk matters), and and are per-name bounds. The budget constraint forces full investment. The bounds are where the three objectives will differ, and they are also what rules out the textbook shortcut: with a box in play, the closed-form Lagrangian answer can demand a negative weight, and clipping it back to zero breaks the budget.

The solver is a primal active-set method, and the idea reads physically. Guess which weights are pinned to a bound. With the pinned names frozen, the problem over the free names has an equality-constrained solution that costs two triangular solves against the free block of , using post 3’s fifty-line Cholesky solver unchanged. If that solution steps outside the box, we walk toward it, stop at the first bound in the way, and pin the blocking name. When the current pinning is optimal, each pinned name’s KKT multiplier reports whether releasing it would improve the objective. Release the worst offender and repeat, and when no pinned name asks to be released, the weights are optimal.

Termination is a property the series purchased two posts in advance. The active-set method’s guarantee of finishing rests on being positive definite, and the last post’s aside on eigenvalue clipping proved the estimator delivers this: the common-weights argument keeps from pricing any factor bet at negative variance, and the strictly positive diagonal of does the rest. That aside also warned that a covariance without the property prices some portfolio at negative variance, and that finding it is what an optimizer is paid to do. This section is where the warning stops being hypothetical, because now the optimizer exists.

Three Objectives

Minimum variance sets with bounds of zero and one: the least predicted variance any long-only, fully-invested reweighting of the thirty names can reach. Nobody runs money this way. It is the benchmark end of the spectrum, the answer to how much risk can leave the portfolio without shorting anything.

Banded minimum variance keeps but confines every weight to within two percentage points of its drawn value, floored at zero. Against a mean weight of , the band is roomy in relative terms, yet every position remains recognizably the one drawn. This is the realistic ask: keep the portfolio, then shed whatever predicted risk the band allows.

Toy alpha sets , with the drawn names’ momentum exposures from post 2 and chosen by bisection so that the optimized portfolio’s predicted variance matches the draw’s own. The comparison is then made at matched risk, the same predicted variance pointed at a signal instead of at nothing. Momentum is a stand-in here, chosen because the reader has already met it. The variant exists to show what an optimizer does with a signal, not to argue that momentum is one.

The units of deserve an aside, because real alphas are not raw scores. The standard refinement (Grinold) is : a standardized score , scaled by the signal’s information coefficient (its correlation with what it forecasts) and by the stock’s residual volatility . In that setting, residual means residual to the benchmark; the nearest object this model owns is the specific volatility . Our momentum exposures are already cross-sectional z-scores, and the risk-matched construction makes the IC invisible: scaling every by the same constant is absorbed into , and the bisection returns the same portfolio. The toy omits only the term, which would enlarge the scores of volatile names and tilt the frontier toward them. For our purposes the bare score keeps the variant legible.

The lab below runs all of it. The first click builds the same factor-return history as the last post’s widgets (twenty to twenty-five seconds cold, nearly instant if another widget already built it), estimates and as of the formation date, draws seed 1, and grades all four portfolios. The summary table is the exam: predicted volatility is a forecast made with data through April 2022, realized volatility is what the 104 holdout weeks delivered, and the chart compounds each variant’s weekly returns across the holdout. The tabs read any variant’s style exposures beside the draw’s, and the holdings table pairs the drawn weights with the selected variant’s.

Portfolio Lab

Estimates the model as it stood 104 weeks before the end of the sample, draws a random portfolio on that date, optimizes it three ways, and grades everything on the weeks the model never saw, re-estimating and rebalancing at the cadence you choose. Needs the full factor return history: about twenty to twenty-five seconds cold, nearly instant if another widget already built it.

The Grade

Seed 1 deserves a reading before any averages. The draw was predicted at 29.0% annualized volatility and realized 28.6%. Min variance was predicted at 17.1% and realized 17.1%. Both forecasts were made in April 2022 about two years no estimate had touched, and the second is the kind of agreement that looks typed in. It is not typical to the tenth of a point, but the table below says it is not far from typical either.

Returns are another matter. On seed 1 the draw lost 10.5% over the two years while min variance made 13.6%, and on other seeds the gap runs the other way. One window grades luck. The honest exam reruns the lab over seeds 1 through 50 and averages, and the table gives the results, with the gap column as realized minus predicted volatility.

portfoliopredicted volrealized volgaptwo-year return (mean / median)realized vol below the draw’s
Random draw24.3%24.0%−0.4pp+15.9% / +15.3%—
Min variance16.8%17.4%+0.6pp+8.6% / +10.0%49 of 50
Banded min variance21.2%21.3%+0.1pp+13.7% / +13.8%50 of 50
Toy alpha24.3%21.1%−3.2pp+16.5% / +13.6%43 of 50

Two results in that table are the reason the series exists. The first is calibration: for the three diversified rows, forecast and realization agree to within 0.6 points of annualized volatility, on portfolios the model had never seen. For an estimator whose every constant was chosen for defensibility rather than fitted, the agreement is closer than its simplicity promised. The second is that the optimization is real ex post. Min variance realized less volatility than its own draw in 49 of 50 seeds, and the banded variant in 50 of 50. Those predicted-variance reductions were claims about an unseen future, and the future confirmed them.

The cost side behaves the way the tradeoff says it must. Min variance kept 8.6 of the draw’s 15.9 points of mean two-year return, while the banded variant kept 13.7. Put against the risk numbers, the band recovered 2.7 of the 6.6 realized-volatility points that full min variance removed, at 2.2 points of forgone return against min variance’s 7.3: about 40% of the risk reduction for about 30% of the return cost. The first increments of de-risking come cheap, and the band’s whole design is to buy only those.

These return numbers need a hedge the volatility numbers do not. The holdout is one path, May 2022 through April 2024, a drawdown followed by a rally that rewarded the market exposure min variance sheds. All fifty seeds live inside that path, so the return column is fifty correlated observations of one regime. The volatility calibration repeats across seeds. The return ranking could flip in a different two years.

The Error Maximizer

The toy alpha row is a demonstration of the oldest charge against mean-variance optimization: that an optimizer is an estimation-error maximizer (Michaud), betting hardest wherever its inputs flatter it most, which is wherever they are most likely wrong. Measured, the charge looks like this. On seed 1 the variant put 61.9% of the portfolio into one name. A convenient summary is the effective number of names, , the count of equal-weight positions with the same concentration: 14.6 for the draw, 8.3 for min variance, 2.3 for the toy alpha. Thirty names went in, and a bet on roughly two came out.

Across the sweep, concentration shows up as a mean return above the draw’s (16.5% against 15.9%) with a median below it (13.6% against 15.3%). A few seeds found large winners and most did not, which is the distribution a two-name bet produces.

The toy alpha is also the one row the model misprices, realizing 3.2 points under its predicted volatility. The leading suspect is a choice the last post made deliberately. Specific variances square residuals around zero, so a stock’s realized drift reads as risk, and high-momentum names are by construction the names with realized drift behind them. A concentrated portfolio leans on those per-name estimates far harder than a diversified one, since specific variance enters the prediction as and squared weights punish concentration. The miss runs conservative, and in the direction the last post said that choice would err.

This behavior, more than any subtlety in the math, is why production optimizers arrive wrapped in constraints: position bounds, factor-exposure bounds, turnover penalties. The QP solves its stated problem to machine precision. The problem is built from estimates, and constraints meter how much of the account is allowed to depend on any one of them. The banded variant is the same machinery with that lesson applied, and it produced the sweep’s only 50-of-50 row.

The Series’ Report Card

Five posts built five objects: a data pipeline, an exposure matrix, a history of factor returns and residuals, a covariance model, and an optimizer graded out of sample. Two parquet files and a browser tab produced risk forecasts that stayed within roughly half a point of realization across fifty random portfolios, two years out of sample, and an optimization whose promised risk reduction showed up in 99 of the 100 seed trials it was graded on (min variance and the band, fifty each).

The same exam drew the model’s boundary. Pointed at risk, its numbers survived contact with a future it never saw. Handed a return forecast, it spent estimation error as if it were information, and needed constraints to be trusted with money. The open question at the end of the last post has its answer, and the series ends where a risk model’s competence does: silent on what will go up, and accurate, two years in advance, about how much it could move.