import numpy as np
import pandas as pd
%matplotlib inline
base_folder = 'D:/REPOS/LeanVersions/LeanSTP/Tests/TestData/'
The tests passes the with this data.
spy = pd.read_csv(base_folder + 'spy_with_macd.txt', index_col=0, parse_dates=True, dayfirst=True)
# Estimate the MACD
spy['PandasMACD'] = (spy.Close.ewm(span=12,adjust=False).mean() -
spy.Close.ewm(span=26,adjust=False).mean())
spy['PandasSignal'] = spy.MACD.ewm(span=9,adjust=False).mean()
spy['PandasHistogram'] = spy.MACD - spy.Signal
spy.head()
Open | High | Low | Close | MACD | Signal | Histogram | Volume | PandasMACD | PandasSignal | PandasHistogram | |
---|---|---|---|---|---|---|---|---|---|---|---|
Date | |||||||||||
2016-03-10 | 199.90 | 201.07 | 197.38 | 199.54 | NaN | NaN | NaN | 156800300.0 | 0.000000 | NaN | NaN |
2016-03-11 | 201.25 | 202.81 | 199.52 | 202.76 | NaN | NaN | NaN | 137945600.0 | 0.256866 | NaN | NaN |
2016-03-14 | 202.20 | 203.04 | 201.77 | 202.50 | NaN | NaN | NaN | 73546500.0 | 0.434446 | NaN | NaN |
2016-03-15 | 201.32 | 202.53 | 201.05 | 202.17 | NaN | NaN | NaN | 93119900.0 | 0.542301 | NaN | NaN |
2016-03-16 | 201.62 | 203.82 | 201.55 | 203.34 | NaN | NaN | NaN | 129225400.0 | 0.713955 | NaN | NaN |
spy.get(['MACD', 'PandasMACD', 'Signal', 'PandasSignal']).plot(grid= True, figsize=(18, 10))
<matplotlib.axes._subplots.AxesSubplot at 0x946fe48>
spy.loc['2016-04',['MACD', 'PandasMACD', 'Signal', 'PandasSignal']].plot(grid= True, figsize=(18, 10))
<matplotlib.axes._subplots.AxesSubplot at 0x97f1860>
spy.get(['Histogram', 'PandasHistogram']).plot(grid= True, figsize=(18, 10))
<matplotlib.axes._subplots.AxesSubplot at 0x98213c8>
# spy.to_csv('D:/REPOS/LeanVersions/LeanSTP/Tests/TestData/spy_macd.csv')