Numerical methods can fail silently when matrices are ill-conditioned. The condition number (ratio of largest to smallest singular values) measures sensitivity. A high means small changes in input produce huge changes in output.
For linear systems , the relative error in can be up to times the relative error in . With double precision ( digits), leaves about trustworthy digits.
Common pitfalls:
- Computing before solving regression squares the condition number. Use QR or SVD directly.
- Inverting matrices is a code smell. Solve linear systems instead — same answer, more stable.
- Subtracting nearly-equal numbers loses precision (catastrophic cancellation).
In quant work, near-singular covariance matrices appear all the time (e.g. when assets are highly correlated). Regularization (shrinkage, ridge) and PCA-based dimensionality reduction are the standard defenses.