| Overall Statistics |
|
Total Trades 33 Average Win 6.24% Average Loss -1.98% Compounding Annual Return 18269.169% Drawdown 24.400% Expectancy 1.333 Net Profit 23.892% Sharpe Ratio 3.219 Loss Rate 44% Win Rate 56% Profit-Loss Ratio 3.15 Alpha 2.081 Beta 216.439 Annual Standard Deviation 1.806 Annual Variance 3.263 Information Ratio 3.209 Tracking Error 1.806 Treynor Ratio 0.027 Total Fees $43.45 |
import numpy as np
from datetime import datetime
import pandas as pd
class VolTrading(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2018,2,1) #Set Start Date
self.SetEndDate(2018,2,15) #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(10)
self.previous = None
self.position = None
def OnData(self, data):
if self.IsWarmingUp: return
if data.Bars.ContainsKey("SPY") or data.Bars.ContainsKey("VIXY"):
SPercent = np.log(float(self.Securities[self.spy].Price/data["SPY"].Open))
VPercent = np.log(float(self.Securities[self.vixy].Price/data["VIXY"].Open))
if SPercent <= -0.003:
#or Vpercent >= .001
if self.position == None:
self.SetHoldings("VIXY", 1)
elif self.position == "SPY":
self.Liquidate("SPY")
self.SetHoldings("VIXY", 1)
self.position = "VIXY"
if SPercent >= 0.003:
#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"import numpy as np
from datetime import datetime
import pandas as pd
class VolTrading(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2018,2,1) #Set Start Date
#self.SetEndDate(2018,2,5) #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(10)
self.previous = None
self.position = None
def OnData(self, data):
if self.IsWarmingUp: return
if data.Bars.ContainsKey("SPY") or data.Bars.ContainsKey("VIXY"):
history_s = self.History([self.spy], 1, Resolution.Minute)
history_v = self.History([self.vixy], 1, Resolution.Minute)
if str(self.spy) in history_s.index and str(self.vixy) in history_v.index:
last_minute_close_s = history_s.loc[str(self.spy)]["close"][-1]
last_minute_close_v = history_v.loc[str(self.vixy)]["close"][-1]
SPercent = np.log(float(self.Securities[self.spy].Price/data["SPY"].Open))
VPercent = np.log(float(self.Securities[self.vixy].Price/data["VIXY"].Open))
if SPercent <= -0.001:
#or Vpercent >= .001
if self.position == None:
self.SetHoldings("VIXY", 1)
elif self.position == "SPY":
self.Liquidate("SPY")
self.SetHoldings("VIXY", 1)
self.position = "VIXY"
if SPercent >= .001:
#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"
### want to lock in returns and start algorthim over
# if return is >= .5:
#liquidate all positions and start algrothim over
#elif return <=-.3:
#stop loss
#else:
#keep running
### id sd is high buy into or if sd hight and regression is hight buy intoimport numpy as np
from datetime import datetime
import pandas as pd
class VolTrading(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2018,2,1) #Set Start Date
self.SetEndDate(2018,2,15) #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(100)
self.previous = None
self.position = None
def OnData(self, data):
self.stop_price_v_high = float(data["VIXY"].Open) * 1.05
self.stop_price_v_low = float(data["VIXY"].Open) * .9
self.stop_price_s_high = float(data["SPY"].Open) * 1.05
self.stop_price_s_low = float(data["SPY"].Open) * .9
if self.IsWarmingUp: return
if data.Bars.ContainsKey("SPY") or data.Bars.ContainsKey("VIXY"):
SPercent = np.log(float(self.Securities[self.spy].Price/data["SPY"].Open))
VPercent = np.log(float(self.Securities[self.vixy].Price/data["VIXY"].Open))
if SPercent <= -0.003:
#and VPercent >= .003
if self.position == None:
self.SetHoldings("VIXY", 1)
elif self.position == "SPY":
self.Liquidate("SPY")
self.SetHoldings("VIXY", 1)
self.position = "VIXY"
if SPercent >= .003:
#and VPercent <= -.003
if self.position == None:
self.SetHoldings("SPY", 1)
elif self.position == "VIXY":
self.Liquidate("VIXY")
self.SetHoldings("SPY", 1)
self.position = "SPY"
if self.position =="VIXY" and self.Securities[self.vixy].Price == self.stop_price_v_high:
self.Liquidate("VIXY")
elif self.position =="VIXY" and self.Securities[self.vixy].Price == self.stop_price_v_low:
self.Liquidate("VIXY")
if self.position =="SPY" and self.Securities[self.spy].Price == self.stop_price_s_high:
self.Liquidate("SPY")
elif self.position =="SPY" and self.Securities[self.spy].Price == self.stop_price_s_low:
self.Liquidate("SPY")
#if self.position =="VIXY" and self.vixy == self.stop_price_v_high:
# self.StopMarketOrder(self.vixy, -self.Portfolio["VIXY"].Quantity, stop_price_v_high)
#elif self.position =="VIXY" and self.vixy == self.stop_price_v_low:
# self.StopMarketOrder(self.vixy, -self.Portfolio["VIXY"].Quantity, stop_price_v_low)
#if self.position =="SPY" and self.spy == self.stop_price_s_high:
# self.StopMarketOrder(self.spy, -self.Portfolio["SPY"].Quantity, stop_price_s_high)
#elif self.position =="SPY" and self.spy == self.stop_price_s_low:
# self.StopMarketOrder(self.spy, -self.Portfolio["SPY"].Quantity, stop_price_s_low)
### want to lock in returns and start algorthim over
# if return is >= .5:
#liquidate all positions and start algrothim over
#elif return <=-.3:
#stop loss
#else:
#keep running
## change vixy to another VIX
## look to see if can use correlation as
# when correctation is close to - 1 and 1 use
## try to use X
### id sd is high buy into or if sd hight and regression is hight buy into
###import numpy as np
from datetime import datetime
import pandas as pd
class VolTrading(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2018,2,1) #Set Start Date
self.SetEndDate(2018,2,15) #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(100)
self.previous = None
self.position = None
def OnData(self, data):
self.stop_price_v_high = float(data["VIXY"].Open) * 1.05
self.stop_price_v_low = float(data["VIXY"].Open) * .9
self.stop_price_s_high = float(data["SPY"].Open) * 1.05
self.stop_price_s_low = float(data["SPY"].Open) * .9
if self.IsWarmingUp: return
if self.position =="VIXY" and self.vixy == self.stop_price_v_high:
self.StopMarketOrder(self.vixy, -self.Portfolio["VIXY"].Quantity, stop_price_v_high)
elif self.position =="VIXY" and self.vixy == self.stop_price_v_low:
self.StopMarketOrder(self.vixy, -self.Portfolio["VIXY"].Quantity, stop_price_v_low)
if self.position =="SPY" and self.spy == self.stop_price_s_high:
self.StopMarketOrder(self.spy, -self.Portfolio["SPY"].Quantity, stop_price_s_high)
elif self.position =="SPY" and self.spy == self.stop_price_s_low:
self.StopMarketOrder(self.spy, -self.Portfolio["SPY"].Quantity, stop_price_s_low)
if data.Bars.ContainsKey("SPY") or data.Bars.ContainsKey("VIXY"):
SPercent = np.log(float(self.Securities[self.spy].Price/data["SPY"].Open))
VPercent = np.log(float(self.Securities[self.vixy].Price/data["VIXY"].Open))
if SPercent <= -0.003:
#and VPercent >= .003
if self.position == None:
self.SetHoldings("VIXY", 1)
elif self.position == "SPY":
self.Liquidate("SPY")
self.SetHoldings("VIXY", 1)
self.position = "VIXY"
if SPercent >= .003:
#and VPercent <= -.003
if self.position == None:
self.SetHoldings("SPY", 1)
elif self.position == "VIXY":
self.Liquidate("VIXY")
self.SetHoldings("SPY", 1)
self.position = "SPY"
#if self.position =="VIXY" and self.Securities[self.vixy].Price == self.stop_price_v_high:
# self.Liquidate("VIXY")
#elif self.position =="VIXY" and self.Securities[self.vixy].Price == self.stop_price_v_low:
# self.Liquidate("VIXY")
#if self.position =="SPY" and self.Securities[self.spy].Price == self.stop_price_s_high:
# self.Liquidate("SPY")
#elif self.position =="SPY" and self.Securities[self.spy].Price == self.stop_price_s_low:
# self.Liquidate("SPY")
#if self.position =="VIXY" and self.vixy == self.stop_price_v_high:
# self.StopMarketOrder(self.vixy, -self.Portfolio["VIXY"].Quantity, stop_price_v_high)
#elif self.position =="VIXY" and self.vixy == self.stop_price_v_low:
# self.StopMarketOrder(self.vixy, -self.Portfolio["VIXY"].Quantity, stop_price_v_low)
#if self.position =="SPY" and self.spy == self.stop_price_s_high:
# self.StopMarketOrder(self.spy, -self.Portfolio["SPY"].Quantity, stop_price_s_high)
#elif self.position =="SPY" and self.spy == self.stop_price_s_low:
# self.StopMarketOrder(self.spy, -self.Portfolio["SPY"].Quantity, stop_price_s_low)
### want to lock in returns and start algorthim over
# if return is >= .5:
#liquidate all positions and start algrothim over
#elif return <=-.3:
#stop loss
#else:
#keep running
## change vixy to another VIX
## look to see if can use correlation as
# when correctation is close to - 1 and 1 use
## try to use X
### id sd is high buy into or if sd hight and regression is hight buy into
###