CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

ARIMA Models in Python

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de 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)
Modifier et exécuter le code