FunctionRacerProblemsRace

Slope Through Time

HardstatsmodelsPython

A stock's daily returns y are compared with the market's daily returns x. Its beta is the slope of the least squares line of y on x (with an intercept). Return the beta of every stretch of window days in a row, in order: first days 0 to window - 1, then days 1 to window, and so on.

Example 1

x [1,2,3,4,5,6,7]
y [2,4,6,8,10,12,14]
window 5
returns [2.0,2.0,2.0]

y is always twice x, so every stretch of 5 days has a beta of 2.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More statsmodels problems