import numpy as np
import pandas as pd
class HistoryAndIndicatorArrays(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2017,1,28)
self.SetEndDate(2017,1,30)
self.SetCash(100000) # Set Strategy Cash
# Default resolution is Minute
self.symbol = self.AddEquity("SPY").Symbol
# Default resolution is the one defined by AddEquity
self.macd = self.MACD(self.symbol, 12, 26, 9, MovingAverageType.Simple)
self.rsi = self.RSI(self.symbol, 14, MovingAverageType.Simple)
self.history = self.History(self.symbol, 240).close.unstack(0)
index = []
macdHistory = {}
rsiHistory = {}
for time, close in self.history[self.symbol].iteritems():
index.append(time)
self.macd.Update(time, close)
if self.macd.IsReady:
macdHistory[time] = self.macd.Current.Value
self.rsi.Update(time, close)
if self.rsi.IsReady:
rsiHistory[time] = self.rsi.Current.Value
self.history = pd.DataFrame({
'Close': self.history[self.symbol],
'MACD': pd.Series(data=macdHistory, index=index),
'RSI': pd.Series(data=rsiHistory, index=index)
})
self.history = self.history.dropna(how='any',axis=0)