The Interview Book · Careers
15Linear Algebra and Calculus
A risk system rejects the morning’s correlation matrix: one eigenvalue is . The quant on call is asked, before touching any code, why three pairwise correlations that each look reasonable can be impossible together, and what the nearest valid matrix is. Linear algebra and calculus questions in interviews are rarely about technique for its own sake; they are about the few facts that recur in finance (a covariance matrix must be positive semidefinite, a regression is a projection, a Gaussian integral has a closed form, a constrained optimum has a multiplier) and about using them quickly.
15.1 Eigenvalues, definiteness and correlation matrices
A covariance or correlation matrix is symmetric positive semidefinite: is the variance of the portfolio and cannot be negative (One Quant Book 4, chapter 22). Equivalently all eigenvalues are non-negative, or all principal minors are. Pairwise estimation, missing data and hand-edited stress scenarios break this property, and interviews ask how to see it and repair it.
Proposition 15.1 (The third correlation)
Given and , the correlation matrix is positive semidefinite exactly when
Proof. The determinant is a concave quadratic in whose roots are the two bounds; between them it is non-negative, and the minors are non-negative for correlations in . ∎
fig_iv_corr.py.Example 15.2 (Equicorrelation)
An matrix with ones on the diagonal and elsewhere is . Its eigenvalues are , with eigenvector , and with multiplicity , so it is a correlation matrix exactly when . Ten assets cannot all be pairwise correlated at .
Method 15.3 (Repairing a correlation matrix)
- Check: compute the smallest eigenvalue; a Cholesky factorisation that fails is the fast test.
- Repair by clipping: set negative eigenvalues to zero (or a small floor), rebuild, and rescale to a unit diagonal (eigenvalue clipping, One Quant Book 4, chapter 22).
- Repair by the nearest correlation matrix in the Frobenius norm (Higham, 2002): alternate projections onto the positive semidefinite cone and onto unit-diagonal matrices.
- Say which entries moved most, since they are the ones the data did not support.
15.2 Projections and least squares
Ordinary least squares projects the vector of observations onto the column space of the regressors . The hat matrix is symmetric and idempotent, its eigenvalues are 0 and 1, and its trace is the number of regressors ; its diagonal entries are the leverages, which average . The residual is orthogonal to every column of , and is the squared cosine of the angle between the centred and its projection.
Example 15.4 (A rank-one update)
has eigenvalue in the direction of and 1 on the orthogonal complement, and its inverse is (Sherman–Morrison). A one-factor covariance matrix is this form, and its inverse is what minimum-variance portfolios need.
15.3 Integrals, series and expansions
A handful of results covers most calculus questions: ; for a standard normal , , and ; for ; and Taylor’s theorem with a remainder, which turns “approximately” into a bound.
Method 15.5 (Integrals in an interview)
- Look for a density: an integrand that is a density times something is an expectation.
- Complete the square in an exponent; it turns a Gaussian integral with a linear term into a shifted one.
- Use symmetry to kill odd moments.
- Differentiate under the integral sign, or with respect to a parameter of a known series.
15.4 Optimisation with a constraint
A constrained optimum sets the gradient of the objective parallel to the gradient of the constraint. The minimum-variance portfolio fully invested () is ; the portfolio of highest expected return at a given volatility is proportional to , scaled to the volatility (One Quant Book 7, chapter 25, on mean–variance construction).
Example 15.6 (Two assets)
With volatilities and correlation , the minimum-variance weight on the first asset is . With 20%, 10% and 0.3 it is about 0.105, for a portfolio volatility of about 9.8%, below that of either asset.
15.5 Worked answers
Example 15.7 (The volatility of a pair trade)
“Long one unit of a stock with 20% volatility, short one unit of a peer with 25%, correlation 0.9. What is the volatility of the pair?” Write the quadratic form with : , a volatility of . Checks: at correlation 1 the pair’s volatility would be the difference, 5%; at 0 it would be ; 11% lies between and near the high-correlation end. The answer also shows why pairs are sized by volatility: with the short scaled to units the variance falls to , about 8.9%.
Example 15.8 (Integration by parts against a normal)
“For a standard normal , compute .” Since , integrating by parts gives for smooth of moderate growth. So , the real part of the characteristic function at 1: . The identity is worth knowing by name (Stein’s lemma), because it also gives in one line and appears in the Greeks of Chapter 17.
Example 15.9 (Newton’s method on a transcendental equation)
“Solve to four decimals, by hand.” With and , start at , where : the step is , so . One more step gives , and the next changes only the sixth decimal: . Newton roughly doubles the number of correct digits at each step, which is why the same method solves for an implied volatility or a yield in two or three iterations from a sensible start.
15.6 Question bank
Interview question 15.1 ★ researcher, bank • any
What are the eigenvalues and eigenvectors of ?
Solution
Solution of Interview question 15.1.
The matrix is in two dimensions: eigenvalue 3 with eigenvector and 1 with . Trace 4 and determinant 3 confirm.
What the interviewer is looking for: recognising the structure and checking with trace and determinant.
Interview question 15.2 ★ researcher, risk • bank
Is the matrix with unit diagonal, and a valid correlation matrix? How do you see it quickly?
Solution
Solution of Interview question 15.2.
No. By Proposition 15.1, with the third correlation must lie in . The determinant is , and the eigenvalues are , 1.9 and 1.9. Intuitively, assets 2 and 3 cannot both move with asset 1 and against each other.
What the interviewer is looking for: a feasibility check by the bound or the determinant, with the intuition.
Interview question 15.3 ★ researcher, bank • bank
For a standard normal , compute and .
Solution
Solution of Interview question 15.3.
Completing the square, (the lognormal mean). (the fourth moment of a normal, used as the benchmark kurtosis).
What the interviewer is looking for: the moment generating function and the normal kurtosis.
Interview question 15.4 ★ researcher, trader • any
Compute .
Solution
Solution of Interview question 15.4.
Differentiate : , which at is 2. (It is also the mean of a geometric waiting time.)
What the interviewer is looking for: differentiating a known series.
Interview question 15.5 ★★ risk, researcher • bank
Two assets have correlations 0.8 and 0.6 with a third. What values can their correlation with each other take?
Solution
Solution of Interview question 15.5.
: any value from 0 to 0.96.
What the interviewer is looking for: the determinant condition applied with numbers.
Interview question 15.6 ★★ researcher • systematic fund
Ten assets are all pairwise correlated at . What are the eigenvalues of the correlation matrix, and what is the smallest possible ?
Solution
Solution of Interview question 15.6.
Eigenvalue (eigenvector ) and with multiplicity 9. Non-negativity needs : ten assets can be at most about correlated with each other on average, because their equally weighted sum cannot have negative variance.
What the interviewer is looking for: the equicorrelation spectrum and the portfolio interpretation of the bound.
Interview question 15.7 ★★ researcher, mle • systematic fund
In a regression of 250 observations on an intercept and four regressors, what are the trace and the eigenvalues of the hat matrix? What is the average leverage, and why does it matter?
Solution
Solution of Interview question 15.7.
is a projection onto a five-dimensional space: eigenvalues 1 (five times) and 0 (245 times), trace 5. The average leverage is ; observations with leverage several times that (extreme regressor values) pull the fit towards themselves and deserve a look, as does any regression whose is not small.
What the interviewer is looking for: the projection’s spectrum and the meaning of leverage.
Interview question 15.8 ★★ risk, trader • asset manager
Two assets have volatilities 20% and 10% and correlation 0.3. What fully invested portfolio has the lowest variance, and what is its volatility?
Solution
Solution of Interview question 15.8.
in the volatile asset, 0.895 in the other, for a volatility of about 9.8%, lower than the less volatile asset’s 10% because the correlation is below .
What the interviewer is looking for: the two-asset formula and the diversification condition.
Interview question 15.9 ★★ bank, researcher • bank
For a standard normal , compute . Where does this number appear in option pricing?
Solution
Solution of Interview question 15.9.
. It gives the at-the-money approximation of an option: a forward at-the-money call is worth about (Chapter 17).
What the interviewer is looking for: the integral by the density’s derivative, and the link to option prices.
Interview question 15.10 ★★★ risk, developer • bank
Find the valid correlation matrix nearest, in the Frobenius norm, to the invalid matrix of Interview question 15.2. How far does it move, and which algorithm scales to a thousand assets?
Solution
Solution of Interview question 15.10.
By symmetry the answer keeps the pattern of signs with equal magnitudes; alternating projections (or eigenvalue clipping, which coincides here) give and , with eigenvalues 0, 1.5, 1.5: every entry moves by 0.4, a Frobenius distance of . For a thousand assets use the alternating-projections algorithm with Dykstra’s correction (each step one eigendecomposition, ) or a Newton method on the dual (Higham’s paper and its successors), and report which entries moved.
What the interviewer is looking for: the structure of the answer, its distance, and the algorithm at scale.
Interview question 15.11 ★★★ researcher, bank • systematic fund
With , what are the eigenvalues of , and what is its inverse? Why does this matter for a one-factor covariance model?
Solution
Solution of Interview question 15.11.
: eigenvalues 10 (along ) and 1, 1. The inverse is by Sherman–Morrison. A one-factor covariance is a scaled version, so its inverse (needed for minimum-variance weights or a Mahalanobis distance) costs , not .
What the interviewer is looking for: the spectrum of a rank-one update and the computational payoff.
Interview question 15.12 ★★★ researcher, trader • multi-manager fund
Two uncorrelated assets have expected returns 5% and 3% and volatilities 20% and 10%. Which portfolio has the highest expected return at a volatility of 10%, with no budget constraint? What are its weights, its expected return and its Sharpe ratio?
Solution
Solution of Interview question 15.12.
Maximise subject to : , whose volatility is ; scale by to . Expected return about 3.91%, Sharpe ratio about 0.39, higher than either asset’s 0.25 and 0.30.
What the interviewer is looking for: the Lagrangian solution and the scaling.
Interview question 15.13 ★★★ bank, researcher • any
Bound the error of as an approximation of at , and compare with the actual error.
Solution
Solution of Interview question 15.13.
The Lagrange remainder is for some , at most . The actual error is , inside the bound.
What the interviewer is looking for: the remainder term, bounded honestly.
Sources and further reading
- N. J. Higham, “Computing the nearest correlation matrix—a problem from finance”, IMA Journal of Numerical Analysis 22(3), 2002, 329–343.
- One Quant Book 4, chapters 16, 22 and 25 (least squares, covariance estimation, numerical linear algebra); One Quant Book 7, chapter 25 (portfolio construction).