How About Stock Returns?
In the last exercise, you showed that Amazon stock prices, contained in the DataFrame AMZN follow a random walk. In this exercise. you will do the same thing for Amazon returns (percent change in prices) and show that the returns do not follow a random walk.
Diese Übung ist Teil des Kurses
Time Series Analysis in Python
Anleitung zur Übung
- Import the
adfullermodule from statsmodels. - Create a new DataFrame of AMZN returns by taking the percent change of prices using the method
.pct_change(). - Eliminate the NaN in the first row of returns using the
.dropna()method on the DataFrame. - Run the Augmented Dickey-Fuller test on the
'Adj Close'column ofAMZN_ret, and print out the p-value inresults[1].
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Import the adfuller module from statsmodels
from statsmodels.tsa.stattools import adfuller
# Create a DataFrame of AMZN returns
AMZN_ret = ___
# Eliminate the NaN in the first row of returns
AMZN_ret = ___
# Run the ADF test on the return series and print out the p-value
results = adfuller(___)
print('The p-value of the test on returns is: ' + str(results[___]))