Building a Factor Risk Model: The Covariance Matrix

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

Building a Factor Risk Model: The Covariance Matrix

The last post ended on the question this one has to answer: how much of the measured past should be believed about next week? Everything the series has built so far is history. The exposures are measured characteristics, the factor returns are estimated history, and the residuals are what that history left unexplained. None of it is a forecast.

This post assembles the forecast. The deliverable is the matrix a risk model is named for, and its assembly is one line:

Where is the exposure matrix from post 2, one row per stock and one column per factor. is the covariance of the twenty factor returns, estimated from the 572 weeks of history the last post produced. is a diagonal matrix holding each stock’s own leftover risk, estimated from the 1.25 million residuals. Given any portfolio, answers the question a risk model exists for, which is how much that portfolio could plausibly move next week.

The work of the post is the two estimators, one repair each: a decaying memory for , and shrinkage toward a sector prior for the thin end of . Assembled, they price any portfolio’s risk in one pass over its holdings.

Starting From Empty

None of that arithmetic can start until its inputs exist, and for a reader arriving at this page they do not. The last post’s run produces two tables: factor_returns, with 11,440 rows (twenty factors on each of 572 Fridays), and specific_returns, with 1,253,927 rows, one per stock per week. DuckDB-WASM keeps its state in the browser tab’s memory, so landing here directly means an empty database no matter what ran before.

This post therefore builds its own entry point. One call runs the full chain: download the two parquet files, rebuild the exposure pipeline and the regression panel, solve the 572 weekly cross-sections, and write both tables back. Cold, the chain takes about twenty to twenty-five seconds, and most of that is the parquet download. The 572 regressions inside it account for well under one second. The tab ends up holding about 1.7 GB, the same steady state the last post measured, because everything after the pipeline is small next to the pipeline.

Every component below shares that one build, and none of them starts it until asked.

The Factor Covariance Matrix

With the tables in hand, the first new object is : a matrix recording, for every pair of factors, how much they move together. The raw material is the factor return history, 572 weekly observations of each of the twenty series.

The obvious estimator is the sample covariance with every week counting equally, and it makes a claim worth saying out loud: that a week from May 2013 tells us as much about next week’s risk as a week from April 2024 does. Volatility does not work that way. Calm and turbulent stretches arrive in runs, so the recent past contains most of the usable information, and a covariance that remembers 2013 at full strength will still be describing a market that no longer exists.

The standard repair is to let the memory decay. Each week gets a weight that halves with every half-life of age:

and the covariance between factors and is the weighted average product of their deviations:

Where is the number of weeks, is factor ’s return in week , is the mean of that series under the same weights, and is the half-life: the age, in weeks, at which an observation’s influence has fallen to half of a brand-new one’s. The denominator in the weights makes them sum to one.

This model uses weeks. At that setting the standard effective-sample-size calculation, , comes to about 150: the estimate behaves as if it were built from roughly 150 equally weighted weeks rather than 572, concentrated at the recent end. The oldest week in the sample still participates, at about 1/2,000 the weight of the newest.

For scale, the median factor volatility at this half-life is about 0.97% per week, or 7% annualized (multiplying a weekly volatility by throughout). The country factor, which the last post showed is the cap-weighted market by another name, runs 17.3% annualized.

Choosing the Half-Life

The formula takes as given, and the choice trades speed against stability. A short half-life notices a regime change sooner and hands the estimate less data to average over. A long one is steady and slow, and it will still be underweighting March 2020 in June.

Barra splits the decision. USE4 estimates volatilities at an 84-trading-day half-life and correlations at 504, which on weekly bars is roughly 17 weeks and 100 weeks: fast on the sizes of moves, slow on the pattern of co-movement. A single 52-week half-life sits between the two, and the measured sensitivity is what licenses collapsing the split: re-estimating the correlation matrix at half-lives of 17, 26, 52, and 104 weeks moves no entry by more than 0.19, and most far less. The pattern of co-movement is stable across the settings. The sizes of moves are not, which is why the interactive below has a slider instead of this post having three more paragraphs.

