Overall Statistics
Total Trades
56
Average Win
0.01%
Average Loss
0%
Compounding Annual Return
2.394%
Drawdown
0.100%
Expectancy
0
Net Profit
0.290%
Sharpe Ratio
11.994
Probabilistic Sharpe Ratio
99.998%
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
0.017
Beta
-0.001
Annual Standard Deviation
0.001
Annual Variance
0
Information Ratio
-4.043
Tracking Error
0.135
Treynor Ratio
-14.626
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>
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)

        if len(call_contract) == 0: 
            return
        else:
            if current_price >= 0.999*self.day_high:
                call_ = call_contract[0].Symbol
                self.MarketOrder(call_, -1)
     

    def OnOrderEvent(self, orderEvent):
        self.Debug(str(orderEvent))
    
    def OnEndOfDay(self):
        self.day_low = 10000
        self.day_high = 0