| Overall Statistics |
|
Total Trades 2 Average Win 0% Average Loss 0% Compounding Annual Return -11.483% Drawdown 1.400% Expectancy 0 Net Profit -1.020% Sharpe Ratio -3.268 Probabilistic Sharpe Ratio 3.152% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha -0.11 Beta 0.068 Annual Standard Deviation 0.034 Annual Variance 0.001 Information Ratio -0.974 Tracking Error 0.115 Treynor Ratio -1.621 Total Fees $0.00 Estimated Strategy Capacity $30000000.00 Lowest Capacity Asset SPX XEIS68694ETQ|SPX 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("SPX")
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.Daily)
self.Debug(f"We got {len(history)} from our history request for {security.Symbol}")