量化金融 · 第 18 册 · 职业发展

Interviews I: Maths, Probability and Speed

本书暂未推出简体中文版。现有版本:English, Français。

Interviews I: Maths, Probability and Speed · 职业发展

19Linear Algebra

Reading off rank and eigenvalues from a matrix’s structure, without expansion by hand, and knowing what a covariance matrix can and cannot be. The later questions cover PCA and the SVD, conditioning, and why a sample covariance matrix misleads when there are many assets and few days.

Question 19.1 ★ QR, QT, DS, QD • any • junior

Let u=(1,2,3)u = (1, 2, 3) and v=(1,1,1)v = (1, 1, 1). What are the rank and the eigenvalues of the matrix uv⊤uv^\top? What are the eigenvalues of the nn by nn matrix of all ones, and of the matrix with zeros on the diagonal and ones elsewhere?

Answer

Answer to Question 19.1.

The matrix uv⊤uv^\top has rank 1, and its eigenvalues are v⊤u=6v^\top u = 6, 0 and 0. The matrix of all ones has eigenvalues nn and 00 (n−1n - 1 times). With zeros on the diagonal, they are n−1n - 1 and −1-1 (n−1n - 1 times).

For any vector xx, uv⊤x=u(v⊤x)uv^\top x = u(v^\top x), a multiple of uu. So the image is one line, and uu is an eigenvector: uv⊤u=(v⊤u)uuv^\top u = (v^\top u)u. Everything orthogonal to vv goes to 0. The trace is v⊤uv^\top u, as a check.

The matrix of all ones is 11⊤\mathbf{1}\mathbf{1}^\top, with 1⊤1=n\mathbf{1}^\top\mathbf{1} = n. Taking away the identity shifts each eigenvalue by −1-1.

Classic wrong answer. Computing a characteristic polynomial. Spot the structure first: a shift by the identity moves all the eigenvalues, and it leaves the eigenvectors alone.

Question 19.2 ★ QR, QT, DS, Risk • any • junior

Ten assets have unit variance and a common pairwise correlation of ρ=0.2\rho = 0.2. What are the eigenvalues of the correlation matrix, and what are the eigenvectors? What is the lowest possible value of ρ\rho for 10 assets, and what is the variance of their equally weighted average for large numbers?

Answer

Answer to Question 19.2.

The eigenvalues are 2.82.8 once, with eigenvector 1\mathbf{1}, and 0.80.8 nine times, on everything orthogonal to 1\mathbf{1}. The lowest ρ\rho is −1/9-1/9, and the variance of the average falls to ρ\rho for large numbers.

Write the matrix as (1−ρ)I+ρ11⊤(1 - \rho)I + \rho\mathbf{1}\mathbf{1}^\top. The matrix of all ones has eigenvalues nn and 0, so the eigenvalues here are 1−ρ1 - \rho and 1−ρ+nρ=1+(n−1)ρ1 - \rho + n\rho = 1 + (n - 1)\rho.

A correlation matrix needs all eigenvalues at or above zero, so ρ≥−1/(n−1)\rho \ge -1/(n - 1). At that value, the sum of the assets is constant.

The average has variance 1n21⊤C1=1+(n−1)ρn=ρ+1−ρn\frac{1}{n^2}\mathbf{1}^\top C\mathbf{1} = \frac{1 + (n - 1)\rho}{n} = \rho + \frac{1 - \rho}{n}. Here it is 0.280.28. This is the limit of diversification: the shared part never goes away.

Classic wrong answer. Thinking that any ρ\rho in [−1,1][-1, 1] is possible. With many assets, they cannot all be strongly negatively correlated with each other.

Question 19.3 ★ QR, QT, Risk, DS • any • junior

Three assets have pairwise correlations ρ12=0.9\rho_{12} = 0.9, ρ23=0.9\rho_{23} = 0.9 and ρ13=0\rho_{13} = 0, as given by a data vendor. Is this a valid correlation matrix? Prove your answer by finding a portfolio with an impossible variance.

Answer

Answer to Question 19.3.

No. Its determinant is −0.62-0.62, and the portfolio (1,−2,1)(1, -\sqrt{2}, 1) has a variance of 4−3.62≈−1.094 - 3.6\sqrt{2} \approx -1.09, which is impossible.

A valid correlation matrix must be positive semi-definite, because w⊤Cww^\top Cw is the variance of a portfolio. All 2 by 2 blocks look fine, so looking at pairs does not catch this. By symmetry, try w=(1,−a,1)w = (1, -a, 1). Its variance is 1+a2+1−2a(0.9)−2a(0.9)=2+a2−3.6a1 + a^2 + 1 - 2a(0.9) - 2a(0.9) = 2 + a^2 - 3.6a. That is lowest at a=1.8a = 1.8, and already negative at a=2a = \sqrt{2}.

Intuitively, if XX is close to YY and YY is close to ZZ, then XX cannot be uncorrelated with ZZ.

Classic wrong answer. Checking that each number lies in [−1,1][-1, 1]. Those are necessary conditions on pairs, but the requirement is on the whole matrix.

Question 19.4 ★ QR, QT, DS, QD • any • junior

A matrix PP has the property P2=PP^2 = P. What can its eigenvalues be? Show that its rank equals its trace. What is the trace of the matrix X(X⊤X)−1X⊤X(X^\top X)^{-1}X^\top, where XX has nn rows and pp independent columns?

Answer

Answer to Question 19.4.

The eigenvalues can only be 0 or 1. The rank equals the trace, and the trace of X(X⊤X)−1X⊤X(X^\top X)^{-1}X^\top is pp.

If Pv=λvPv = \lambda v, then P2v=λ2vP^2v = \lambda^2v, and so λ2=λ\lambda^2 = \lambda. Since P(P−I)=0P(P - I) = 0, the polynomial x(x−1)x(x - 1) has distinct roots, so PP is diagonalisable. The trace is the count of 1s, and the rank is also the count of 1s.

