| Overall Statistics |
|
Total Trades 7 Average Win 2.61% Average Loss -2.11% Compounding Annual Return -33.092% Drawdown 7.200% Expectancy -0.255 Net Profit -3.142% Sharpe Ratio -1.491 Probabilistic Sharpe Ratio 20.829% Loss Rate 67% Win Rate 33% Profit-Loss Ratio 1.24 Alpha -0.256 Beta 0.088 Annual Standard Deviation 0.183 Annual Variance 0.034 Information Ratio -0.325 Tracking Error 0.253 Treynor Ratio -3.098 Total Fees $0.00 |
from QuantConnect.Python import PythonQuandl # quandl data not CLOSE
from QuantConnect.Python import PythonData # custom data
from QuantConnect.Data import SubscriptionDataSource
from datetime import datetime, timedelta
import decimal
class CboeVix(PythonData):
'''CBOE Vix Download Custom Data Class'''
def GetSource(self, config, date, isLiveMode):
url_vix = "http://www.cboe.com/publish/scheduledtask/mktdata/datahouse/vixcurrent.csv"
return SubscriptionDataSource(url_vix,
SubscriptionTransportMedium.RemoteFile)
def Reader(self, config, line, date, isLiveMode):
if not (line.strip() and line[0].isdigit()): return None
# New CboeVix object
index = CboeVix();
index.Symbol = config.Symbol
try:
# Example File Format:
# Date VIX Open VIX High VIX Low VIX Close
# 01/02/2004 17.96 18.68 17.54 18.22
#print line
data = line.split(',')
date = data[0].split('/')
index.Time = datetime(int(date[2]), int(date[0]), int(date[1]))
index.Value = decimal.Decimal(data[4])
index["Open"] = float(data[1])
index["High"] = float(data[2])
index["Low"] = float(data[3])
index["Close"] = float(data[4])
except ValueError:
# Do nothing
return None
# except KeyError, e:
# print 'I got a KeyError - reason "%s"' % str(e)
return index
class CboeVixsm(PythonData):
'''CBOE Vix Download Custom Data Class'''
def GetSource(self, config, date, isLiveMode):
url_vix = "https://www.cboe.com/publish/scheduledtask/mktdata/datahouse/vix9ddailyprices.csv"
return SubscriptionDataSource(url_vix,
SubscriptionTransportMedium.RemoteFile)
def Reader(self, config, line, date, isLiveMode):
if not (line.strip() and line[0].isdigit()): return None
# New CboeVix object
index = CboeVixsm();
index.Symbol = config.Symbol
try:
# Example File Format:
# Date VIX Open VIX High VIX Low VIX Close
# 01/02/2004 17.96 18.68 17.54 18.22
#print line
data = line.split(',')
date = data[0].split('/')
index.Time = datetime(int(date[2]), int(date[0]), int(date[1]))
index.Value = decimal.Decimal(data[4])
index["Open"] = float(data[1])
index["High"] = float(data[2])
index["Low"] = float(data[3])
index["Close"] = float(data[4])
except ValueError:
# Do nothing
return None
# except KeyError, e:
# print 'I got a KeyError - reason "%s"' % str(e)
return index
# NB: CboeVxV class == CboeVix class, except for the URL
class CboeVxv(PythonData):
'''CBOE VXV Download Custom Data Class'''
def GetSource(self, config, date, isLiveMode):
url_vxv = "http://www.cboe.com/publish/scheduledtask/mktdata/datahouse/vix3mdailyprices.csv"
return SubscriptionDataSource(url_vxv,
SubscriptionTransportMedium.RemoteFile)
def Reader(self, config, line, date, isLiveMode):
if not (line.strip() and line[0].isdigit()): return None
index = CboeVxv();
index.Symbol = config.Symbol
try:
# Example File Format:
# OPEN HIGH LOW CLOSE
# 12/04/2007 24.8 25.01 24.15 24.65
data = line.split(',')
date = data[0].split('/')
index.Time = datetime(int(date[2]), int(date[0]), int(date[1]))
index.Value = decimal.Decimal(data[4])
index["Open"] = float(data[1])
index["High"] = float(data[2])
index["Low"] = float(data[3])
index["Close"] = float(data[4])
except ValueError:
# Do nothing
return None
return indexfrom System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Data.Custom.CBOE import *
from QuantConnect.Python import PythonQuandl # quandl data not CLOSE
from QuantConnect.Data import SubscriptionDataSource
from QuantConnect.Python import PythonData
import pandas as pd
from my_custom_data import * # QuandlFuture, CboeVix, CboeVxV
from QuantConnect.Python import PythonData # custom data
from datetime import date, timedelta, datetime
from decimal import Decimal
import numpy as np
from math import floor
import json
class QuandlFutures(PythonQuandl):
def __init__(self):
self.ValueColumnName = "open"
class VentralTachyonAtmosphericScrubbers(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 9, 4) # Set Start Date
#self.SetStartDate(2018, 3, 20)
self.SetEndDate(2020, 10, 4)
self.SetCash(5000) # Set Strategy Cash
self.UniverseSettings.FeeModel = ConstantFeeModel(0.0)
self.UniverseSettings.Leverage = 1
self.SetBrokerageModel(BrokerageName.Alpaca, AccountType.Margin)
self.perc_qnty = 1
self.selectedResolution = Resolution.Daily
self.uvxy = self.AddEquity("UVXY", self.selectedResolution).Symbol
self.svxy = self.AddEquity("SVXY", self.selectedResolution).Symbol
self.spy = self.AddEquity("SPY", self.selectedResolution).Symbol
self.tqqq = self.AddEquity("TQQQ", self.selectedResolution).Symbol
self.spySma = self.SMA(self.spy, 25, self.selectedResolution, Field.Open)
self.vixStr = "VIX"
self.vxvStr = "VXV"
self.vixsmStr = "VIX9D"
self.AddData(CboeVix, "VIX")
self.AddData(CboeVxv, "VXV")
self.AddData(CboeVixsm, "VIX9D")
self.macd = self.MACD("SPY", 12, 26, 6, MovingAverageType.Exponential, self.selectedResolution, Field.Open)
self.yvixRatio = 0
self.yvixCrossUp = False
self.yspy = 0
self.yspySma = 0
def OnData(self, data):
if self.vixStr not in data or self.vxvStr not in data: return
vixPrice = data[self.vixStr].Open
vxvPrice = data[self.vxvStr].Open
vixsmPrice = None
if self.vixsmStr in data:
vixsmPrice = data[self.vixsmStr].Open
uvxy_qnty = self.Portfolio[self.uvxy].Quantity
svxy_qnty = self.Portfolio[self.svxy].Quantity
tqqq_qnty = self.Portfolio[self.tqqq].Quantity
vixRatio = vixPrice/vxvPrice
#self.Plot("Vix/Vix3M", "Vix/Vix3M", vixRatio)
#self.Plot("SVXY", "SVXY", self.Securities["SVXY"].Price)
#self.Plot("SPY", "SPY", self.Securities["SPY"].Open)
#self.Plot("MACD", "Source", self.macd.Current.Value)
#self.Plot("MACD", "Signal", self.macd.Signal.Current.Value)
vixCrossUp = False
if vixsmPrice:
vixCrossUp = vixsmPrice > vixPrice
macdLong = self.macd.Current.Value < self.macd.Signal.Current.Value
inLong = uvxy_qnty != 0
inShort = svxy_qnty != 0
inRest = tqqq_qnty != 0
shortEntry = (vixRatio < 0.95) and not vixCrossUp and not (self.Securities["SPY"].Open <= self.spySma.Current.Value and self.yspy > self.yspySma)
shortExit = inShort and (not shortEntry)
longEntry = vixRatio > 1.05 and vixCrossUp and macdLong
longExit = inLong and (not longEntry)
if shortExit or longExit:
self.Liquidate()
if not inRest and longExit:
self.SetHoldings(self.tqqq, self.perc_qnty)
return
if (shortEntry):
if inLong:
self.Liquidate(self.uvxy)
if inRest:
self.Liquidate(self.tqqq)
if not inShort:
self.SetHoldings(self.svxy, self.perc_qnty)
if (longEntry):
if inShort:
self.Liquidate(self.svxy)
if inRest:
self.Liquidate(self.tqqq)
if not inLong:
self.SetHoldings(self.uvxy, self.perc_qnty)
self.yvixRatio = vixRatio
self.yvixCrossUp = vixCrossUp
self.yspy = self.Securities["SPY"].Open
self.yspySma = self.spySma.Current.Value