Advertisement
medmond919

ADFuller Example

Jun 19th, 2019
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import numpy as np
  2. import pandas as pd
  3. import pandas_datareader as pdr
  4. from statsmodels.tsa.stattools import adfuller
  5. pd.core.common.is_list_like = pd.api.types.is_list_like
  6. import matplotlib.pyplot as plt
  7. from datetime import datetime
  8. import time
  9. %matplotlib inline
  10.  
  11. start, end = datetime(2016, 1, 1), time.strftime("%x")
  12. aapl = pdr.DataReader(['AAPL'],
  13. 'yahoo',
  14. start,
  15. end)
  16. aapl.columns = [col[0].lower().replace(' ', '_')
  17. for col in aapl.columns]
  18.  
  19. aapl_close = aapl[['close']]
  20. aapl_close = aapl_close.apply(lambda x: np.log(x) - np.log(x.shift(1)))
  21. aapl_close.dropna(inplace=True)
  22.  
  23. _ = aapl_close.plot(figsize=(20, 10),
  24. linewidth=3,
  25. fontsize=14)
  26.  
  27. result = adfuller(aapl_close['close'].values)
  28. print('Augmented Dickey-Fuller test statistic: {}'.format(result[0]))
  29. print('p-value: {}'.format(result[1]))
  30. print('Critical Values:')
  31. for key, value in result[4].items():
  32. print('\t{}: {}'. format(key, value))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement