Lesson 4 of 15

Differencing & Integration

Differencing & Integration

Differencing transforms a non-stationary series into a stationary one by computing successive differences. A series differenced d times is said to be integrated of order d, written I(d).

First-order differencing:

Δxs[t] = xs[t] - xs[t-1]

Second-order differencing applies it twice:

Δ²xs[t] = Δxs[t] - Δxs[t-1]

Undifferencing (integration) reconstructs the original series from differences and an initial value:

xs[0] = x0
xs[t] = xs[t-1] + dxs[t-1]

Task

Implement:

  • difference(xs, d=1) — apply d-th order differencing
  • undifference(dxs, x0) — reconstruct series from first differences and starting value
Python runtime loading...
Loading...
Click "Run" to execute your code.