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
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
1.793
Tracking Error
0.157
Treynor Ratio
0
Total Fees
$0.00
import typing
from QuantConnect.Securities.Future import Future


class AdvancedCopulaMethod(QCAlgorithm):
    consolidator_by_symbol = {}

    def Initialize(self):
        self.SetStartDate(2020, 1, 1)
        self.SetEndDate(2020, 3, 1)
        self.SetCash(1000000)
        universe: typing.Dict[str, Future] = {s: self.AddFuture(s, Resolution.Minute) for s in self.tickers}
        [future.SetFilter(timedelta(0), timedelta(180)) for future in universe.values()]

    def OnData(self, data: Slice):
        for chain in data.FutureChains.Values:
            contracts = chain.Contracts
            if len(contracts) == 0:
                continue
            sorted_by_oi_contracts = sorted(contracts.Values, key=lambda k: k.OpenInterest, reverse=True)
            popular_contracts = sorted_by_oi_contracts[:3]
                   
            # Comment out the following 3 lines to disable consolidation
            for contract in popular_contracts:
                if contract.Symbol not in self.consolidator_by_symbol:
                    self.consolidate_future(contract)
                    
    def consolidate_future(self, contract):
        dailyConsolidator = TradeBarConsolidator(timedelta(days=1))
        dailyConsolidator.DataConsolidated += self.DailyHandler
        self.SubscriptionManager.AddConsolidator(contract.Symbol, dailyConsolidator)
        self.consolidator_by_symbol[contract.Symbol] = dailyConsolidator

    def DailyHandler(self, sender: DataConsolidator, bar: TradeBar):
        pass

    @property
    def tickers(self):
        indices = [
            Futures.Indices.SP500EMini,
            Futures.Indices.SP400MidCapEmini,
            Futures.Indices.Dow30EMini,
            Futures.Indices.Russell2000EMini,

            Futures.Indices.Nikkei225Dollar,
            Futures.Indices.USDDenominatedIbovespa,

            Futures.Indices.SPGSCICommodity,
            Futures.Indices.BloombergCommodityIndex,

            Futures.Indices.VIX,
        ]

        metals = [
            Futures.Metals.Gold,
            Futures.Metals.Silver,
            Futures.Metals.Platinum,
            Futures.Metals.Palladium,
            Futures.Metals.Copper,
        ]

        grains = [
            Futures.Grains.Wheat,
            Futures.Grains.Corn,
            Futures.Grains.Soybeans,
            Futures.Grains.Oats,
        ]

        tickers = indices + metals + grains

        return tickers