| Overall Statistics |
|
Total Trades 58 Average Win 4.69% Average Loss 0% Compounding Annual Return 5122034.159% Drawdown 65.900% Expectancy 0 Net Profit 277.095% Sharpe Ratio 3507.355 Probabilistic Sharpe Ratio 99.991% Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 2534.239 Beta -0.563 Annual Standard Deviation 0.722 Annual Variance 0.522 Information Ratio 3382.984 Tracking Error 0.749 Treynor Ratio -4498.814 Total Fees $0.00 Estimated Strategy Capacity $3000.00 Lowest Capacity Asset SPXW 324PKWOZ82NAM|SPX 31 |
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
#
from AlgorithmImports import *
### <summary>
### This example demonstrates how to add and trade SPX index weekly options
### </summary>
pos_size = 0.05 # percent of balance to invest
class BasicTemplateSPXWeeklyIndexOptionsAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2023, 1, 1)
self.SetEndDate(2023, 2, 14)
self.SetCash(100000)
self.spx = self.AddIndex("SPX", Resolution.Minute)
# weekly option SPX contracts
spxw = self.AddIndexOption(self.spx.Symbol, "SPXW")
# set our strike/expiry filter for this option chain
spxw.SetFilter(lambda u: (u.Strikes(-25, 25)
.Expiration(0,0)
.IncludeWeeklys()))
self.spxw_option = spxw.Symbol
self.day_low = 10000
self.day_high = 0
#self.SetWarmUp(90, Resolution.Minute)
def OnData(self,slice):
#day high and day low
current_price = self.spx.Price
if current_price < self.day_low:
self.day_low = current_price
if current_price > self.day_high:
self.day_high = current_price
ratio = current_price/self.day_high
#self.Debug(current_price)
#self.Debug(int(self.day_low))
#self.Debug(ratio)
if self.Portfolio.Invested: return
if self.Time.hour <= 10: return
delta = 0.01
chain = slice.OptionChains.GetValue(self.spxw_option)
if chain is None:
return
call = [x for x in chain if x.Right == OptionRight.Call]
put = [x for x in chain if x.Right == OptionRight.Put]
# we sort the contracts to find contract with the right delta
put_contract = sorted(put,key = lambda x: abs(abs(x.Greeks.Delta) - delta))
call_contract = sorted(call,key = lambda x: abs(x.Greeks.Delta - delta))
# if found, trade it
if len(put_contract) == 0:
return
else:
if current_price <= 1.001*self.day_low:
put_ = put_contract[0].Symbol
# self.MarketOrder(put_, -1)
self.SetHoldings(put_, -pos_size)
if len(call_contract) == 0:
return
else:
if current_price >= 0.999*self.day_high:
call_ = call_contract[0].Symbol
# self.MarketOrder(call_, -1)
self.SetHoldings(call_, -pos_size)
def OnOrderEvent(self, orderEvent):
self.Debug(str(orderEvent))
def OnEndOfDay(self, symbol):
self.day_low = 10000
self.day_high = 0