Returns to covariance
Prices become daily log returns, \(r_t = \ln(P_t / P_{t-1})\). They add across days, so variance scales linearly with the horizon. Taking the sample covariance of four assets' returns, with Bessel's correction, gives \(\Sigma\): variances on the diagonal, covariances off it.
Each term is an outer product: one day's deviation vector times its own transpose, a rank-one matrix. Averaging enough of them recovers the full covariance, which the figure does over ten simulated years.
Split it apart
\(\Sigma\) mixes two things: how much each asset moves, and how the assets move together. Pulling the volatilities out onto a diagonal matrix \(D\) leaves the correlation matrix \(\rho\), with ones on its diagonal. Watch the entries of \(\Sigma\) turn into correlations.
This split comes back in the stress test.
Factor it, column by column
To simulate, \(\Sigma\) needs a square root. The Cholesky-Banachiewicz algorithm finds the lower-triangular \(L\) with \(LL^\top = \Sigma\), one column at a time: the diagonal entry first, then everything below it. Each entry only uses entries already found: a dot product of two partial rows of \(L\), taken off \(\Sigma_{ij}\), then divided by \(L_{jj}\) (or square-rooted on the diagonal). The figure works through each one. The engine implements this by hand rather than calling a library.
Check the factor
Multiplying \(L\) by its transpose rebuilds \(\Sigma\). The difference is at machine precision, which is the engine's first built-in check. The residual on the left is computed live in your browser, in double precision.
The algorithm costs \(O(n^3/3)\), about twice as fast as LU, because symmetry means only the lower triangle is computed.
Correlate the noise
Independent standard normals \(Z\) have no structure: a round cloud. Multiplying by \(L\) stretches and shears them into returns with exactly the target covariance, because \(\operatorname{Cov}(LZ) = L\,I\,L^\top = \Sigma\). Over an \(h\)-day horizon:
Geometrically, \(L\) maps the unit circle of independent draws onto the covariance ellipse \(\{x : x^\top \Sigma^{-1} x = 1\}\), and each draw follows: the figure sends one \(z\) through \(L\) row by row.