Overall Statistics |
Total Orders 2 Average Win 0% Average Loss -0.48% Compounding Annual Return 147.915% Drawdown 11.100% Expectancy -1 Start Equity 1000000 End Equity 1079266.25 Net Profit 7.927% Sharpe Ratio 2.205 Sortino Ratio 1.378 Probabilistic Sharpe Ratio 57.516% Loss Rate 100% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.469 Beta 1.227 Annual Standard Deviation 0.336 Annual Variance 0.113 Information Ratio 3.252 Tracking Error 0.16 Treynor Ratio 0.604 Total Fees $146.25 Estimated Strategy Capacity $41000.00 Lowest Capacity Asset SPY 31EXY8JLVV692|SPY R735QTJ8XC9X Portfolio Turnover 0.36% |
# region imports from AlgorithmImports import * # endregion class WheelStrategyAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2020, 6, 1) self.set_end_date(2020, 7, 1) self.set_cash(1_000_000) self.set_security_initializer(BrokerageModelSecurityInitializer(self.brokerage_model, FuncSecuritySeeder(self.get_last_known_prices))) self._equity = self.add_equity("SPY", data_normalization_mode=DataNormalizationMode.Raw) self._discount = 0.05 # 5% def _get_target_contract(self, right, target_price): contract_symbols = self.option_chain_provider.get_option_contract_list(self._equity.symbol, self.time) expiry = min([s.id.date for s in contract_symbols if s.id.date.date() > self.time.date() + timedelta(30)]) filtered_symbols = [ s for s in contract_symbols if (s.id.date == expiry and s.id.option_right == right and (s.id.strike_price <= target_price if right == OptionRight.PUT else s.id.strike_price >= target_price)) ] symbol = sorted(filtered_symbols, key=lambda s: s.id.strike_price, reverse=right == OptionRight.PUT)[0] self.add_option_contract(symbol) return symbol def on_data(self, data): if not self.portfolio.invested and self.is_market_open(self._equity.symbol): symbol = self._get_target_contract(OptionRight.PUT, self._equity.price * (1-self._discount)) #self.market_order(symbol, -int(self.portfolio.cash_book['USD'].amount / symbol.id.strike_price / 100)) self.set_holdings(symbol, -1) elif [self._equity.symbol] == [symbol for symbol, holding in self.portfolio.items() if holding.invested]: symbol = self._get_target_contract(OptionRight.CALL, self._equity.price * (1+self._discount)) self.market_order(symbol, -self._equity.holdings.quantity / 100)