This chapter defines how the library measures, from stored history, how much series move (their volatility) and how they move together (their correlation). The first use is the exposure model of a cross-currency trade, which needs the correlation between each currency's interest-rate factor and the FX rate; FX volatilities come from here too until FX option markets are stored. The chapter defines returns, how series published on different calendars are aligned, the equally weighted and the exponentially weighted estimators, how a volatility is expressed per year, and how a matrix of correlations that is not valid is repaired. Everything here runs on plain numbers: historical statistics are inputs to models, not prices, and are never differentiated.
17.1 Notation
| Symbol | Meaning |
|---|---|
| \(m\) | The number of series |
| \(x_i(d)\) | The level of series \(i\) on date \(d\), as stored |
| \([d_a, d_b]\) | The window: the first and the last date considered |
| \(D_i\) | The dates on which series \(i\) has a stored level |
| \(t_0 < t_1 < \dots < t_N\) | The common dates: the dates in the window on which every series has a level |
| \(h\) | The horizon: the number of common dates a return spans, \(h \ge 1\) |
| \(r_i(k)\) | The return of series \(i\) from \(t_k\) to \(t_{k+h}\), for \(k = 0, \dots, n - 1\) |
| \(n = N + 1 - h\) | The number of returns |
| \(\bar r_i\) | The sample mean of the returns of series \(i\) |
| \(C_{ij}\) | The covariance of the returns of series \(i\) and \(j\) |
| \(\rho_{ij}\) | The correlation of the returns of series \(i\) and \(j\) |
| \(\lambda\) | The EWMA decay factor, \(0 < \lambda < 1\) |
| \(w_k\) | The weight of return \(k\) |
| \(P\) | The number of common dates per year |
| \(\sigma_i\) | The annualised volatility of series \(i\) |
| \(A\), \(X\) | A symmetric matrix and its nearest correlation matrix |
| \(W = \operatorname{diag}(w_1, \dots, w_m)\) | Positive weights of the rows of \(A\) |
| \(\lVert M \rVert_W\) | The weighted Frobenius norm \(\lVert W^{1/2} M W^{1/2} \rVert_F\) |
| \(\mathcal S\), \(\mathcal U\) | The positive semi-definite matrices, and the symmetric matrices with ones on the diagonal |
| \(Q \Lambda Q^\top\) | The eigen-decomposition of a symmetric matrix: \(Q\) orthogonal, \(\Lambda\) diagonal |
17.2 Returns
A return is how much a series moved between two dates. Prices and FX rates are positive and move in proportion to their level, so their return is the log return:
Interest rates and spreads can be zero or negative and move by amounts that do not scale with their level, so their return is the difference:
In words: a log return of 0.01 is a rise of about one percent; a difference of 0.0001 in a rate stored as a decimal is a rise of one basis point. A log return needs both levels to be positive; the library refuses a non-positive level rather than skip it.
With a horizon \(h > 1\) the returns overlap: consecutive returns share \(h - 1\) of their steps. Overlapping returns keep every date in use (no data is thrown away to make the returns independent), at the price of returns that are correlated with their neighbours; the estimates below stay unbiased, but their sampling error is larger than \(n\) independent returns would give. As a rule of thumb, \(n\) overlapping returns over \(h\) steps are worth about \(n / h\) independent ones: a correlation of 0.3 from 60 overlapping weekly returns (\(h = 5\)) carries about the uncertainty of one from 12 independent returns, a standard error near \((1 - 0.3^2)/\sqrt{12} \approx 0.26\).
Default return kind. When the user does not choose, the front ends take a
log return for an FX outright (a quote such as USD/SAR SPOT | Mid) and for a
data series whose units are not a percentage or basis points (a price index,
an FX rate published as a data series), and a difference for every other
series: rates, spreads, fixings, FX points, and data series in percent or
basis points.
17.3 Aligning series
Series are published on their own business days. The Saudi weekend is Friday and Saturday since 29 June 2013 (Thursday and Friday before); the New York weekend is Saturday and Sunday. Holidays differ too. Returns of two series can only be compared when they cover the same period, so the library keeps only the common dates:
in increasing order, and measures every return between common dates. A Riyadh series and a New York series thus meet on Monday to Thursday outside holidays. A return that spans a weekend or a holiday is simply a longer step; no value is filled in.
Asynchronous closes. Riyadh closes many hours before New York. A move in New York after the Riyadh close shows in the New York series today and in the Riyadh series tomorrow, which biases one-day correlations towards zero. Returns over two common dates (\(h = 2\), the default) halve the share of each return affected; weekly returns (\(h = 5\)) reduce it further. One-day returns (\(h = 1\)) remain available.
17.4 Equally weighted estimates
With equal weights, the sample mean, covariance and correlation of the returns are
In words: the covariance averages the product of the two series' deviations from their own mean, dividing by \(n - 1\) so that it is unbiased for independent returns; the correlation (Pearson's) divides it by the two standard deviations, which puts it between \(-1\) and \(1\). The diagonal of the correlation matrix is exactly 1, and the matrix is positive semi-definite because it is computed from one set of common dates. A series that does not move over the window has \(C_{ii} = 0\) and no correlation; the library refuses it.
17.5 Exponentially weighted estimates
The exponentially weighted moving average (EWMA) gives recent returns more weight, so the estimate follows changes of regime faster (J.P. Morgan and Reuters, 1996). The weight of return \(k\) falls by the factor \(\lambda\) per return into the past, and the weights are normalised to sum to one:
In words: the most recent return has weight about \(1 - \lambda\), the one before it \(\lambda\) times that, and so on. RiskMetrics' \(\lambda = 0.94\) (the default) gives the last 30 returns about 84% of the weight. The mean is taken as zero, as RiskMetrics does: over short horizons the mean return is small against its noise, and estimating it would add noise. Normalising the weights makes the estimate independent of any starting value; it equals the running sums \(S(k) = \lambda S(k-1) + r(k)^2\) and \(M(k) = \lambda M(k-1) + 1\) divided, \(S/M\). The correlation is then Equation (17.6) applied to this \(C\).
17.6 Annualised volatility
A volatility is quoted per year. The library counts the common dates per year over the span they cover,
where \(t_N - t_0\) is in days. In words: \(C_{ii}\) is the variance of an \(h\)-step return, \(C_{ii} / h\) the variance of one step between common dates, and \(P\) such steps make a year. \(P\) is measured, not assumed: two series on the same five-day week give about 252 common dates a year, a Riyadh series against a New York series about 200, since their weeks share four days. With EWMA, \(C_{ii}\) is the RiskMetrics variance about a zero mean (Section 17.5), so \(\sigma_i\) is the RiskMetrics volatility scaled the same way. A log-return volatility is a decimal (0.08 for 8%); a difference volatility is in the series' units per square-root year (a rate stored as a decimal gives 0.01 for 100 basis points a year; a FRED rate in percent gives 1.0).
17.7 Nearest correlation matrix
A correlation matrix assembled from estimates on different windows, or edited by hand, may not be positive semi-definite: some combination of the series would have a negative variance, and a simulation cannot draw from it. The nearest correlation matrix (Higham, 2002) solves
In words: among the valid correlation matrices, find the one closest to \(A\), where a larger weight \(w_i\) makes changes to row and column \(i\) cost more.
Both sets are convex, and each has a simple projection in the \(W\)-norm (for a diagonal \(W\)):
where \((Q \Lambda Q^\top)_+ = Q \max(\Lambda, 0) Q^\top\) sets the negative eigenvalues to zero. Projecting alternately onto the two sets would reach a matrix in both, but not the nearest one; Dykstra's correction (Dykstra, 1983) fixes that. Starting from \(Y_0 = A\) and \(\Delta S_0 = 0\), each iteration computes
- \(R = Y_k - \Delta S_k\),
- \(X_{k+1} = P_{\mathcal S}(R)\),
- \(\Delta S_{k+1} = X_{k+1} - R\),
- \(Y_{k+1} = P_{\mathcal U}(X_{k+1})\),
and stops when \(\lVert Y_{k+1} - Y_k \rVert_F\) and \(\lVert Y_{k+1} - X_{k+1} \rVert_F\) are both below the tolerance (by default \(10^{-10}\)) times \(\lVert Y_{k+1} \rVert_F\). The library returns \(D^{-1/2} X D^{-1/2}\) with \(D = \operatorname{diag}(X)\): it is positive semi-definite like \(X\), has an exact unit diagonal, and differs from \(X\) by no more than the tolerance. A valid correlation matrix comes back unchanged.
Example (Higham, 2002, section 4). The matrix with ones on the diagonal, 1 next to it and 0 in the corners is not positive semi-definite (its eigenvalues are \(1 - \sqrt 2\), 1 and \(1 + \sqrt 2\)). Its nearest correlation matrix in the unweighted norm has 0.7607 next to the diagonal and 0.1573 in the corners.
17.8 Eigen-decomposition by Jacobi rotations
The projection \(P_{\mathcal S}\) needs the eigenvalues and eigenvectors of a symmetric matrix. The library uses the cyclic Jacobi method (Golub and Van Loan, 2013, section 8.5): a plane rotation \(J\) in rows and columns \(p\) and \(q\) is chosen to make entry \((p, q)\) of \(J^\top A J\) zero,
with \(J_{pp} = J_{qq} = c\), \(J_{pq} = s\), \(J_{qp} = -s\); \(t = \tan\theta\) is the smaller root of \(t^2 + 2\beta t - 1 = 0\), so each rotation turns by at most 45 degrees. A sweep applies a rotation to every pair \(p < q\); sweeps repeat until the off-diagonal entries are negligible against the largest entry, and the product of the rotations gives the eigenvectors. Rotations preserve the eigenvalues, and the off-diagonal mass falls quadratically once small, so a few sweeps suffice. Jacobi is slower than the tridiagonal QR method for large matrices but accurate to working precision, and correlation matrices hold a few dozen series.
17.9 Use in the exposure model
A one-factor Hull–White model per currency (Chapter 16) and a log-normal FX rate
need the instantaneous correlation between each currency's rate factor and the
FX log return, and between two currencies' factors. A factor is not observed,
so a stored rate proxies it: the 5-year swap rate of the currency's
discounting curve, differenced (USD-SOFR-OIS 5Y | Mid,
SAR-SAIBOR-3M-IRS 5Y | Mid, EUR-EuroSTR-OIS 5Y | Mid), and the FX spot
outright, in log returns (USD/SAR SPOT | Mid). The historical correlation of
these returns is then used as the model's instantaneous correlation. This is an
approximation: a one-factor model's factor moves every rate of the curve
together, while a single rate also carries the curve's other movements, so the
proxy's correlation tends to understate the factor's. The choice of tenor is a
parameter of the exposure model, recorded with it.
17.10 Worked example
Three series, from 4 to 12 October 2026: USD/SAR on Riyadh business days (Sunday to Thursday), the SOFR 5-year swap rate and EUR/USD on New York business days (Monday to Friday).
| Date | USD/SAR | SOFR 5Y | EUR/USD |
|---|---|---|---|
| 04-Oct-2026 (Sun) | 3.7500 | ||
| 05-Oct-2026 | 3.7510 | 0.0350 | 1.1000 |
| 06-Oct-2026 | 3.7505 | 0.0352 | 1.1022 |
| 07-Oct-2026 | 3.7520 | 0.0349 | 1.0989 |
| 08-Oct-2026 | 3.7515 | 0.0355 | 1.1011 |
| 09-Oct-2026 (Fri) | 0.0356 | 1.1030 | |
| 11-Oct-2026 (Sun) | 3.7530 | ||
| 12-Oct-2026 | 3.7525 | 0.0358 | 1.1004 |
The common dates (Equation (17.3)) are 5, 6, 7, 8 and 12 October (\(N = 4\)). With \(h = 1\), USD/SAR and EUR/USD in log returns and SOFR in differences, the four returns are
| Return | USD/SAR | SOFR 5Y | EUR/USD |
|---|---|---|---|
| 5 to 6 Oct | −0.00013331 | 0.0002 | 0.00199800 |
| 6 to 7 Oct | 0.00039987 | −0.0003 | −0.00299850 |
| 7 to 8 Oct | −0.00013327 | 0.0006 | 0.00200000 |
| 8 to 12 Oct | 0.00026652 | 0.0003 | −0.00063593 |
Pearson's correlations (Equation (17.6)) are −0.734654 between USD/SAR
and SOFR, −0.977360 between USD/SAR and EUR/USD, and 0.828087 between SOFR and
EUR/USD. With EWMA and \(\lambda = 0.94\) (Equation (17.7)) they are −0.339613,
−0.877060 and 0.714395: the zero mean and the heavier last return change them
noticeably on so short a window. The common dates span 7 days, so
\(P = 4 / (7 / 365.25) = 208.714\) (Equation (17.8)), and the Pearson
volatilities are 0.0039696 for USD/SAR (0.40% a year), 0.0054056 for SOFR (54
basis points a year) and 0.0347472 for EUR/USD (3.47% a year). The test
HistoricalStatisticsTests reproduces these numbers, and SeriesFunctionsTests
does so through QX.Correlation and QX.Volatility.
17.11 Dummy series
Until real series are stored, the dummy provider stores
eight synthetic daily series with known statistics, each code starting with
DUMMY-: EUR/USD, GBP/USD, USD/JPY and USD/SAR spot, the USD SOFR, SAR SAIBOR
and EUR ESTR 5-year swap rates (in percent), and a Saudi sovereign 5-year CDS
spread (in basis points). One path of correlated standard normal shocks
\(z(d)\) is drawn per calendar day \(d\) from 1 January 2016 to 15 October 2026
from a fixed seed, correlated by the Cholesky factor of a target matrix, and
for the log-normal series (FX rates, CDS spread) and the normal ones (swap
rates). Each series keeps the days of its own week, without holidays: Riyadh
series Sunday to Thursday, the others Monday to Friday. Because the shocks are
per calendar day, a return between any two common dates has the target
correlation, and Equation (17.8) recovers the target volatility. The test
DummyDataSeriesProviderTests checks that ten years of history give every
volatility within 6% of its target and every correlation within 0.06. The
values are not market data and carry a note saying so.
17.12 Edge cases
- Too few dates. At least \(h + 2\) common dates are needed (two returns); fewer is an error that names the count.
- A flat series. A series that does not move has no correlation; it is an error that names the series.
- A non-positive level under log returns is an error that names the series; choose differences for such a series.
- Nothing stored. In Excel, a series with nothing stored in the window
gives
#N/A. - Rounding. Correlations are clamped to \([-1, 1]\) against rounding; the diagonal is exactly 1.
References
- Richard L. Dykstra (1983). An algorithm for restricted least squares regression. Journal of the American Statistical Association 78(384), 837–842.
- Gene H. Golub and Charles F. Van Loan (2013). Matrix Computations. Fourth edition. Johns Hopkins University Press.
- Nicholas J. Higham (2002). Computing the nearest correlation matrix – a problem from finance. IMA Journal of Numerical Analysis 22(3), 329–343.
- J.P. Morgan and Reuters (1996). RiskMetrics – Technical Document. Fourth edition. J.P. Morgan and Reuters.