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_ohlcv.txt', index_col=0, parse_dates=True)
# Estimate the MACD
spy['MACD'] = (spy.Close.ewm(span=12,adjust=False).mean() -
spy.Close.ewm(span=26,adjust=False).mean())
spy['Signal'] = spy.MACD.ewm(span=9,adjust=False).mean()
spy['Histogram'] = spy.MACD - spy.Signal
spy.get(['MACD', 'Signal']).plot(grid= True, figsize=(18, 10))
<matplotlib.axes._subplots.AxesSubplot at 0x9219ba8>
spy.Histogram.plot(grid= True, figsize=(18, 10))
<matplotlib.axes._subplots.AxesSubplot at 0x97a92e8>
spy.head()
Open | High | Low | Close | Volume | MACD | Signal | Histogram | |
---|---|---|---|---|---|---|---|---|
Date | ||||||||
2013-02-22 | 151.16 | 151.89 | 150.49 | 151.89 | 106292600.0 | 0.000000 | 0.000000 | 0.000000 |
2013-02-25 | 152.63 | 152.86 | 149.00 | 149.00 | 245483200.0 | -0.230541 | -0.046108 | -0.184433 |
2013-02-26 | 149.72 | 150.20 | 148.73 | 150.02 | 186331600.0 | -0.327170 | -0.102321 | -0.224849 |
2013-02-27 | 149.89 | 152.33 | 149.76 | 151.91 | 143932600.0 | -0.248379 | -0.131532 | -0.116846 |
2013-02-28 | 151.90 | 152.87 | 151.41 | 151.61 | 123724200.0 | -0.207749 | -0.146776 | -0.060973 |
spy.to_csv('D:/REPOS/LeanVersions/LeanSTP/Tests/TestData/spy_macd.csv')