Lesson 11 of 15
Linear Regression (OLS)
Ordinary Least Squares (OLS)
OLS regression fits a line that minimizes the sum of squared residuals.
The closed-form solution for the slope is:
And the intercept:
where and .
OLS is used everywhere in quantitative finance: factor models, risk attribution, and return prediction all rely on OLS regression.
Your Task
Implement ols(xs, ys) which returns a tuple (slope, intercept).
Python runtime loading...
Loading...
Click "Run" to execute your code.