For the hat matrix, tr⁡(X(X⊤X)−1X⊤)=tr⁡((X⊤X)−1X⊤X)=tr⁡(Ip)=p\operatorname{tr}\bigl(X(X^\top X)^{-1}X^\top\bigr) = \operatorname{tr}\bigl((X^\top X)^{-1}X^\top X\bigr) = \operatorname{tr}(I_p) = p. The cyclic rule does the work.

Classic wrong answer. Assuming that a projection must be symmetric. The matrix with rows (1,1)(1, 1) and (0,0)(0, 0) is idempotent and not symmetric, and its rank and trace still agree.

Question 19.5 ★ QR, QT, QD, DS • any • junior

Let AA be the 2 by 2 symmetric matrix with 2 on the diagonal and 1 off it. Find its eigenvalues and eigenvectors, and use them to write down A10A^{10} and A−1A^{-1} exactly, with no repeated multiplication.

Answer

Answer to Question 19.5.

The eigenvalues are 3 and 1, with eigenvectors (1,1)(1, 1) and (1,−1)(1, -1). So A10A^{10} has diagonal (310+1)/2=29 525(3^{10} + 1)/2 = 29\,525 and off-diagonal (310−1)/2=29 524(3^{10} - 1)/2 = 29\,524, and A−1A^{-1} has diagonal 2/32/3 and off-diagonal −1/3-1/3.

The matrix is I+11⊤I + \mathbf{1}\mathbf{1}^\top, so its eigenvalues follow at once. It is 3 times one projection plus 1 times another, and the product of these two projections is zero. So any function of AA applies to the 3 and to the 1 only:

f(A)=f(3)2(1111)+f(1)2(1−1−11).f(A) = \frac{f(3)}{2}\begin{pmatrix}1&1\\1&1\end{pmatrix} + \frac{f(1)}{2}\begin{pmatrix}1&-1\\-1&1\end{pmatrix}.

With f(x)=1/xf(x) = 1/x, the diagonal is (13+1)/2=23(\tfrac13 + 1)/2 = \tfrac23, and the off-diagonal is (13−1)/2=−13(\tfrac13 - 1)/2 = -\tfrac13. Direct multiplication gives the same.

Classic wrong answer. Raising the entries to the power 10. Powers of a matrix act on its eigenvalues, not its entries.

Question 19.6 ★★ QR, QT, Risk, DS • any • junior

Asset XX has a correlation of 0.90.9 with YY, and YY has a correlation of 0.90.9 with ZZ. What are the lowest and highest possible correlations between XX and ZZ? Derive them in two ways: from a determinant and from angles between vectors.

Answer

Answer to Question 19.6.

The correlation between XX and ZZ can be anywhere from 0.620.62 to 1.

From the determinant: a 3 by 3 correlation matrix is valid when

1+2abc−a2−b2−c2≥0,1 + 2abc - a^2 - b^2 - c^2 \ge 0,

which, for a given aa and bb, gives c∈[ab−(1−a2)(1−b2), ab+(1−a2)(1−b2)]c \in \bigl[ab - \sqrt{(1 - a^2)(1 - b^2)},\ ab + \sqrt{(1 - a^2)(1 - b^2)}\bigr]. Here that is 0.81±0.190.81 \pm 0.19.

From angles: a correlation is the cosine of the angle between two random variables seen as vectors. arccos⁡0.9≈25.8\arccos 0.9 \approx 25.8 degrees. Angles between XX and ZZ can be from 0 to 2⋅25.82 \cdot 25.8 degrees, and the cosine at the top end is cos⁡(2arccos⁡0.9)=2⋅0.81−1=0.62\cos(2\arccos 0.9) = 2 \cdot 0.81 - 1 = 0.62.

Correlation is not transitive in general. With correlations of 0.10.1 and 0.10.1, the third can be anywhere from −0.98-0.98 to 1, which is no real constraint. A strong constraint appears only when the correlations are high.

Classic wrong answer. Multiplying 0.9⋅0.9=0.810.9 \cdot 0.9 = 0.81, and giving that as the answer. It is the centre of the interval, and it would be the answer if XX and ZZ were linked only through YY. They need not be.

Question 19.7 ★★ QR, QT, QD • any • junior

Let PP be the nn by nn cyclic shift, with (Px)i=xi+1(Px)_i = x_{i + 1}, indices wrapping around. What are its eigenvalues and eigenvectors, and what is its condition number? Use them to find the eigenvalues of the 4 by 4 circulant whose first row is (2,1,0,0)(2, 1, 0, 0).

Answer

Answer to Question 19.7.

The eigenvalues of PP are the nn-th roots of unity, the eigenvectors are the Fourier vectors (1,ω,ω2,… )(1, \omega, \omega^2, \dots) and the condition number is 1. The circulant has eigenvalues 33, 11, 2+i2 + i and 2−i2 - i.

If xk=ωkx_k = \omega^k, with ωn=1\omega^n = 1, then (Px)k=ωk+1=ωxk(Px)_k = \omega^{k + 1} = \omega x_k. Since PP is orthogonal, P⊤P=IP^\top P = I, all its singular values are 1, which gives the condition number.

A circulant with first row (c0,c1,… )(c_0, c_1, \dots) is the polynomial c0I+c1P+…c_0I + c_1P + \dots in PP. So it has the same eigenvectors, and its eigenvalues are c0+c1ω+…c_0 + c_1\omega + \dots. Here, 2+ω2 + \omega with ω∈{1,i,−1,−i}\omega \in \{1, i, -1, -i\} gives 33, 2+i2 + i, 11 and 2−i2 - i.

Classic wrong answer. Saying that a real matrix has real eigenvalues. Only symmetric ones must. A shift is a rotation in disguise, and a rotation has complex eigenvalues.

Why it matters. This is why fast Fourier transforms solve circular convolutions: the Fourier basis diagonalises every circulant matrix at once.

Question 19.8 ★★ QR, QD, QT • any • junior

