| Overall Statistics |
|
Total Trades 2 Average Win 0% Average Loss 0% Compounding Annual Return -52.016% Drawdown 8.000% Expectancy 0 Net Profit -5.985% Sharpe Ratio -2.511 Probabilistic Sharpe Ratio 6.319% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha -0.397 Beta 0.098 Annual Standard Deviation 0.158 Annual Variance 0.025 Information Ratio -2.188 Tracking Error 0.182 Treynor Ratio -4.043 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset VIX XFF9X9TJXENI|VIX 31 |
from AlgorithmImports import *
class IndexOptionsDataAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 1, 1)
self.SetEndDate(2020, 2, 1)
self.SetCash(200000)
index = self.AddIndex("VIX")
option = self.AddOption(index.Symbol)
option.SetFilter(-2, +2, 0, 180)
self.optionSymbol = option.Symbol
def OnData(self, data):
if not self.Portfolio.Invested and self.IsMarketOpen(self.optionSymbol):
chain = data.OptionChains.get(self.optionSymbol)
if not chain:
return
callContracts = [c for c in chain if c.Right == OptionRight.Call]
if callContracts:
expiry = max([c.Expiry for c in callContracts])
callContracts = sorted([c for c in callContracts if c.Expiry == expiry],
key=lambda c: c.Strike)
if len(callContracts) < 2:
return
longCall, shortCall = callContracts[0:2]
# Use all the buying power
quantity = min([
abs(self.CalculateOrderQuantity(shortCall.Symbol, -1)),
abs(self.CalculateOrderQuantity(longCall.Symbol, 1))])
self.MarketOrder(shortCall.Symbol, -quantity)
self.MarketOrder(longCall.Symbol, quantity)
expectedMarginUsage = max((longCall.Strike - shortCall.Strike) * self.Securities[longCall.Symbol].SymbolProperties.ContractMultiplier * quantity, 0)
if expectedMarginUsage != self.Portfolio.TotalMarginUsed:
raise Exception("Unexpect margin used!")
def OnSecuritiesChanged(self, changes):
for security in changes.AddedSecurities:
if security.Type == SecurityType.IndexOption:
# Historical data
history = self.History(security.Symbol, 10, Resolution.Minute)
self.Debug(f"We got {len(history)} from our history request for {security.Symbol}")