Get startedGet started for free

Other tranforms

Differencing should be the first transform you try to make a time series stationary. But sometimes it isn't the best option.

A classic way of transforming stock time series is the log-return of the series. This is calculated as follows: $$log\_return ( y_t ) = log \left( \frac{y_t}{y_{t-1}} \right)$$

The Amazon stock time series has already been loaded for you as amazon. You can calculate the log-return of this DataFrame by substituting:

  • \(y_t \rightarrow\) amazon
  • \(y_{t-1} \rightarrow\) amazon.shift(1)
  • \(log() \rightarrow\) np.log()

In this exercise you will compare the log-return transform and the first order difference of the Amazon stock time series to find which is better for making the time series stationary.

This exercise is part of the course

ARIMA Models in Python

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Calculate the first difference and drop the nans
amazon_diff = ____
amazon_diff = amazon_diff.dropna()

# Run test and print
result_diff = adfuller(amazon_diff['close'])
print(result_diff)
Edit and Run Code