Overall Statistics
import numpy as np
from datetime import datetime
import pandas as pd



class VolTrading(QCAlgorithm):

    def __init__(self):
            self.previous = None
            self.position = None
            
            
            

    def Initialize(self):
      
        self.SetStartDate(2018,10,1)  #Set Start Date
        #self.SetEndDate(2018,1,1)    #Set End Date
        self.SetCash(10000)           #Set Strategy Cash
        self.AddEquity("SPY", Resolution.Minute)
        self.AddEquity("VIXY", Resolution.Minute)
        self.SetWarmUp(440)
        

    def OnData(self, data):
        
        
         #history_s = self.History(["SPY"], 1, Resolution.Minute)
         #last_minute_close_s = history_s.loc["SPY"]["close"][-1]
         #history_v = self.History(["IEF"], 1, Resolution.Minute)
         #last_minute_close_v = history_v.loc["IEF"]["close"][-1]
         
         #if self.position == None:
             # return messes everything up
         ##add if statement here if none skip it ##self.Securities["SPY"].Price
         #self.SPercent =  np.log(((float(self.Identity("SPY").Current.Value))/(float(data["SPY"].Open))))
         #self.VPercent =  np.log(((float(self.Identity("VIXY").Current.Value))/(float(data["VIXY"].Open))))
        
         self.SPercent =  np.log(((float(self.Identity("SPY").Current.Value))/(float(data["SPY"].Open))))
         self.VPercent =  np.log(((float(self.Identity("VIXY").Current.Value))/(float(data["VIXY"].Open))))
         
         
         if self.IsWarmingUp:
            return 
        
         #if  self.SPercent is None:
         #    return
         #if  self.VPercent is None:
         #  return
      
         if self.SPercent <= -.005:
             #or VPercent >=.01
             if self.position == None:
                self.SetHoldings("VIXY", 1)
             elif self.position == "SPY":
                  self.Liquidate("SPY")  
                  self.SetHoldings("VIXY", 1)
             self.position = "VIXY"
                  
                  
         elif self.SPercent >= .005:
              #or VPercent <=-.01
             if self.position == None:
                self.SetHoldings("SPY", 1)
             elif self.position == "VIXY":
                  self.Liquidate("VIXY")  
                  self.SetHoldings("SPY", 1)
             self.position = "SPY"
             
             ##1. run time error with the NoneType             
             ##2. when trades are excuted 
             ## 3.error with not buying anyhtng other than vixy may be do to the if
             
             
             #####
import numpy as np
from datetime import datetime
import pandas as pd
import math


class VolTrading(QCAlgorithm):

    def __init__(self):
            self.previous = None
            self.position = None
            
            
            

    def Initialize(self):
      
        self.SetStartDate(2012,1,1)  #Set Start Date
        #self.SetEndDate(2018,10,29)    #Set End Date
        self.SetCash(10000)           #Set Strategy Cash
        self.AddEquity("SPY", Resolution.Minute)
        self.AddEquity("VIXY", Resolution.Minute)
        self.SetWarmUp(440)
        

    def OnData(self, data):
         history_s = self.History(["SPY"], 1, Resolution.Minute)
         last_minute_close_s = history_s.loc["SPY"]["close"][-1]
         
         history_v = self.History(["VIXY"], 1, Resolution.Minute)
         last_minute_close_v = history_v.loc["VIXY"]["close"][-1]
         self.SPercent =  math.log((self.Identity("SPY").Current.Value)/(last_minute_close_s))
         self.VPercent =  math.log((self.Identity("VIXY").Current.Value)/(last_minute_close_v))
        
       
         if self.IsWarmingUp:
            return 
      
         if SPercent <= -.01:
             if self.position == None:
                self.SetHoldings("VIXY", 1)
             elif self.position == "SPY":
                  self.Liquidate("SPY")  
                  self.SetHoldings("VIXY", 1)
             self.position = "VIXY"
                  
                  
         elif VPercent <= -.01:
             if self.position == None:
                self.SetHoldings("SPY", 1)
             elif self.position == "VIXY":
                  self.Liquidate("VIXY")  
                  self.SetHoldings("SPY", 1)
             self.position = "SPY"
import numpy as np
from datetime import datetime
import pandas as pd



