Skip to content
  • Overview
  • Curriculum
    • FLUMental maths and numerical fluency
    • MKTMarkets and products
    • CSData structures and algorithms
    • PYPython and data for quants
    • NUMNumerical methods
      • 1Root finding

        • Root finding, with implied volatility as the worked case
      • 2Interpolation

        • Interpolation: splines, Runge and building a curve
      • 3Numerical integration

        • Numerical integration: trapezoid, Simpson and Gauss
      • 4Linear algebra numerics

        • Linear algebra in practice: factorisations and conditioning
      • 5ODE and PDE solvers

        • ODE and PDE solvers: finite differences and stability
      • 6Floating point

        • Floating point: IEEE 754, cancellation and why prices are integers
    • SYSSystems and low latency

Practise

  • Question bank
  • Mental arithmetic
  • Market simulator
  • Arbitrage trees
  • Horse racing
  • Bid book
  • Screening tests
  • Mock papers

Reference

  • Formula reference
  • Search

Your record

  • Review queue
  • Progress
  • Leaderboard
  • Profile
  • Invite friends
AccountSend feedback
  1. Curriculum
  2. /Quantitative development
  3. /Numerical methods
  4. /Linear algebra numerics

Linear algebra in practice: factorisations and conditioning

NUM · Chapter 4·12 min read·Asked at Two Sigma, Citadel Securities, Hudson River Trading, Jump

Assumes Numerical integration: trapezoid, Simpson and Gauss.

After this lesson you should be able to

  • Choose a factorisation from the matrix structure.
  • Explain the condition number and what it costs in precision.
  • Say why you never invert a matrix explicitly.

Solving a linear system is the inner loop of regression, portfolio optimisation and risk. The mathematics says the answer is A−1bA^{-1}bA−1b; the numerics says never to compute that, and the difference between the two is where precision is lost on real, nearly-collinear financial data.

MatrixUseCost
General squareLU with partial pivoting23n3\tfrac{2}{3}n^332​n3
Symmetric positive definiteCholesky13n3\tfrac{1}{3}n^331​n3 — half of LU
Rectangular, least squaresQR2mn22mn^22mn2
Rank-deficient or ill-conditionedSVDO(mn2)O(mn^2)O(mn2), most expensive and most robust
Large and sparseIterative (CG, GMRES)Per iteration, times the iterations
Table 4.1 · Which factorisation. Cholesky is the one to reach for on a covariance matrix: it is twice as fast as LU, needs no pivoting, and its failure is a *feature* — if it breaks down, the matrix was not positive definite and you have learned something.

Equation 4.2

The condition number

How much a relative error in the input can be amplified in the output. A condition number of 10k10^k10k means losing about kkk digits of precision.

κ(A)=∥A∥ ∥A−1∥=σmax⁡σmin⁡\kappa(A) = \|A\|\,\|A^{-1}\| = \frac{\sigma_{\max}}{\sigma_{\min}}κ(A)=∥A∥∥A−1∥=σmin​σmax​​
σ\sigmaσ
Singular values. The ratio of the largest to the smallest is the condition number.
κ=1016\kappa = 10^{16}κ=1016
All sixteen digits of a double are gone; the answer is noise.
κ(A)1,000κ(AᵀA) = κ(A)²1,000,000
Figure 4.3 · Why nobody forms A⊤AA^{\top}AA⊤A. Forming the normal equations squares the condition number, which costs you half your digits before any arithmetic happens. In double precision that takes a well-behaved problem to the edge of nonsense — and it is why every serious least-squares routine goes through QR instead.

Why the normal equations lose twice as much. The condition number of X⊤XX^\top XX⊤X is the *square* of that of XXX. So a design matrix with κ=106\kappa = 10^6κ=106 — awkward but workable, losing six digits — becomes 101210^{12}1012 once you form the product, which leaves four digits of a double. QR works on XXX directly and never forms the product, so it loses six digits rather than twelve. On well-conditioned data both approaches agree; on collinear data, which is when you most need the answer, the normal equations can return coefficients that are simply wrong, and nothing in the output says so.

Example 4.4

A design matrix has condition number 10710^{7}107. How many digits survive solving by QR, and by the normal equations?

Show the worked solutionHide the worked solution

Worked solution

  1. Formula
    digits lost≈log⁡10κ\text{digits lost} \approx \log_{10}\kappadigits lost≈log10​κ
  2. Substitute
    double precision≈16 digits\text{double precision} \approx 16 \text{ digits}double precision≈16 digits
  3. Solve
    QR: κ=107⇒16−7=9 digits\text{QR: } \kappa = 10^{7} \Rightarrow 16 - 7 = 9 \text{ digits}QR: κ=107⇒16−7=9 digits
  4. normal equations: κ2=1014⇒16−14=2 digits\text{normal equations: } \kappa^2 = 10^{14} \Rightarrow 16 - 14 = 2 \text{ digits}normal equations: κ2=1014⇒16−14=2 digits
  5. Answer
    9 against 29 \text{ against } 29 against 2

Sanity check. Two significant digits on a regression coefficient is not a rounding issue, it is the difference between a usable estimate and a meaningless one. And a condition number of 10710^7107 is entirely ordinary for a factor library with correlated features.

The rest of this lesson is in Premium

You have read the opening. 10 more sections follow, including 4 worked examples and 3 quick checks.

Start the free 7-day trialSign in

Nothing is charged for 7 days, and you can cancel before then. Or read Complexity: reading it off, and deriving it in full, free.

← Numerical integration: trapezoid, Simpson and GaussODE and PDE solvers: finite differences and stability →
On this page
  • Which factorisation
  • The condition number
  • Why nobody forms A⊤AA^{\top}AA⊤A
  • Worked example

QuantMax · 141 lessons · 1342 questions · c5c0caa

  • Premium
  • Arbitrage trees
  • Horse racing
  • Invite friends
  • Account
  • About QuantMax
  • Terms
  • Privacy

Firm names identify publicly reported question patterns and nothing more. QuantMax is not affiliated with, endorsed by, or recruiting for any firm named in the curriculum. Everything you do in lessons and the question bank is kept to your account.