Overall Statistics
Total Trades
3315
Average Win
0.01%
Average Loss
-0.01%
Compounding Annual Return
-50.114%
Drawdown
8.200%
Expectancy
-0.695
Net Profit
-8.160%
Sharpe Ratio
-10.443
Probabilistic Sharpe Ratio
0%
Loss Rate
89%
Win Rate
11%
Profit-Loss Ratio
1.66
Alpha
-0.346
Beta
-0.07
Annual Standard Deviation
0.037
Annual Variance
0.001
Information Ratio
-6.345
Tracking Error
0.149
Treynor Ratio
5.514
Total Fees
$0.00
Estimated Strategy Capacity
$42000.00
Lowest Capacity Asset
SPXW Y5ZD03UXOOI6|SPX 31
# This is not a very good strategy.
#
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)

        self.AddRiskManagement(MaximumDrawdownPercentPerSecurity(2.0))  # fix stop loss at 10%
        self.AddRiskManagement(MaximumUnrealizedProfitPercentPerSecurity(1))	# fixed take profit at 10%
        self.AddRiskManagement(TrailingStopRiskManagementModel(0.05))	# trailing stop at 5%



    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.05

        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