All problems
ADF Lag-One Slope
Problem
Run the core regression of an ADF-style stationarity test by hand. Regress the first difference at time t on the level at time t-1 without an intercept, so the slope is sum(x[t-1] * dx[t]) / sum(x[t-1]^2).
Return 0.0 when there are fewer than two observations or when the denominator is zero. A strongly negative slope is evidence of stationarity.
Hint
The numerator telescopes: it is half of the change in the squared level.
Test cases
case 1
in: [[1,2,3,4]]
expected: 0.42857142857142855
case 2
in: [[0,0,0]]
expected: 0
case 3
in: [[2,1,2,1,2]]
expected: -0.2
case 4
in: [[5]]
expected: 0
Starter codePython
def adf_lag1_slope(series):
# Your code here
pass4 test cases · run your code against them in the editor