Overall Statistics |
Total Trades 51 Average Win 3.12% Average Loss -0.40% Compounding Annual Return 19792170106220.100% Drawdown 4.600% Expectancy 3.526 Net Profit 42.806% Sharpe Ratio 8.739 Loss Rate 48% Win Rate 52% Profit-Loss Ratio 7.70 Alpha -18.211 Beta 2577.436 Annual Standard Deviation 3.003 Annual Variance 9.021 Information Ratio 8.737 Tracking Error 3.002 Treynor Ratio 0.01 Total Fees $73.72 |
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: 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: if self.position == None: self.SetHoldings("SPY", 1) elif self.position == "VIXY": self.Liquidate("VIXY") self.SetHoldings("SPY", 1) self.position = "SPY"