Take the nn by nn tridiagonal matrix with 2 on the diagonal and −1-1 just off it. Find its eigenvalues for n=3n = 3, then give the general formula. What happens to the condition number as nn grows, and why does it matter when solving a finite-difference problem?

Answer

Answer to Question 19.8.

For n=3n = 3 the eigenvalues are 2−22 - \sqrt{2}, 22 and 2+22 + \sqrt{2}. In general they are 2−2cos⁡kπn+12 - 2\cos\frac{k\pi}{n + 1} for k=1,…,nk = 1, \dots, n. The condition number grows like 4(n+1)2/π24(n + 1)^2/\pi^2, about 4100 for n=100n = 100.

Try xj=sin⁡jkπn+1x_j = \sin\frac{jk\pi}{n + 1}, a discrete sine wave that is zero at j=0j = 0 and j=n+1j = n + 1. Then

−xj−1+2xj−xj+1=(2−2cos⁡kπn+1)xj,-x_{j - 1} + 2x_j - x_{j + 1} = \Bigl(2 - 2\cos\frac{k\pi}{n + 1}\Bigr)x_j,

by the sum formula for sines. It satisfies the boundary rows automatically.

The largest eigenvalue is near 4, and the smallest is about π2/(n+1)2\pi^2/(n + 1)^2, so the ratio goes as stated. A finer grid gives a less well-conditioned matrix. Direct solves are still fine for a tridiagonal system, but rounding errors grow with the grid, and an iterative solver slows down without a preconditioner.

Classic wrong answer. Thinking that a finer grid must always give better answers. The discretisation error falls, but the rounding error rises, and there is a best grid size.

Question 19.9 ★★ QR, QT, DS, Risk • hedge fund • junior

Two assets have a correlation of 0.50.5. If both have unit volatility, what are the two principal components and their shares of variance? If the first asset’s volatility is doubled, how much variance does the first component explain? Why does this show that PCA depends on units, and what do you do about it?

Answer

Answer to Question 19.9.

With unit volatilities the components are (1,1)/2(1, 1)/\sqrt{2}, with a 75% share, and (1,−1)/2(1, -1)/\sqrt{2}, with 25%. If the first asset’s volatility is doubled, the first component explains about 86%. PCA depends on units, so use the correlation matrix when units are not comparable.

The first matrix has eigenvalues 1+ρ=1.51 + \rho = 1.5 and 1−ρ=0.51 - \rho = 0.5, summing to 2.

With volatilities 2 and 1, the covariance matrix has rows (4,1)(4, 1) and (1,1)(1, 1). Its eigenvalues are 5±132\frac{5 \pm \sqrt{13}}{2}, so 4.304.30 and 0.700.70. The share is 4.30/5=0.864.30/5 = 0.86. The top component now points mostly along the first asset, at about 17 degrees from it, with tan⁡2θ=2/3\tan 2\theta = 2/3. The correlation has not changed. Only the units have.

So PCA on returns with very different volatilities mostly finds the most volatile assets. Decide whether you want that. Scale to unit variance if not, or weight by a risk budget.

Classic wrong answer. Treating the components as properties of the assets. They are also a property of the scale you chose, and a change of currency or a leverage factor changes them.

Question 19.10 ★★ QR, QD, DS • any • junior

Find the singular values of the matrix with rows (3,0)(3, 0) and (4,5)(4, 5), and its condition number in the 2-norm. Compare them with the eigenvalues of the matrix. How do singular values relate to the principal components of a data matrix?

Answer

Answer to Question 19.10.

The singular values are 35≈6.713\sqrt{5} \approx 6.71 and 5≈2.24\sqrt{5} \approx 2.24, so the condition number is 3. The eigenvalues are 3 and 5, which would suggest a different ratio.

Singular values are the square roots of the eigenvalues of A⊤AA^\top A. Here A⊤AA^\top A has rows (25,20)(25, 20) and (20,25)(20, 25), whose eigenvalues are 45 and 5.

The matrix is triangular, so its eigenvalues are its diagonal: 3 and 5. For a non-symmetric matrix, eigenvalues do not measure size or conditioning, and only singular values do.

For a centred data matrix X=UΣV⊤X = U\Sigma V^\top with nn rows, the covariance is X⊤X/(n−1)=VΣ2V⊤/(n−1)X^\top X/(n - 1) = V\Sigma^2V^\top/(n - 1). So the columns of VV are the principal components, and their variances are σi2/(n−1)\sigma_i^2/(n - 1). A test on random data confirms this. It is better to use the SVD on XX than an eigensolver on the covariance, because forming the covariance squares the condition number.

Classic wrong answer. Using the ratio 5/3≈1.675/3 \approx 1.67 as the condition number. That works only for a symmetric matrix.

Question 19.11 ★★ QR, QD, QT, DS • any • junior

Solve Ax=bAx = b for AA with rows (1,1)(1, 1) and (1,1.0001)(1, 1.0001), and for b=(2,2)b = (2, 2) and then b=(2,2.0001)b = (2, 2.0001). What does the result show? Give the condition number of AA, and the rule of thumb linking it to lost digits. What does squaring AA, as in the normal equations of a regression, do?

Answer

Answer to Question 19.11.

The solutions are (2,0)(2, 0) and (1,1)(1, 1). So changing bb by 0.00010.0001 moves xx by 1. The condition number is about 4×1044 \times 10^4, and you lose about 4.64.6 digits. Forming A⊤AA^\top A squares the condition number, which loses about 99 digits.

The matrix is nearly singular, as its rows are nearly equal. Its eigenvalues are about 2 and 5×10−55 \times 10^{-5}, whose ratio is the condition number.

The rule of thumb is that relative error in the answer can be κ\kappa times the relative error in the input. If you work with 16 digits, you can lose about log⁡10κ\log_{10}\kappa of them. With the normal equations, X⊤XX^\top X has a condition number of κ2\kappa^2, and that is why good regression code uses QR or the SVD on XX.