class VolTrading(QCAlgorithm):

    def __init__(self):
            self.previous = None
            self.position = None
            
            
            

    def Initialize(self):
      
        self.SetStartDate(2017,3,1)  #Set Start Date
        self.SetEndDate(2017,5,1)    #Set End Date
        self.SetCash(10000)           #Set Strategy Cash
        self.AddEquity("SPY", Resolution.Minute)
        self.AddEquity("VIXY", Resolution.Minute)
        self.SetWarmUp(440)
        

    def OnData(self, data):
        
        
         #history_s = self.History(["SPY"], 1, Resolution.Minute)
         #last_minute_close_s = history_s.loc["SPY"]["close"][-1]
         #history_v = self.History(["IEF"], 1, Resolution.Minute)
         #last_minute_close_v = history_v.loc["IEF"]["close"][-1]
         
         #if self.position == None:
             # return messes everything up
         ##add if statement here if none skip it ##self.Securities["SPY"].Price
         #self.SPercent =  np.log(((float(self.Identity("SPY").Current.Value))/(float(data["SPY"].Open))))
         #self.VPercent =  np.log(((float(self.Identity("VIXY").Current.Value))/(float(data["VIXY"].Open))))
        
         self.SPercent =  np.log(((float(self.Securities["SPY"].Price))/(float(data["SPY"].Open))))
         self.VPercent =  np.log(((float(self.Securities["VIXY"].Price))/(float(data["VIXY"].Open))))
        
        
         if self.IsWarmingUp:
            return 
         #if  self.SPercent is None:
        #    return
         #if  self.VPercent is None:
          #  return
      
         if self.SPercent <= -.005:
             #or VPercent >=.01
             if self.position == None:
                self.SetHoldings("VIXY", 1)
             elif self.position == "SPY":
                  self.Liquidate("SPY")  
                  self.SetHoldings("VIXY", 1)
             self.position = "VIXY"
                  
                  
         elif self.SPercent >= .005:
              #or VPercent <=-.01
             if self.position == None:
                self.SetHoldings("SPY", 1)
             elif self.position == "VIXY":
                  self.Liquidate("VIXY")  
                  self.SetHoldings("SPY", 1)
             self.position = "SPY"
             
             ## run time error with the none
             ## error with not buying anyhtng other than vixy may be do to the if
             ##statemt if statement continues to run then  cant get to elif
             ## check to if else isted of elif
             
             ## and in a stop loss at a certian amount
             ## also add in a "lock in results" for gain above...import numpy as np
from datetime import datetime
import pandas as pd



class VolTrading(QCAlgorithm):

    def __init__(self):
            self.previous = None
            self.position = None
            
            
            

    def Initialize(self):
      
        self.SetStartDate(2018,10,1)  #Set Start Date
        #self.SetEndDate(2017,10,1)    #Set End Date
        self.SetCash(10000)           #Set Strategy Cash
        self.AddEquity("SPY", Resolution.Minute)
        self.AddEquity("VIXY", Resolution.Minute)
        self.SetWarmUp(440)
        

    def OnData(self, data):
         #history_s = self.History(["SPY"], 1, Resolution.Minute)
         #last_minute_close_s = history_s.loc["SPY"]["close"][-1]
         
         #history_v = self.History(["IEF"], 1, Resolution.Minute)
         #last_minute_close_v = history_v.loc["IEF"]["close"][-1]
         self.SPercent =  np.log(abs((float(self.Identity("SPY").Current.Value))/(float(data["SPY"].Open))))
         self.VPercent =  np.log(abs((float(self.Identity("VIXY").Current.Value))/(float(data["VIXY"].Open))))
        
        
         if self.IsWarmingUp:
            return 
      
         if self.SPercent <= -.005:
             #or VPercent >=.01
             if self.position == None:
                self.SetHoldings("VIXY", 1)
             elif self.position == "SPY":
                  self.Liquidate("SPY")  
                  self.SetHoldings("VIXY", 1)
             self.position = "VIXY"
                  
                  
         elif self.SPercent >= .005:
              #or VPercent <=-.01
             if self.position == None:
                self.SetHoldings("SPY", 1)
             elif self.position == "VIXY":
                  self.Liquidate("VIXY")  
                  self.SetHoldings("SPY", 1)
             self.position = "SPY"
             
             
             
             
             ## and in a stop loss at a certian