Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
import numpy as np
from datetime import datetime
import pandas as pd
import math
import numpy as np


class VolTrading(QCAlgorithm):

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

    def Initialize(self):

        self.SetStartDate(2018,1,1) #Set Start Date
        self.SetEndDate(2018,1,10) #Set End Date
        self.SetCash(10000) #Set Strategy Cash
        self.spy = self.AddEquity("SPY", Resolution.Minute).Symbol
        self.vixy = self.AddEquity("VIXY", Resolution.Minute).Symbol
        self.SetWarmUp(440)



    def OnData(self, data):
        history_s = self.History([self.spy], 2, Resolution.Minute)
        history_v = self.History([self.vixy], 2, Resolution.Minute)
        if not history_v.empty and not history_s.empty:
            last_minute_close_s = history_s.loc[str(self.spy)]["close"][-1]
            last_minute_close_v = history_v.loc[str(self.vixy)]["close"][-1]
        else:
            return
        
        SPercent = np.log((float(self.Securities[self.spy].Price))/last_minute_close_s)
        VPercent = np.log((float(self.Securities[self.vixy].Price))/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"