| Overall Statistics |
|
Total Orders 10 Average Win 0.61% Average Loss -1.08% Compounding Annual Return 162.131% Drawdown 1.300% Expectancy 0.249 Start Equity 50000 End Equity 50670 Net Profit 1.340% Sharpe Ratio 3.869 Sortino Ratio 0 Probabilistic Sharpe Ratio 60.740% Loss Rate 20% Win Rate 80% Profit-Loss Ratio 0.56 Alpha 0.257 Beta 1.109 Annual Standard Deviation 0.122 Annual Variance 0.015 Information Ratio 2.496 Tracking Error 0.111 Treynor Ratio 0.424 Total Fees $10.00 Estimated Strategy Capacity $2500000.00 Lowest Capacity Asset SPXW 32E3B8UZGP5DA|SPX 31 Portfolio Turnover 0.82% |
from AlgorithmImports import *
class SPXWeeklyOptionsDemoAlgorithm(QCAlgorithm):
def initialize(self):
self.set_start_date(2024, 1, 8)
self.set_end_date(2024, 1, 12)
self.set_cash(50000)
# Add SPX and weekly SPX options
self.spx = self.add_index("SPX")
spxw = self.add_index_option(self.spx.symbol, "SPXW")
self.spxw_option = spxw.symbol
spxw.set_filter(lambda u: (u.strikes(-50, 50).expiration(0, 3).puts_only().include_weeklys()))
self.current_option_symbol = None
def on_data(self,slice):
if self.time.hour == 12 and self.time.minute == 55:
# Select an option by strike offset
chain = slice.option_chains.get_value(self.spxw_option)
short_contracts = [contract for contract in chain if contract.expiry.date() == self.Time.date() and contract.right == 1 and contract.bid_price != 0 and contract.strike <= chain.underlying.close - 5]
contract_short = sorted(short_contracts, key = lambda x: x.strike, reverse=True)[0] # Select the highest strike
# Order short
symbol = contract_short.symbol
self.Securities[symbol].set_fee_model(InteractiveBrokersFeeModel())
self.Securities[symbol].set_buying_power_model(BuyingPowerModel.NULL)
self.market_order(symbol, -1)
self.current_option_symbol = symbol
# Check if the stop is reached or the option is expired at 16:00
if self.portfolio.invested == True:
symbol = self.current_option_symbol
if (self.time.hour == 16 and self.time.minute == 0):
self.liquidate(symbol)
elif self.Securities[symbol].high >= 8:
self.liquidate(symbol)