Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Sortino Ratio
0
Probabilistic Sharpe Ratio
0%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
2.493
Tracking Error
0.137
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
Portfolio Turnover
0%
from AlgorithmImports import *
from QuantConnect.DataSource import *
from datetime import datetime, timedelta

class HyperActiveApricotChicken(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2023, 2, 1)
        self.SetEndDate(2023, 3, 10)
        self.SetCash(100000)
        self.tickers_list = [Futures.Grains.SRWWheat, Futures.Indices.SP500EMini]#[Futures.Dairy.ClassIIIMilk, Futures.Energies.CrudeOilWTI, Futures.Energies.HeatingOil, Futures.Energies.NaturalGas, Futures.Energies.Gasoline, Futures.Grains.Corn, Futures.Grains.Soybeans, Futures.Grains.SRWWheat, Futures.Indices.SP500EMini, Futures.Indices.NASDAQ100EMini, Futures.Metals.Gold, Futures.Metals.Copper, 	Futures.Metals.Silver]
        # MILK (DC), CRUDE OIL (LO), HEATING OIL (OH), NATURAL GAS (ON), GASOLINE (OB), CORN (OZC), SOYABEANS (OZS), WHEAR (OZW), SP500EMINI (ES), NAS100EMINI (NQ), GOLD (OG), COPPER (HXE), SILVER (SO)
        self.res = Resolution.Daily
        self.futureSymbols = []  

        self.Debug("1. Initialization started")
        for ticker in self.tickers_list:
            self.Debug(f"2. Subscribing to future: {ticker}")
            future = self.AddFuture(ticker, self.res)
            future.SetFilter(2, 90)
            #future.SetDataNormalizationMode(DataNormalizationMode.Raw)
            self.AddFutureOption(future.Symbol)
            self.futureSymbols.append(future.Symbol.Value) 
            self.Debug(f"3. Future symbol stored: {future.Symbol.Value}")

    def OnData(self, data: Slice):
        self.Debug(f"5. OnData called at {self.Time}")
        self.option_w_OInt_OVol = {}
        volCount = 0
        oiCount = 0

        if data.OptionChains.Count > 0:
            self.Debug(f"6. Processing {data.OptionChains.Count} option chains")
            for optionChain in data.OptionChains.Values:
                underlyingFutureSymbol = optionChain.Symbol.Underlying.Value
                optionChainSymbol = optionChain.Symbol.Value
                self.Debug(f"7. Checking option chain for underlying future symbol: {underlyingFutureSymbol}")
                self.Debug(f"7i. Available option chain symbol: {optionChainSymbol}")

                if underlyingFutureSymbol in optionChainSymbol:
                    self.Debug(f"8. Found matching future symbol: {underlyingFutureSymbol}")
                    for contract in optionChain.Contracts.values():
                        OInt = contract.OpenInterest
                        if OInt>0: oiCount += 1
                        OVol = contract.Volume
                        if OVol>0: volCount += 1
                        if OInt != 0 and OVol != 0: 
                            vol_OI_Ratio = OVol / OInt
                            self.option_w_OInt_OVol[contract.Symbol] = {"OpenInterest": OInt, "Volume": OVol, "Vol_OI_Ratio": vol_OI_Ratio}
                            self.Debug(f"9. Contract added: {contract.Symbol} with OI: {OInt} and Volume: {OVol}")

        self.Debug(f"10. oi count is {oiCount}, vol count is {volCount}")
        sorted_options = sorted(self.option_w_OInt_OVol.items(), key=lambda x: x[1]["Vol_OI_Ratio"], reverse=True)[:1]
        for option in sorted_options:
            self.Debug(f"11. Top option: {option[0].Value} - {option[1]}")