Overall Statistics
Total Trades
7496
Average Win
0.00%
Average Loss
0.00%
Compounding Annual Return
-100.000%
Drawdown
10.400%
Expectancy
-0.827
Net Profit
-10.389%
Sharpe Ratio
-70.785
Loss Rate
90%
Win Rate
10%
Profit-Loss Ratio
0.66
Alpha
-9.024
Beta
-0.226
Annual Standard Deviation
0.128
Annual Variance
0.016
Information Ratio
-68.8
Tracking Error
0.133
Treynor Ratio
39.993
Total Fees
$13867.60
import clr
clr.AddReference("System")
clr.AddReference("QuantConnect.Algorithm")
clr.AddReference("QuantConnect.Common")

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *

class BasicTemplateFuturesAlgorithm(QCAlgorithm):
    ''' This example demonstrates how to add futures for a given underlying.
    It also shows how you can prefilter contracts easily based on expirations.
    It also shows how you can inspect the futures chain to pick a specific contract to trade.'''

    def Initialize(self):
        self.SetStartDate(2016, 8, 17)
        self.SetEndDate(2016, 8, 20)
        self.SetCash(1000000)

        futureSP500 = self.AddFuture(Futures.Indices.SP500EMini)
        futureGold = self.AddFuture(Futures.Metals.Gold)

        # set our expiry filter for this futures chain
        futureSP500.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182))
        futureGold.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182))

        benchmark = self.AddEquity("SPY")
        self.SetBenchmark(benchmark.Symbol)

    def OnData(self, slice):
    	if not self.Portfolio.Invested:
            for chain in slice.FutureChains:
                # find the front contract expiring no earlier than in 90 days
                contracts = [ i for i in chain.Value if i.Expiry > self.Time.Date.AddDays(90) ]
                
                # if thre is more than one contract, trade the one woth the closes expire date
                if len(contracts) > 0:
                    contract = sorted(contracts, key=lambda x: x.Expiry, reverse=True)[0]
                    self.MarketOrder(contract.Symbol, 1);
        else:
            self.Liquidate();

        def OnOrderEvent(self, orderEvent):
            self.Log(orderEvent.ToString())