Drag the half-life slider to re-estimate the matrix in place. The grid is the correlation between each pair of factor returns, and the diagonal is annotated with each factor’s own annualized volatility.

Factor Correlation Heatmap

Needs the full factor return history: a parquet download, the pipeline, and 572 weekly regressions, twenty to twenty-five seconds cold. Shared with the risk decomposition below, so whichever runs first pays it once.

The Cell the Last Post Flagged

One cell of that grid arrives with a marker on it. The last post measured the exposure columns for volatility and beta correlated at 0.571 across stocks, declined to orthogonalize them, and promised that if the covariance matrix came back with the two factors joined at the hip, that decision was the line to revisit. Here is the covariance matrix. At the 52-week half-life, the correlation between the volatility and beta factor returns is 0.10.

The gap between 0.571 and 0.10 is the cross-sectional regression doing the job it was built for. Recall that each factor return is the return of a portfolio constructed to have one unit of its own exposure and zero of every other factor’s, within its week. Correlated input columns widen the error bars on that construction, but the hedge itself is exact: the volatility portfolio built each Friday has a beta exposure of zero on that Friday. What the weekly hedge cannot do is reach across weeks, so the 572 hedged portfolios remain free to co-move through time, and is where that co-movement would show up.

Measured, it shows up small and unstable. The volatility-beta correlation reads 0.38 at a 17-week half-life, 0.29 at 26, 0.10 at 52, and at 104. Weighted toward recent years the two factors co-move a little, and over the full history they barely co-move at all, which is not the signature of two factors that are secretly one. The orthogonalization the last post declined stays declined, on evidence this time rather than on effort.

Specific Risk

prices the risk stocks share. prices the risk they do not: the earnings surprise, the recall, the merger rumor, everything the twenty factors decline to explain. The raw material is the residual series the regression left behind, 1,253,927 of them, and the estimator is the same idea as pointed at one stock at a time. Each stock's specific variance is the exponentially weighted average of its own squared residuals, at the same 52-week half-life:

Where is stock ’s residual in week and the weights decay with age as before, normalized within the stock’s own history. No mean is subtracted. A specific return is defined as the part of a stock’s return the model does not explain, with nothing systematic left in it, and granting each ticker a fitted mean would let eleven years of realized drift read as low risk. Squaring around zero errs the other way: whatever true drift exists inflates the estimate rather than shrinking it.

Computationally this is a weighted GROUP BY over 1.25 million rows, which is the shape of work the series brought DuckDB in for. The whole of is one SQL query, and it runs in 578 ms.

Thin Histories

The estimator has a failure mode, and this panel is full of it. The median ticker has 375 weeks of residuals to average over, which is plenty. But 527 of the panel’s 3,703 tickers have less than a year, 337 have less than six months, and the minimum is a single week. These are the same young companies whose missing exposures the last post imputed, now missing history instead of fundamentals. A variance computed from one squared residual is not an estimate so much as a coin flip promoted to the diagonal of a risk model.

The repair is to trust each stock’s own estimate in proportion to how much history backs it, and to fill the balance from stocks like it:

Where is the ticker’s residual count and the constant 26 sets the prior’s weight at half a year of pseudo-observations. The prior is the mean raw variance of the ticker’s sector, computed only from tickers with at least a year of history, so the thin estimates being repaired do not also set the target they are pulled toward. A sector with no trusted ticker falls back to the universe-wide mean. This is the simplest defensible version of the Bayesian shrinkage Barra applies at the same spot in USE4.

The prior is sector-level rather than one number for everyone because the sectors differ: the trusted-ticker means range from 23.9% annualized specific volatility in Utilities to 61.1% in Health Care, a spread of 2.6 times. Shrinking a one-week biotech toward a universe average would hand it a utility’s risk.

