Overall Statistics
Total Trades
5
Average Win
13.26%
Average Loss
0%
Compounding Annual Return
-2.156%
Drawdown
44.600%
Expectancy
0
Net Profit
-1.075%
Sharpe Ratio
0.963
Probabilistic Sharpe Ratio
38.309%
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
0.999
Beta
10.596
Annual Standard Deviation
1.302
Annual Variance
1.696
Information Ratio
1.018
Tracking Error
1.208
Treynor Ratio
0.118
Total Fees
$1028.60
class FuturesAlgo(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2015, 1, 1) 
        self.SetEndDate(2015, 6, 30) 
        self.SetCash(1000000)
        self.es = self.AddFuture(Futures.Indices.SP500EMini)
        # Filter contracts to only front month contract
        self.es.SetFilter(lambda x : x.FrontMonth())
        # 5 period SMA
        self.ema = ExponentialMovingAverage(200)
        # Pointer to track front month contract
        self.frontmonthContract = None
        
    def OnData(self, data):
      
        for chain in data.FutureChains:
            # Trades bars for contracts in chain
            tradebars = chain.Value.TradeBars
            
            contracts = [contract for contract in chain.Value]
            
            # If front month contract is updated
            if self.frontmonthContract == None or contracts[0].Symbol != self.frontmonthContract.Symbol:
                # contracts has only 1 element, the front month contract
                self.frontmonthContract = contracts[0]
            
            symbol = self.frontmonthContract.Symbol
            # Update SMA with tradebar data
            price = 0
            if symbol in tradebars.Keys:   
                tradebar = tradebars[symbol]
                price = tradebar.Close
                self.ema.Update(tradebar.EndTime, tradebar.Close)
           
            if self.ema.IsReady:
                if not self.Portfolio.Invested:
                    if price != 0 and price > self.ema.Current.Value:
                        self.SetHoldings(self.frontmonthContract.Symbol, 0.5)
                        self.Debug(f"Symbol: {symbol}, Expiry: {self.frontmonthContract.Expiry}, SMA: {self.ema.Current.Value}")