Classic wrong answer. Checking the residual, and being satisfied that it is small. Both solutions have tiny residuals against the other bb. A small residual does not mean a small error when AA is badly conditioned.

Why it matters. Two near-identical assets in a risk model create exactly this problem. A small change in estimated means or covariances then gives wildly different portfolio weights.

Question 19.12 ★★ QR, QT, DS, Risk • hedge fund, bank • junior

You compute the sample covariance matrix of 500 stocks from 250 daily returns. What is the largest its rank can be? What follows for a minimum-variance portfolio computed from it? Give two practical repairs.

Answer

Answer to Question 19.12.

The rank is at most 249, after subtracting the means. So there are at least 251 independent portfolios with exactly zero sample variance, and a minimum-variance optimiser sends its weights to them.

S=1T−1∑t(rt−rˉ)(rt−rˉ)⊤S = \frac{1}{T - 1}\sum_t (r_t - \bar{r})(r_t - \bar{r})^\top is a sum of TT rank-one matrices, and the centred vectors add up to zero, so its rank is at most T−1T - 1. A simulation with 250 and 500 confirms 249.

A portfolio with zero sample variance is not riskless. Its weights are fitted to the sample’s quirks, and its true risk is ordinary. The optimiser cannot be solved uniquely and, with constraints, it still heads straight for these directions.

Two repairs: impose structure with a factor model, Σ=D+BB⊤\Sigma = D + BB^\top, which is full rank with few parameters. Or shrink: αF+(1−α)S\alpha F + (1 - \alpha)S, with a simple target FF. Weight limits also help, because they act like shrinkage.

Classic wrong answer. Inverting with a pseudo-inverse and calling it fixed. That gives you a number, but the problem is that you have too little data, and no matrix algebra adds any.

Question 19.13 ★★ QR, QT, Risk, DS • hedge fund • junior

A covariance matrix has eigenvalues 5, 1 and 0.10.1. You replace it with 0.70.7 times itself plus 0.30.3 times μI\mu I, with μ\mu the mean of the eigenvalues. What are the new eigenvalues and the new condition number? What stays the same? Why does this help an optimiser, and where would 0.30.3 come from?

Answer

Answer to Question 19.13.

The new eigenvalues are 4.114.11, 1.311.31 and 0.680.68. The condition number falls from 50 to about 6.06.0. The eigenvectors and the trace stay the same.

With μ=6.1/3≈2.03\mu = 6.1/3 \approx 2.03, each eigenvalue becomes 0.7λ+0.3μ0.7\lambda + 0.3\mu, because II has every vector as an eigenvector. Sample eigenvalues are too spread out: the top is too high, and the bottom too low. So this moves them together while keeping the total variance.

An optimiser’s weights use Σ−1\Sigma^{-1}, so they are dominated by the smallest eigenvalues, which are the least reliable. Raising them from 0.10.1 to 0.680.68 reduces the weight given to those directions about sevenfold.

The 0.30.3 can be chosen by the Ledoit–Wolf formula, which estimates the intensity that minimises the expected squared distance to the true matrix, using how noisy SS is. Or use cross-validation on out-of-sample variance.

Classic wrong answer. Thinking of shrinkage as losing information because it changes the numbers. The sample values have errors that always spread them apart, and moving them together corrects that.

Question 19.14 ★★ QR, QT, Risk • hedge fund • junior

One asset has a volatility of 10%, another of 20%, and their correlation is ρ\rho. Find the minimum-variance weights. For what ρ\rho is the second asset’s weight exactly zero? What are the weights and the portfolio’s volatility at ρ=0.8\rho = 0.8? Why is the variance below that of the first asset, when the second is riskier and correlated?

Answer

Answer to Question 19.14.

The weights are proportional to σ22−ρσ1σ2\sigma_2^2 - \rho\sigma_1\sigma_2 and σ12−ρσ1σ2\sigma_1^2 - \rho\sigma_1\sigma_2. The second is zero at ρ=σ1/σ2=0.5\rho = \sigma_1/\sigma_2 = 0.5. At ρ=0.8\rho = 0.8 the weights are (4/3,−1/3)(4/3, -1/3), and the volatility is about 8.94%8.94\%.

w∝Σ−11w \propto \Sigma^{-1}\mathbf{1}, which for two assets gives the formula above. A grid search on the weight at ρ=0.8\rho = 0.8 finds the same.

At ρ=0.8\rho = 0.8: variance is 169(0.01)+19(0.04)−2⋅43⋅13⋅0.016=0.008\frac{16}{9}(0.01) + \frac19(0.04) - 2 \cdot \frac43 \cdot \frac13 \cdot 0.016 = 0.008.

Why the variance is lower: the short position in the second asset hedges the first. The marginal effect of adding the second asset at zero weight is its covariance with the first, 0.0160.016, which is above the first’s variance, 0.010.01. So being short it lowers the risk. In other words, the beta of asset 1 on asset 2 is 0.40.4, and the best portfolio holds a partial hedge against it.

Above ρ=0.5\rho = 0.5 the riskier asset is a hedge, and it is shorted. Below that, you hold it long.

Classic wrong answer. Saying that a riskier asset always gets a smaller positive weight. For a high enough correlation it gets a negative weight, because it is then useful as a hedge.

Question 19.15 ★★ QR, QT, DS, QD • any • junior

A market state moves between two regimes: from calm, it stays calm with chance 0.90.9; from stressed, it stays stressed with chance 0.80.8. Write the transition matrix, its eigenvalues and its stationary distribution. How quickly does the effect of today’s state die away? What is that time for a half-way decay?

Answer

Answer to Question 19.15.

The matrix has rows (0.9,0.1)(0.9, 0.1) and (0.2,0.8)(0.2, 0.8), with eigenvalues 1 and 0.70.7. The stationary distribution is (2/3,1/3)(2/3, 1/3). The effect of today’s state shrinks by a factor of 0.70.7 per day, which is a half-life of about 1.91.9 days.

