Overall Statistics
Total Trades
44
Average Win
0%
Average Loss
0%
Compounding Annual Return
473.071%
Drawdown
5.100%
Expectancy
0
Net Profit
4.899%
Sharpe Ratio
11.477
Probabilistic Sharpe Ratio
70.044%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
1.643
Beta
2.116
Annual Standard Deviation
0.493
Annual Variance
0.243
Information Ratio
8.523
Tracking Error
0.441
Treynor Ratio
2.673
Total Fees
$81.40
Estimated Strategy Capacity
$19000000.00
from datetime import datetime, timedelta

from QuantConnect.Algorithm import *
from QuantConnect.Data import *
from QuantConnect import *


class WTICrudeOilFuturesOptionsChainProviderAlgorithm(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2020, 5, 1)
        self.SetEndDate(2020, 5, 10)
        self.SetCash(1000000)

        # METHOD 2 -- using the OptionChainProvider
        #
        # This method should ideally only be used when you are dealing
        # with single futures contracts that have not had their option chain
        # loaded. The OptionChainProvider will return a list of all options
        # tradable for the future contract at a given date.
        #
        # ---------------------------
        # 
        # We need to add a specific future contract first, since 
        # the OptionChainProvider expects a specific future contract.
        cln20 = Symbol.CreateFuture("CL", Market.NYMEX, datetime(2020, 6, 22))
        cln20 = self.AddFutureContract(cln20, Resolution.Minute).Symbol

        # Loads all Futures Options contracts on 2020-05-01 for CLN20.
        # Note that this result will not be updated as the algorithm progresses.
        allContractsCLN20 = self.OptionChainProvider.GetOptionContractList(cln20, self.Time)

        # We can add the contracts here, but once they expire, no more new contracts
        # will be added to the algorithm, unless we do all of this again.
        for clOptionContract in allContractsCLN20:
            self.AddFutureOptionContract(clOptionContract, Resolution.Minute)

    def FilterFutureOptionContract(self, filterUniverse):
        return filterUniverse.Strikes(-5, +5)

    def OnData(self, data):
        if self.Portfolio.Invested:
            return

        # Loop through all futures options contracts that were loaded.
        # We long calls, and short the puts that were loaded.
        for chain in data.OptionChains.Values:
            for contract in chain.Contracts.Values:
                # The contract's strike, right, and style can all be accessed
                # from the `Symbol` object as well, if you don't have access
                # to the `OptionContract` object. 
                #
                #   strike: contract.Symbol.ID.StrikePrice
                #   right:  contract.Symbol.ID.OptionRight
                #   style:  contract.Symbol.ID.OptionStyle
                #
                if contract.Right == OptionRight.Call:
                    # Buy 1 CL call contract
                    self.MarketOrder(contract.Symbol, 1)
                else:
                    # Short 1 CL put contract
                    self.MarketOrder(contract.Symbol, -1)