Overall Statistics |
Total Trades 1 Average Win 0% Average Loss 0% Compounding Annual Return 7.502% Drawdown 1.200% Expectancy 0 Net Profit 0.079% Sharpe Ratio 0.638 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 1.409 Beta 2.107 Annual Standard Deviation 0.179 Annual Variance 0.032 Information Ratio 7.762 Tracking Error 0.094 Treynor Ratio 0.054 Total Fees $1.56 |
from QuantConnect.Securities.Option import OptionPriceModels class ParticleMultidimensionalAntennaArray(QCAlgorithm): def Initialize(self): self.SetStartDate(2020, 6, 8) # Set Start Date self.SetEndDate(2020, 6, 9) self.SetCash(100000) # Set Strategy Cash self.bond = self.AddEquity("SPY") self.bond.SetDataNormalizationMode(DataNormalizationMode.Raw) self.bondSymbol = self.bond.Symbol self.bondOptionTargetDuration = TimeSpan.FromDays(8) self.bondOption = self.AddOption(self.bondSymbol) self.bondOption.SetFilter(0, 100, TimeSpan.FromDays(0), self.bondOptionTargetDuration) self.bondOption.PriceModel = OptionPriceModels.BinomialCoxRossRubinstein() self.bondOptionSymbol = self.bondOption.Symbol self.sellCallsTime = self.Time + timedelta(hours = 10, minutes = 30) self.SetWarmUp(timedelta(days=20)) def OnData(self, data): if self.IsWarmingUp: x = 1 return if not self.Portfolio.Invested: self.SetHoldings("SPY", 1) if self.Time >= self.sellCallsTime: x = self.SellBondOptions() def GetBondCallOption(self, expirationDelta, targetDelta): optionchain = None y = len([x for x in self.CurrentSlice.OptionChains.Keys]) for kvp in self.CurrentSlice.OptionChains: if kvp.Key != self.bondOptionSymbol: continue optionchain = kvp.Value if not optionchain: return None optionchain = [x for x in optionchain if x.Right == OptionRight.Call] optionchain = sorted(optionchain, key = lambda x: x.Expiry) x = 1 return optionchain[0] if len(optionchain) > 0 else None def OnOrderEvent(self, orderEvent): order = self.Transactions.GetOrderById(orderEvent.OrderId) if order.Type == OrderType.OptionExercise: self.Debug(f"{self.Time} Bond exercise") num = self.Portfolio.Cash // self.Securities[self.bondSymbol].AskPrice self.Debug(f"{self.Time} on order event buy") self.Buy(self.bondSymbol, num) def SellBondOptions(self): self.bondOption = self.GetBondCallOption(self.bondOptionTargetDuration, .2) if not self.bondOption: return 0 num = self.Portfolio[self.bondSymbol].Quantity // 100 self.Debug(f"{self.Time} selling bond option for {self.bondOption.BidPrice * num * 100}") self.Sell(self.bondOption.Symbol, num) return 1