Rows sum to 1, so 1\mathbf{1} is a right eigenvector with eigenvalue 1. The other eigenvalue comes from the trace: 1.7−1=0.71.7 - 1 = 0.7. The stationary π\pi solves πP=π\pi P = \pi, which gives 0.1π1=0.2π20.1\pi_1 = 0.2\pi_2, so π1=2π2\pi_1 = 2\pi_2.

The difference between the chance of calm tomorrow starting from calm and starting from stress is 0.9−0.2=0.70.9 - 0.2 = 0.7, which is the eigenvalue. After kk days that is 0.7k0.7^k, so half-way takes ln⁡0.5/ln⁡0.7≈1.94\ln 0.5/\ln 0.7 \approx 1.94 days. A matrix power at 200 steps gives the stationary row from either start.

Classic wrong answer. Thinking the state’s duration tells you about mixing: the expected length of a stress spell is 5 days and of a calm spell is 10, and these are longer than the half-life. Mixing combines both exits, and the eigenvalue already includes them.

Question 19.16 ★★ QR, QD, Dev • any • junior

Write the Fibonacci recursion as a 2 by 2 matrix. What are its eigenvalues? Derive the closed form, and say how many multiplications matrix powers need for FnF_n. Using double-precision floating point, does the closed form always give the exact integer?

Answer

Answer to Question 19.16.

The matrix has rows (1,1)(1, 1) and (1,0)(1, 0), with eigenvalues φ=(1+5)/2\varphi = (1 + \sqrt{5})/2 and ψ=(1−5)/2\psi = (1 - \sqrt{5})/2. So Fn=(φn−ψn)/5F_n = (\varphi^n - \psi^n)/\sqrt{5}, and about 2log⁡2n2\log_2 n matrix products are needed. With doubles, the rounded formula first goes wrong at n=71n = 71.

(Fn+1,Fn)⊤=M(Fn,Fn−1)⊤(F_{n + 1}, F_n)^\top = M(F_n, F_{n - 1})^\top, so MnM^n has FnF_n in its off-diagonal. Expanding the start vector in eigenvectors gives the formula. Since ∣ψ∣<1|\psi| < 1, FnF_n is the nearest integer to φn/5\varphi^n/\sqrt{5}.

Repeated squaring computes MnM^n in about log⁡2n\log_2 n squarings, and up to as many extra products.

Doubles have about 53 bits. φn/5\varphi^n/\sqrt{5} passes 2532^{53} near n=78n = 78, but the rounding errors in φ\varphi accumulate before then. A test finds the first wrong value at n=71n = 71. So use integer matrix powers for an exact value. A test computes F30=832 040F_{30} = 832\,040 that way.

Classic wrong answer. Saying that the closed form is always better because it has no loop. It is only as exact as its floating-point inputs, and the integer method has no such limit.

Question 19.17 ★★ QR, QT, QD • any • junior

A 100 by 100 matrix has entries aij=i+ja_{ij} = i + j, with indices from 1 to 100. What is its rank? Find its nonzero eigenvalues in closed form, without expanding anything, by using the structure of the matrix.

Answer

Answer to Question 19.17.

The rank is 2, and the nonzero eigenvalues are 5050±100⋅338 350≈10 866.85050 \pm \sqrt{100 \cdot 338\,350} \approx 10\,866.8 and −766.8-766.8.

Write A=u1⊤+1u⊤A = u\mathbf{1}^\top + \mathbf{1}u^\top, with u=(1,…,100)u = (1, \dots, 100). Each term has rank 1, and the two together have rank 2. Any eigenvector with a nonzero eigenvalue lies in the span of uu and 1\mathbf{1}. Write x=au+b1x = au + b\mathbf{1}. Then Ax=u(1⊤x)+1(u⊤x)Ax = u(\mathbf{1}^\top x) + \mathbf{1}(u^\top x), which gives the 2 by 2 matrix

(1⊤u1⊤1u⊤uu⊤1)=(5050100338 3505050).\begin{pmatrix} \mathbf{1}^\top u & \mathbf{1}^\top\mathbf{1} \\ u^\top u & u^\top\mathbf{1} \end{pmatrix} = \begin{pmatrix} 5050 & 100 \\ 338\,350 & 5050 \end{pmatrix}.

Its eigenvalues are 5050±100⋅338 3505050 \pm \sqrt{100 \cdot 338\,350}. As a check, the sum is 10 10010\,100, which is the trace of AA: ∑2i=10 100\sum 2i = 10\,100. A numerical solver gives the same.

Classic wrong answer. Expecting all eigenvalues to be positive, because all entries are positive. The matrix is not positive semi-definite. A positive entry does not imply that.

Question 19.18 ★★★ QR, QT, DS, Risk • hedge fund • junior, experienced

Five hundred uncorrelated assets with unit variance are observed for 1000 days. Between which values do the sample covariance eigenvalues lie, by the Marchenko–Pastur law, although all the true eigenvalues are 1? A minimum-variance portfolio is built from the sample matrix. How does its risk in the sample compare with its risk out of sample, and with the true optimum?

Answer

Answer to Question 19.18.

The sample eigenvalues lie between about 0.0860.086 and 2.9142.914. In the sample, the portfolio shows a variance of (1−q)/N(1 - q)/N, with q=N/T=0.5q = N/T = 0.5. Out of sample, its true variance is 1/((1−q)N)1/((1 - q)N). So the optimum variance is 1/N1/N, the sample reports half of that, and it delivers twice that, for a ratio of 4 between the delivered risk and the risk seen.

The law says that the eigenvalues of pure noise spread out to (1±q)2(1 \pm \sqrt{q})^2, so (1±0.707)2(1 \pm 0.707)^2. A simulation with 500 assets and 1000 days gets close to both edges.

The optimiser takes w∝S−11w \propto S^{-1}\mathbf{1}. So it picks up the low sample eigenvalues, which are spuriously low, and loads onto those directions. Twenty simulations, one for each seed, give in-sample variance 0.5/N0.5/N and out-of-sample variance 2/N2/N, against the true optimum 1/N1/N, which is the equal-weight portfolio here.