There is deliberately no minimum-history cutoff. At the blend is 96% prior already, which is everything a hard floor would have accomplished, without the cliff at whatever count the floor was set to. Measured across the panel, the shrinkage moves 533 of the 3,703 estimates by more than a quarter, and it reaches 466 of the 527 thin tickers by more than 10%, which is the rule doing its work on the population that needed it. For the 2,492 tickers alive in the panel’s final week, the shrunk estimates put the median stock’s specific risk at 31.0% annualized, with 18.8% at the tenth percentile and 62.4% at the ninetieth.

The Assembled Model

Both halves now exist, so we can cash in the line from the introduction. On the panel’s final week, is the exposure matrix for the 2,492 live stocks, is the factor covariance, carries the 2,492 shrunk specific variances on its diagonal, and

is a full covariance matrix over every pair of stocks. Pause on what that line just bought. A 2,492-stock universe has distinct pairwise covariances, and the factor structure prices every one of them from 210 numbers in (, symmetric) plus 2,492 in . That compression is the entire reason the series built factors first and covariances second.

Materialized, would be doubles, on the order of 50 MB. Nothing in this post builds it, because nothing needs it. For a portfolio with weight vector , the predicted variance folds into:

Where is twenty numbers: the portfolio’s own factor exposures, each one a weighted average of its holdings’ exposures. In physical terms, the computation compresses the whole portfolio down to twenty factor bets, pushes those bets through , and then adds back each holding’s private noise, scaled by the square of its weight. The cost is one pass over the holdings and one sandwich, whatever the portfolio’s size.

Pick a portfolio below to run that computation on the panel’s final week. The bar splits the predicted variance into its factor and specific parts, with the per-factor contributions alongside.

Portfolio Risk Decomposition

Needs the full factor return history, F, and Δ: about twenty to twenty-five seconds cold. Shared with the heatmap above, so this is nearly instant if you have already built that.

For the cap-weighted universe, the model predicts 17.5% annualized volatility, with 97.8% of the variance coming from factors. That headline number has a witness. The country factor’s own volatility at the same half-life is 17.3%, and the last post’s constraint identity says the cap-weighted universe is the country factor’s portfolio, up to terms the constraint zeroes out and a residual the weighting leaves behind. The two agreeing to within a fifth of a point is the identity showing up in risk units.

Equal weight tells the other story. Predicted volatility rises to 23.1% (equal weighting tilts hard toward small, volatile names), while the specific contribution falls to 0.8 points, because at equal weights is the average specific variance divided by 2,492. Diversification has already done everything it can do by that point. What remains is factor risk, which no amount of adding stocks removes, and the whole Investments 101 argument about systematic risk is sitting inside that one readout.

One piece of machinery the series plan promised never made it in. The plan called for eigenvalue clipping: detect negative eigenvalues in the assembled covariance and repair them, since a matrix with a negative eigenvalue prices some portfolio at negative variance, and finding that portfolio is what an optimizer is paid to do. A covariance estimated the way this post estimates it does not need the repair. Every week shares one set of weights, so for any vector of factor bets , the variance assigns it is a weighted sum of squares: , with the vector of twenty factor returns in week and its weighted mean. inherits the property. The smallest eigenvalue of at the working half-life agrees, pricing the least-risky factor combination at about 0.9% annualized volatility. Clipping belongs to estimators that give up the common weights (pairwise-complete covariances, Newey-West adjustments, half-lives short enough that the effective sample falls below the factor count), and this model uses none of them.

What’s Next

The model the series set out to build now exists end to end: two parquet files become exposures, exposures become weekly factor returns and residuals, and those become , , and a that prices the risk of any portfolio over the 2,492 live names, entirely in a browser tab. The four posts map onto the four objects, and each one was measured before it was trusted.

What the series has not done is use the model. Everything a risk model is for (portfolio construction, hedging, tilting toward an alpha without buying risk that was not asked for) lives one step further, in optimization, where the objects this post avoided materializing stop being avoidable. A mean-variance optimizer wants as an operator, wants it inverted or factored, and wants it many times per second, which is a real numerical workload. Whether that post gets written is an open question. The model no longer depends on it: is assembled, and the question the last post ended on has a number attached at every half-life the slider can reach.