Overall Statistics |
Total Trades 2 Average Win 0% Average Loss 0% Compounding Annual Return 40.047% Drawdown 10.900% Expectancy 0 Net Profit 12.295% Sharpe Ratio 1.074 Probabilistic Sharpe Ratio 48.092% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.322 Beta 0.064 Annual Standard Deviation 0.298 Annual Variance 0.089 Information Ratio 0.706 Tracking Error 0.499 Treynor Ratio 4.966 Total Fees $4.94 Estimated Strategy Capacity $26000000.00 Lowest Capacity Asset OG XFN1YFH6335S|GC XHD34ASNX0NX |
from AlgorithmImports import * class FutureOptionDataAlgorithm(QCAlgorithm): option_contract_by_underlying_future_contract = {} def Initialize(self): self.SetStartDate(2020, 1, 28) self.SetEndDate(2020, 6, 1) self.SetCash(100000) self.SetWarmup(30, Resolution.Daily) self.SetSecurityInitializer(self.CustomSecurityInitializer) # Requesting data gold_futures = self.AddFuture(Futures.Metals.Gold, Resolution.Minute) gold_futures.SetFilter(0, 180) option = self.AddFutureOption(gold_futures.Symbol, lambda universe: universe.Strikes(-5, +5) .Expiration(timedelta(days=0), timedelta(days=180)) .CallsOnly() .OnlyApplyFilterAtMarketOpen()) def OnData(self, data): for kvp in data.OptionChains: # Liquidate underlying Future contract after Option assignment underlying_future_contract = kvp.Key.Underlying if self.Portfolio[underlying_future_contract].Invested: self.Liquidate(underlying_future_contract) self.option_contract_by_underlying_future_contract.pop(underlying_future_contract) chain = kvp.Value chain = [contract for contract in chain if self.Securities[contract.Symbol].IsTradable] # Continue if chain is empty or already invested in an Option on this Futures contract if not chain or underlying_future_contract in self.option_contract_by_underlying_future_contract: continue # Select the Option contract with the lowest strike price contract = sorted(chain, key = lambda x: x.Strike)[0] self.Debug(f"Delta {contract.Greeks.Delta}") self.MarketOrder(contract.Symbol, 1) self.option_contract_by_underlying_future_contract[kvp.Key.Underlying] = contract def CustomSecurityInitializer(self, security: Security) -> None: security.SetMarketPrice(self.GetLastKnownPrice(security)) if security.Type == SecurityType.FutureOption: security.PriceModel = OptionPriceModels.CrankNicolsonFD() def OnSecuritiesChanged(self, changes): for security in changes.AddedSecurities: security.SetMarketPrice(self.GetLastKnownPrice(security)) if security.Type == SecurityType.FutureOption: security.PriceModel = OptionPriceModels.CrankNicolsonFD() history = self.History(security.Symbol, 30, Resolution.Daily) #self.Debug(f"We got {len(history)} from our history request for {security.Symbol}")