To make this useful, look at the limits. As q→0q \to 0, you have lots of data, and all three agree. As q→1q \to 1, the out-of-sample risk blows up. Below the Marchenko–Pastur upper edge, real data’s eigenvalues cannot be told apart from noise, so clean them or use a factor model.

Classic wrong answer. Thinking that the risk in the sample is a fair estimate of the risk you will face. An optimised portfolio is the most flattering one for that sample, so it is too low by construction.

Question 19.19 ★★★ QR, QT, QD, Risk • hedge fund • junior, experienced

A factor risk model has covariance matrix Σ=D+ββ⊤\Sigma = D + \beta\beta^\top for 1000 assets, with DD diagonal. Find Σ−1\Sigma^{-1} with the Sherman–Morrison formula, and prove it. What is the cost compared with a direct inverse? Write the minimum-variance weights, and say what they do to high-beta stocks.

Answer

Answer to Question 19.19.

Σ−1=D−1−D−1ββ⊤D−11+β⊤D−1β\Sigma^{-1} = D^{-1} - \dfrac{D^{-1}\beta\beta^\top D^{-1}}{1 + \beta^\top D^{-1}\beta}. This takes O(N)O(N) operations for a matrix-vector product, instead of O(N3)O(N^3) for a direct inverse. The minimum-variance weights are proportional to di−1(1−cβi)d_i^{-1}(1 - c\beta_i), so high-beta stocks get low or negative weights.

Proof: multiply out. Let x=D−1βx = D^{-1}\beta and s=β⊤xs = \beta^\top x. Then

(D+ββ⊤)(D−1−xx⊤1+s)=I+βx⊤−βx⊤+βsx⊤1+s=I+βx⊤−βx⊤=I.(D + \beta\beta^\top)\Bigl(D^{-1} - \frac{xx^\top}{1 + s}\Bigr) = I + \beta x^\top - \frac{\beta x^\top + \beta s x^\top}{1 + s} = I + \beta x^\top - \beta x^\top = I.

Numerical tests with 1000 assets confirm this, and the fast weights match a direct solve.

Applying it to 1\mathbf{1} gives w∝D−11−x1⊤x1+sw \propto D^{-1}\mathbf{1} - x\frac{\mathbf{1}^\top x}{1 + s}, whose ii-th entry is 1di(1−βi1⊤x1+s)\frac{1}{d_i}\bigl(1 - \beta_i\frac{\mathbf{1}^\top x}{1 + s}\bigr), which is the form above. So the weights fall in a straight line with beta, when residual risks are equal. That is the known low-beta tilt of minimum-variance portfolios: the portfolio lowers its market exposure by buying low-beta and shorting high-beta names.

The cost matters: with kk factors, Woodbury’s version needs the inverse of one k×kk \times k matrix, at a cost of O(Nk2)O(Nk^2). So factor models are as much a computational tool as a statistical one.

Classic wrong answer. Forming and inverting the whole matrix each time. That costs a billion operations at this size, and it loses the structure that makes the result stable.

Question 19.20 ★★★ QR, QT, DS • hedge fund • junior, experienced

XX, YY and ZZ have unit variance and all pairwise correlations equal to 0.50.5. What is the partial correlation of XX and YY given ZZ? Compute it in two ways: from residuals of regressions on ZZ, and from the inverse of the correlation matrix. What is the partial correlation in general if the correlation is ρ\rho?

Answer

Answer to Question 19.20.

The partial correlation is 1/31/3. In general it is ρ/(1+ρ)\rho/(1 + \rho).

From residuals: regressing on ZZ gives X−0.5ZX - 0.5Z and Y−0.5ZY - 0.5Z. Each has variance 1−0.25=0.751 - 0.25 = 0.75. Their covariance is 0.5−0.25−0.25+0.25=0.250.5 - 0.25 - 0.25 + 0.25 = 0.25. So the correlation is 0.25/0.75=1/30.25/0.75 = 1/3. A simulation agrees. In general, ρXY−ρXZρYZ(1−ρXZ2)(1−ρYZ2)\frac{\rho_{XY} - \rho_{XZ}\rho_{YZ}}{\sqrt{(1 - \rho_{XZ}^2)(1 - \rho_{YZ}^2)}}.

From the inverse: let P=C−1P = C^{-1}. Then the partial correlation is −P12/P11P22-P_{12}/\sqrt{P_{11}P_{22}}. For this equicorrelated matrix, the inverse has diagonal 1+ρ(1−ρ)(1+2ρ)\frac{1 + \rho}{(1 - \rho)(1 + 2\rho)} and off-diagonal −ρ(1−ρ)(1+2ρ)\frac{-\rho}{(1 - \rho)(1 + 2\rho)}, which gives ρ/(1+ρ)\rho/(1 + \rho).

So the off-diagonal entries of the inverse measure direct links, once all the other variables have been accounted for. A zero entry means that two variables are conditionally independent, in the Gaussian case.

Limits: ρ=0\rho = 0 gives 0, and ρ→1\rho \to 1 gives 12\tfrac12. It is not 1, because when all are close to identical, the residuals after removing ZZ are still correlated by the common structure.

Classic wrong answer. Using the correlation 0.50.5 as the direct link. Part of it comes through ZZ. Partial correlation removes that part, and it may fall a lot, or even change sign.

Question 19.21 ★★★ QR, QD, DS • any • junior, experienced

You need the top eigenvector of a 1000 by 1000 covariance matrix, whose two top eigenvalues are 10 and 5. How does power iteration work, and about how many steps does it take for an error of 10−610^{-6} in the vector? And in the eigenvalue? How many steps if the second eigenvalue is 9.99.9? When could it fail?

Answer

Answer to Question 19.21.

Multiply a start vector by the matrix, then normalise, and repeat. It takes about 20 steps for a 10−610^{-6} error in the vector, and 10 for the eigenvalue. If the second eigenvalue is 9.99.9, it takes about 1375 steps. It fails if the start vector has no component along the top vector.

