import numpy as np
from datetime import timedelta
from datetime import datetime
import pandas as pd
class MovingAverage(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2018, 1, 1)
#self.SetEndDate(2016, 1, 10)
self.SetCash(100000)
self.a = self.AddEquity("VIXY", Resolution.Minute).Symbol
self.b = self.AddEquity("SVXY", Resolution.Minute).Symbol
self.SetWarmUp(2860,Resolution.Hour)
self.previous = None
self.position = None
self.macd1 = self.MACD(self.a, 40, 85, 30, MovingAverageType.Exponential, Resolution.Hour)
self.macd2 = self.MACD(self.b, 40, 85, 30, MovingAverageType.Exponential, Resolution.Hour)
#self.rsi_vixy = self.RSI("VIXY", 18, MovingAverageType.Exponential,Resolution.Hour)
#self.rsi_svxy = self.RSI("SVXY", 18, MovingAverageType.Exponential,Resolution.Hour)
def OnData(self,Data):
if self.IsWarmingUp: return
if self.macd1.Current.Value > self.macd1.Signal.Current.Value and self.macd2.Current.Value < self.macd2.Signal.Current.Value:
#self.rsi_spy.Current.Value >= 70
if self.position == None:
self.Sell("SVXY",self.CalculateOrderQuantity("SVXY", .3))
self.Buy("VIXY", self.CalculateOrderQuantity("VIXY", 1.3))
else:
self.Liquidate("SVXY")
self.Buy("VIXY", self.CalculateOrderQuantity("VIXY", .3))
self.Sell("SVXY",self.CalculateOrderQuantity("SVXY", .3))
self.Buy("VIXY", self.CalculateOrderQuantity("VIXY", 1))
if self.macd1.Current.Value < self.macd1.Signal.Current.Value and self.macd2.Current.Value > self.macd2.Signal.Current.Value:
#self.rsi_spy.Current.Value <= 40
if self.position == None:
self.Sell("VIXY",self.CalculateOrderQuantity("VIXY", .3))
self.Buy("SVXY",self.CalculateOrderQuantity("SVXY", 1.3))
else:
self.Buy("SVXY",self.CalculateOrderQuantity("SVXY", .3))
self.Liquidate("VIXY")
self.Sell("VIXY",self.CalculateOrderQuantity("VIXY", .3))
self.Buy("SVXY",self.CalculateOrderQuantity("SVXY", 1))
###