Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-287

Engle-Granger Residual Change

Problem

Compute the one-step change in the Engle-Granger cointegration residual: (y[-1] - beta * x[-1]) - (y[-2] - beta * x[-2]).

Return 0.0 when the series have fewer than two aligned points.

Hint

The error-correction term moves by (dy - beta * dx) between the last two points.

Test cases

case 1
in: [[10,12,11],[8,9,8],0.5]
expected: -0.5
case 2
in: [[5,6],[3,3],1]
expected: 1
case 3
in: [[1],[0],1]
expected: 0
case 4
in: [[7,9,8],[2,3,2],1.5]
expected: 0.5
Starter codePython
def engle_granger_residual_change(y, x, beta):
    # Your code here
    pass

4 test cases · run your code against them in the editor