Write the start as ∑civi\sum c_iv_i. After kk steps, it is λ1k(c1v1+c2(λ2/λ1)kv2+… )\lambda_1^k\bigl(c_1v_1 + c_2(\lambda_2/\lambda_1)^kv_2 + \dots\bigr). So the error falls like (λ2/λ1)k(\lambda_2/\lambda_1)^k, and 0.520≈10−60.5^{20} \approx 10^{-6}.

The Rayleigh quotient x⊤Axx^\top Ax has an error that depends on the square of the vector’s error, for a symmetric matrix, so it needs half as many steps. A run on a 1000 by 1000 matrix confirms both orders of size.

For 9.9/109.9/10, k=ln⁡10−6/ln⁡0.99≈1375k = \ln 10^{-6}/\ln 0.99 \approx 1375. So the gap matters, not the size.

Failure: exact orthogonality to v1v_1, which is unlikely from a random start, but rounding would usually fix it by itself anyway. A test that keeps removing the top direction shows it stuck on the other direction. If λ1=λ2\lambda_1 = \lambda_2 the top eigenvector is not unique: the iteration converges to some vector in that plane, and which one depends on the start. Lanczos is far faster for a small gap, using the same matrix-vector product, and needs no forming of the matrix. That matters when the covariance is XX⊤XX^\top or a factor model.

Classic wrong answer. Giving an answer that depends on the matrix’s size. The cost per step does, through the matrix-vector product. The number of steps depends only on the ratio of the eigenvalues.

Question 19.22 ★★★ QR, QD, DS, QT • hedge fund • junior, experienced

Show that ABAB and BABA have the same nonzero eigenvalues, even if they have different sizes. Use this to compute the principal components of a TT by NN return matrix with T=250T = 250 and N=5000N = 5000, without forming the NN by NN matrix. What is the eigenvector map? Also derive det⁡(I+uv⊤)=1+v⊤u\det(I + uv^\top) = 1 + v^\top u.

Answer

Answer to Question 19.22.

If ABv=λvABv = \lambda v with λ≠0\lambda \ne 0, then w=Bvw = Bv is non-zero, and BAw=BABv=λBv=λwBAw = BABv = \lambda Bv = \lambda w. So nonzero eigenvalues are shared, with the same multiplicities. For the returns, form the 250 by 250 matrix XX⊤XX^\top and map each eigenvector back with v=X⊤u/λv = X^\top u/\sqrt{\lambda}.

With A=XA = X and B=X⊤B = X^\top, XX⊤XX^\top and X⊤XX^\top X have the same nonzero eigenvalues. If XX⊤u=λuXX^\top u = \lambda u and uu has unit length, let v=X⊤u/λv = X^\top u/\sqrt{\lambda}. Then ∣v∣2=u⊤XX⊤u/λ=1|v|^2 = u^\top XX^\top u/\lambda = 1, and X⊤Xv=X⊤XX⊤u/λ=λX⊤u/λ=λvX^\top Xv = X^\top XX^\top u/\sqrt{\lambda} = \lambda X^\top u/\sqrt{\lambda} = \lambda v. A run with T=250T = 250 and N=5000N = 5000 confirms this. The eigenproblem takes about (250/5000)3≈10−4(250/5000)^3 \approx 10^{-4} of the work.

For the determinant, the identity det⁡(I+AB)=det⁡(I+BA)\det(I + AB) = \det(I + BA) follows from the shared nonzero eigenvalues: each 1+λ1 + \lambda appears in both, and the rest are 1. With A=uA = u and B=v⊤B = v^\top, BABA is the 1 by 1 number v⊤uv^\top u. So det⁡(I+uv⊤)=1+v⊤u\det(I + uv^\top) = 1 + v^\top u. Alternatively, uv⊤uv^\top has one nonzero eigenvalue v⊤uv^\top u, and the others are 0.

Classic wrong answer. Forming the 5000×50005000 \times 5000 matrix first because that is what the formula says. Its rank is at most 249, so most of that work goes on zeros.

Question 19.23 ★★★ QR, QT, Risk, QD • bank, hedge fund • junior, experienced

A correlation matrix built from a mix of sources has ρ12=ρ23=0.9\rho_{12} = \rho_{23} = 0.9 and ρ13=0\rho_{13} = 0. Give its eigenvalues. Repair it by clipping the negative eigenvalue to zero and rescaling to a unit diagonal, and give the new correlations. In what sense is this close to the original, and is it the closest possible?

Answer

Answer to Question 19.23.

The eigenvalues are 1+0.92≈2.2731 + 0.9\sqrt{2} \approx 2.273, 11 and 1−0.92≈−0.2731 - 0.9\sqrt{2} \approx -0.273. After clipping and rescaling, ρ12=ρ23≈0.729\rho_{12} = \rho_{23} \approx 0.729 and ρ13≈0.064\rho_{13} \approx 0.064. This is close, but it is not the closest valid correlation matrix: that one has about 0.740.74 and 0.1050.105.

Set the negative eigenvalue to 0. Let v=(12,−12,12)v = (\tfrac12, -\tfrac{1}{\sqrt{2}}, \tfrac12) be its eigenvector. Then

A′=A+0.273 vv⊤,A' = A + 0.273\,vv^\top,

which has diagonal (1.068,1.136,1.068)(1.068, 1.136, 1.068). It has off-diagonals 0.900−0.273⋅0.354≈0.8030.900 - 0.273 \cdot 0.354 \approx 0.803, and 0.273⋅14≈0.0680.273 \cdot \tfrac14 \approx 0.068. Dividing by the square roots of the diagonals gives the new correlations.

In what sense is it close: before the rescaling, A′A' is the nearest positive semi-definite matrix in the Frobenius norm, at a distance of 0.2730.273, which is exactly the clipped eigenvalue. Rescaling then moves it away, because it restores the unit diagonal without thinking about distance.

