Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
-98.830%
Drawdown
5.300%
Expectancy
0
Net Profit
-4.757%
Sharpe Ratio
-15.896
Probabilistic Sharpe Ratio
0%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.916
Beta
-0.609
Annual Standard Deviation
0.034
Annual Variance
0.001
Information Ratio
0.815
Tracking Error
0.09
Treynor Ratio
0.889
Total Fees
$1.85
class DynamicCalibratedContainmentField(QCAlgorithm):
    
    

    def Initialize(self):
        self.SetStartDate(2019, 3, 3)  # Set Start Date
        self.SetEndDate(2019, 3, 6)   # Set End Date
        self.SetCash(50000) 

        futureES = self.AddFuture("ES", Resolution.Tick)
        futureES.SetFilter(lambda x : x.FrontMonth())
        
        self.frontContract = None
        
        self.sma = SimpleMovingAverage(2)
        
        self.consolidator = TickQuoteBarConsolidator(timedelta(minutes=1))
        self.consolidator.DataConsolidated += self.OnMinuteData
        
    def OnData(self, data):
        
         # Get front month symbol
        for chain in data.FutureChains:
           
            contracts = [contract for contract in chain.Value]
         
            current_contract = contracts[0]
            
            # Handle new contracts
            if self.frontContract is None or self.frontContract.Symbol != current_contract.Symbol:
                
                self.frontContract = current_contract
                
                self.Debug(f"New Front Month Contract {self.frontContract.Symbol} {self.Time}")
                
                # Update consolidator
                self.consolidator.DataConsolidated -= self.OnMinuteData
                
                self.consolidated = TickQuoteBarConsolidator(timedelta(minutes=1))
                
                self.consolidator.DataConsolidated += self.OnMinuteData
                
            
            ticks = chain.Value.Ticks
            
            symbol = self.frontContract.Symbol
            
            if symbol in ticks.Keys:
                for tick in ticks[symbol]:
                    self.consolidator.Update(tick)
        
            # If I am not currently invested then go long
            if not self.Portfolio.Invested:
                self.MarketOrder(self.frontContract.Symbol, 1)
   
    def OnMinuteData(self, sender, bar):
        self.sma.Update(self.Time, bar.Close)
        
        if self.sma.IsReady:
            self.Debug(f"{self.Time} - {self.frontContract.Symbol}, SMA: {self.sma.Current.Value}")