import numpy as np
### <summary>
### Basic template algorithm simply initializes the date range and cash. This is a skeleton
### framework you can use for designing an algorithm.
### </summary>
class BasicTemplateAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2010,10, 7) #Set Start Date
self.SetEndDate(2013,10,11) #Set End Date
self.SetCash(100000) #Set Strategy Cash
self.AddEquity("SPY", Resolution.Minute)
self.AddEquity("AAPL", Resolution.Minute)
self._EMA = self.EMA("SPY", 30, Resolution.Minute)
self.SetBenchmark("SPY")
self.position = None
def OnData(self, data):
if not self._EMA.IsReady:
return
if self._EMA.Current.Value >= self.Portfolio["SPY"].Price and not self.Portfolio.Invested:
self.SetHoldings("SPY", 1)
self.position == "SPY"
else:
self.Liquidate("SPY")
self.SetHoldings("AAPL", 1)
self.position == "AAPL"