The nearest correlation matrix alternates projections onto the positive semi-definite cone and onto unit diagonals, with Dykstra’s correction. A test with this method gives 0.740.74 and 0.1050.105, a smaller distance from the original matrix. The two differ little in many uses, and clipping is simple and fast.

Classic wrong answer. Assuming that rescaling after clipping is the nearest matrix, or that you can fix the problem by adjusting the worst single number. Any repair changes several entries at once.

Question 19.24 ★★★★ QR, QT • hedge fund • experienced

An nn by nn matrix has independent entries, each with mean 0 and variance 1. Find E[det⁡(A)2]E[\det(A)^2] exactly. Check the answer for n=3n = 3 with ±1\pm 1 entries, by reasoning about the size of the enumeration. What does this tell you about how the typical size of a determinant grows? Compare it with the largest possible determinant of a ±1\pm 1 matrix.

Answer

Answer to Question 19.24.

E[det⁡(A)2]=n!E[\det(A)^2] = n!. For n=3n = 3 with ±1\pm 1 entries, there are 29=5122^9 = 512 matrices, and the average of det⁡2\det^2 is 6.

Expand the determinant by permutations:

det⁡(A)=∑σsgn⁡(σ)∏iaiσ(i).\det(A) = \sum_\sigma \operatorname{sgn}(\sigma)\prod_i a_{i\sigma(i)}.

Squaring gives a double sum over σ\sigma and τ\tau. If σ≠τ\sigma \ne \tau, there is a row ii where σ(i)≠τ(i)\sigma(i) \ne \tau(i), so aiσ(i)a_{i\sigma(i)} appears alone in that product (each entry only once in each of the two products), and it has mean zero. If σ=τ\sigma = \tau, the product is ∏aiσ(i)2\prod a_{i\sigma(i)}^2, which has mean 1. So only the n!n! diagonal terms survive.

The enumeration of all 512 matrices gives exactly 6. Simulations with normal entries for n=2n = 2, 4 and 5 agree. So the formula needs only independence, mean 0 and variance 1.

So the root-mean-square size is n!\sqrt{n!}, which sets the growth rate. A typical value is smaller: with normal entries, the geometric mean falls short by a factor of about 1.7n1.7\sqrt{n}, little beside the factorial. For ±1\pm 1 matrices, the largest possible is at most nn/2n^{n/2}, by Hadamard’s inequality, because the determinant is the volume of a box with sides of length n\sqrt{n}. For n=3n = 3 the bound is 5.25.2, and the enumeration finds that the actual maximum is 4. The ratio between n!\sqrt{n!} and nn/2n^{n/2} falls like e−n/2e^{-n/2}, by Stirling. So random vectors are far from orthogonal in that volume sense, even though each pair is nearly orthogonal.

Classic wrong answer. Saying that the mean of the determinant is 0, and so the typical size is small. Yes, the mean is 0, since every term of the expansion is a product of independent factors with mean 0. The second moment gives its size, and it is huge.

Question 19.25 ★★★★ QR, QT, QD • hedge fund • experienced

Prove that the element-by-element product of two positive semi-definite matrices is itself positive semi-definite. Use this to show that multiplying a correlation matrix, entry by entry, by a matrix with entries e−λ∣i−j∣e^{-\lambda |i - j|} gives a valid correlation matrix. Also prove the bound λmin⁡(A∘B)≥λmin⁡(A)min⁡iBii\lambda_{\min}(A \circ B) \ge \lambda_{\min}(A) \min_i B_{ii}.

Answer

Answer to Question 19.25.

Write A=∑kλkukuk⊤A = \sum_k \lambda_ku_ku_k^\top and B=∑lμlvlvl⊤B = \sum_l \mu_lv_lv_l^\top, with all coefficients non-negative. Then A∘B=∑k,lλkμl(uk∘vl)(uk∘vl)⊤A \circ B = \sum_{k, l}\lambda_k\mu_l(u_k \circ v_l)(u_k \circ v_l)^\top, which is a sum of positive semi-definite matrices.

To check the middle step: entry (i,j)(i, j) of A∘BA \circ B is (∑kλkukiukj)(∑lμlvlivlj)\bigl(\sum_k\lambda_ku_{ki}u_{kj}\bigr)\bigl(\sum_l\mu_lv_{li}v_{lj}\bigr), which is the same as ∑k,lλkμl(ukivli)(ukjvlj)\sum_{k, l}\lambda_k\mu_l(u_{ki}v_{li})(u_{kj}v_{lj}). Random tests with low-rank matrices never find a negative eigenvalue, beyond rounding.

For the taper, e−λ∣i−j∣e^{-\lambda|i - j|} is the correlation matrix of an AR(1) process, and so it is positive definite. So the product with a correlation matrix is positive semi-definite. The diagonal stays 1, because both diagonals are 1. It is a valid correlation matrix. A test with n=8n = 8 confirms this.

For the bound, let m=λmin⁡(A)m = \lambda_{\min}(A). Then A−mIA - mI is positive semi-definite, so (A−mI)∘B(A - mI) \circ B is too. This expands to A∘B−mdiag⁡(B)A \circ B - m\operatorname{diag}(B). So

x⊤(A∘B)x≥m∑iBiixi2≥mmin⁡iBii∣x∣2.x^\top(A \circ B)x \ge m\sum_i B_{ii}x_i^2 \ge m\min_iB_{ii}|x|^2.

Random tests confirm this inequality too.

This is why a smooth taper is safe, and a hard cut-off is not. Cutting all entries beyond a band to zero is an element-wise product with a matrix that is not positive semi-definite, and a test shows that it can yield a negative eigenvalue: the one-factor matrix with ρ=0.9\rho = 0.9 and a band of width 1 gives one.

Classic wrong answer. Trying to use the eigenvalues of the two matrices directly, as with a matrix product. The eigenvalues of A∘BA \circ B are not products of eigenvalues. The decomposition into rank-one terms is what makes it work.