Regression and Fitting, Part 1: Linear Regression#
Regression estimates how one quantity depends on others from noisy observations. In valuation it gives a hedge ratio, a proxy for a risk factor that is not quoted, a beta between a position and an index, and the continuation value in a Monte Carlo for early exercise. Linear regression, where the model is linear in the coefficients, has an exact solution, a standard error for every coefficient, and a short list of ways to go wrong. This page sets out the method, shows what the standard errors mean by repeating an estimation 5,000 times, and shows what happens when the regressors move together. It is the first of four pages on regression and fitting.
The model#
The data are \(n\) observations of a response \(y_i\) and \(p\) regressors, collected in the rows of a matrix \(X\), usually with a column of ones for an intercept. The model is
and the ordinary least squares estimate minimises the sum of squared residuals, \(\hat\beta = \arg\min \lVert y - X\beta \rVert^2\). It solves the normal equations,
which is computed in practice by a QR factorisation or the SVD, not by forming \(X^\top X\) (Numerical Linear Algebra). If the errors are uncorrelated with constant variance, \(\hat\beta\) is unbiased and has the smallest variance among linear unbiased estimators, and
An approximate 95% interval for a coefficient is \(\hat\beta_j \pm 1.96\,\operatorname{se}(\hat\beta_j)\), and the t-statistic \(\hat\beta_j / \operatorname{se}(\hat\beta_j)\) tests whether it is zero. The R squared, \(R^2 = 1 - \lVert y - X\hat\beta \rVert^2 / \lVert y - \bar{y} \rVert^2\), is the share of the variance of \(y\) that the regression explains.
A hedge ratio#
The best hedge of a position with return \(r_y\) using an instrument with return \(r_x\) minimises the variance of \(r_y - h\,r_x\). The solution is the regression slope,
and the share of the variance that is removed is the \(R^2\). The slope is estimated from a window of data, and the standard error tells how much of its value is information. For a single regressor, \(\operatorname{se}(\hat\beta) \approx \sigma_\varepsilon / (\sigma_x \sqrt{n})\), so it falls only with the square root of the length of the window.
Multicollinearity#
When two regressors move together, the data cannot separate their effects. With two regressors of correlation \(\rho\), the variance of each coefficient is multiplied by the variance inflation factor \(1/(1 - \rho^2)\). The fit and the sum of the coefficients are still well determined. Each coefficient on its own is not, and it changes a great deal from one sample to the next. In matrix terms \(X^\top X\) is close to singular, and its condition number is large.
Worked example#
The example regresses the daily return of a position on the return of a hedging instrument, with a true slope of 0.85, residual volatility 0.4% and instrument volatility 1%, for windows of 60, 250 and 1,000 days. It repeats the 250-day estimate 5,000 times to compare the spread of the estimates with the reported standard error and to count how often the 95% interval contains the truth. Finally it uses two regressors with a common effect and increasing correlation.
Python code
"""Linear regression: a hedge ratio with its standard error, sampling variability, and multicollinearity."""
import numpy as np
def ols(x, y):
"""Least squares with an intercept. Returns coefficients, standard errors, R squared and the residual standard deviation."""
a = np.column_stack([np.ones(len(y)), x])
beta, *_ = np.linalg.lstsq(a, y, rcond=None)
resid = y - a @ beta
s2 = resid @ resid / (len(y) - a.shape[1])
se = np.sqrt(np.diag(s2 * np.linalg.inv(a.T @ a)))
r2 = 1 - resid @ resid / np.sum((y - y.mean()) ** 2)
return beta, se, r2, np.sqrt(s2)
if __name__ == "__main__":
rng = np.random.default_rng(11)
beta_true, factor_vol, resid_vol = 0.85, 0.010, 0.004
print("1. Hedge ratio: daily returns of a position regressed on the hedging instrument, true slope 0.85")
print(f" {'Days':>6} {'slope':>8} {'std error':>10} {'95% interval':>18} {'t-statistic':>12} {'R squared':>10} {'residual vol':>13}")
for n in (60, 250, 1000):
x = rng.normal(0, factor_vol, n)
y = beta_true * x + rng.normal(0, resid_vol, n)
b, se, r2, s = ols(x, y)
print(f" {n:6d} {b[1]:8.4f} {se[1]:10.4f} {b[1] - 1.96 * se[1]:8.4f}{b[1] + 1.96 * se[1]:9.4f} {b[1] / se[1]:12.1f} {r2:10.3f} {s:13.5f}")
print("\n2. Sampling variability: 5,000 repetitions with 250 days each")
estimates, ses, covered = [], [], 0
for _ in range(5000):
x = rng.normal(0, factor_vol, 250)
y = beta_true * x + rng.normal(0, resid_vol, 250)
b, se, _, _ = ols(x, y)
estimates.append(b[1])
ses.append(se[1])
covered += abs(b[1] - beta_true) < 1.96 * se[1]
theory = resid_vol / (factor_vol * np.sqrt(250))
print(f" mean of the estimates {np.mean(estimates):.4f}, standard deviation {np.std(estimates):.4f}, mean reported standard error {np.mean(ses):.4f}")
print(f" theory: residual vol / (factor vol x sqrt(n)) = {theory:.4f}; the 95% interval contains the true slope in {covered / 5000:.1%}")
print("\n3. Multicollinearity: two regressors with correlation rho, true slopes 0.5 and 0.5, 250 days, 2,000 repetitions")
print(f" {'rho':>5} {'std dev of slope 1':>19} {'std dev of the sum':>19} {'variance inflation':>19} {'R squared':>10}")
for rho in (0.0, 0.9, 0.99, 0.999):
cov = np.array([[1, rho], [rho, 1]]) * factor_vol**2
slopes, r2s = [], []
for _ in range(2000):
x = rng.multivariate_normal([0, 0], cov, 250)
y = 0.5 * x[:, 0] + 0.5 * x[:, 1] + rng.normal(0, resid_vol, 250)
b, _, r2, _ = ols(x, y)
slopes.append(b[1:])
r2s.append(r2)
slopes = np.array(slopes)
print(f" {rho:5.3f} {slopes[:, 0].std():19.4f} {slopes.sum(axis=1).std():19.4f} {1 / (1 - rho**2):19.1f} {np.mean(r2s):10.3f}")
The output is:
1. Hedge ratio: daily returns of a position regressed on the hedging instrument, true slope 0.85
Days slope std error 95% interval t-statistic R squared residual vol
60 1.0020 0.0566 0.8911 1.1129 17.7 0.844 0.00386
250 0.8625 0.0253 0.8129 0.9122 34.0 0.824 0.00394
1000 0.8412 0.0127 0.8164 0.8661 66.4 0.815 0.00404
2. Sampling variability: 5,000 repetitions with 250 days each
mean of the estimates 0.8502, standard deviation 0.0254, mean reported standard error 0.0254
theory: residual vol / (factor vol x sqrt(n)) = 0.0253; the 95% interval contains the true slope in 94.7%
3. Multicollinearity: two regressors with correlation rho, true slopes 0.5 and 0.5, 250 days, 2,000 repetitions
rho std dev of slope 1 std dev of the sum variance inflation R squared
0.000 0.0259 0.0365 1.0 0.758
0.900 0.0573 0.0257 5.3 0.856
0.990 0.1817 0.0259 50.3 0.861
0.999 0.5753 0.0258 500.3 0.862
Reading the output:
A short window gives a wide interval, and it can miss. The 60-day slope is 1.002 with a standard error of 0.057, and its interval, 0.891 to 1.113, does not contain the true 0.85. That is expected in one sample in twenty, and the 60-day estimate is a poor basis for a hedge. The standard error falls with the square root of the window, 0.057, 0.025 and 0.013 for 60, 250 and 1,000 days. The estimates are 1.002, 0.863 and 0.841.
The R squared is the hedge effectiveness. It is 0.82 to 0.84 in all three windows, close to the theoretical 0.82, so a hedge at the estimated slope removes about 82% of the variance of the position and leaves 18%. Better data would not change that: it is the residual risk of the hedge, the basis.
The standard error is a fair measure of the spread of the estimate. Over 5,000 repetitions the estimates have a mean of 0.8502 for a true 0.85, and a standard deviation of 0.0254, the same as the mean standard error reported by the regression, 0.0254, and the theoretical 0.0253. The 95% interval contains the truth in 94.7% of the samples.
Collinear regressors have unstable coefficients and a stable sum. As the correlation rises from 0 to 0.999, the spread of the first slope grows from 0.026 to 0.575, 22 times, which is \(\sqrt{500}\), the square root of the variance inflation factor. The spread of the sum of the two slopes stays at 0.026, and the R squared does not fall, 0.76 to 0.86. The regression fits and predicts well, and says nothing reliable about the split between the two regressors.
A valuation control view#
Ask for the standard error and the window, not only the coefficient: a hedge ratio of 1.00 with a standard error of 0.06 is not distinguishable from 0.85. A proxy or a beta that is used in a valuation needs an interval, and the interval is an uncertainty that can feed a reserve (Prudent Valuation: Requirements).
Read the R squared as the quality of the proxy: a proxy regression with an R squared of 0.5 leaves half of the variance unexplained, and the valuation of the position carries that.
Check the assumptions on the residuals: constant variance, no autocorrelation, no outliers. Residuals that are larger in volatile periods, or that are correlated from day to day, make the reported standard errors too small. Robust and weighted fits are in Regression and Fitting, Part 4: Least-Squares Fitting.
Test the stability of the coefficient over time: a slope that moves when the window is shifted by a month is not a parameter, and the relationship may have changed. Compare windows, and look for a break.
Be careful with correlated regressors: a model with two factors that move together gives coefficients that cannot be interpreted one by one. Look at the variance inflation, the condition number, and the stability of the coefficients across samples.
Next, Regression and Fitting, Part 2: Polynomial Regression extends the regression to a polynomial in the regressor, which is still linear in the coefficients and raises the question of how many terms to use.