A regression is a projection, and QR computes it
Everything in this skill meets in one computation. The regression of a response y on regressors in the columns of X projects y onto the column space of X; the coefficients β̂ are the weights of that projection, and the residual is orthogonal to every regressor. To find the weights without squaring the condition number, factor X=QR and solve the triangular system Rβ̂=Qᵀy by back substitution. This is what a library does when you call a least squares routine.
In finance the response is the daily return of a stock and the regressors are the returns of the market and other factors. The intercept α is the average return not explained by the factors, each slope β is the sensitivity to a factor, and R² is the share of the stock's variance the factors explain. You compute them from daily simple returns rₜ=Pₜ/Pₜ₋₁-1, using only days where all series have a return.
- Modified Gram-Schmidt builds Q and R; subtract each projection from the updated vector.
- Back substitution solves a triangular system from the last row up.
- The column of ones gives the intercept; without it the fit is forced through the origin.
Lab · what's graded
- Modified Gram-Schmidt25 pts
- Back substitution15 pts
- An OLS fit from QR30 pts
- Betas on real returns30 pts