Overall Statistics Total Trades7496Average Win0.00%Average Loss0.00%Compounding Annual Return-100.000%Drawdown10.400%Expectancy-0.827Net Profit-10.389%Sharpe Ratio-70.785Loss Rate90%Win Rate10%Profit-Loss Ratio0.66Alpha-9.024Beta-0.226Annual Standard Deviation0.128Annual Variance0.016Information Ratio-68.8Tracking Error0.133Treynor Ratio39.993Total Fees\$13867.60
```import clr

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)

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

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())```