Overall Statistics
Total Trades
5
Average Win
0.40%
Average Loss
0%
Compounding Annual Return
-2.210%
Drawdown
3.700%
Expectancy
0
Net Profit
-2.605%
Sharpe Ratio
-1.152
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
-0.022
Beta
0.027
Annual Standard Deviation
0.015
Annual Variance
0
Information Ratio
-1.794
Tracking Error
0.095
Treynor Ratio
-0.652
Total Fees
$9.25
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Securities import *
from datetime import timedelta

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(2013, 10, 07)
        self.SetEndDate(2014, 12, 11)
        self.SetCash(1000000)

        # Subscribe and set our expiry filter for the futures chain
        # futureES = self.AddFuture(Futures.Indices.SP500EMini)
        # futureES.SetFilter(timedelta(0), timedelta(182))
        
        # futureGC = self.AddFuture(Futures.Metals.Gold)        
        # futureGC.SetFilter(timedelta(0), timedelta(182))
        # self.Log("What is this {0}".format(Futures.Metals.Gold))
        
       	futureCL = self.AddFuture("CL")        
        futureCL.SetFilter(timedelta(0), timedelta(182))
        

    def OnData(self,slice):
        if not self.Portfolio.Invested:
            for chain in slice.FutureChains:           
                 # Get contracts expiring no earlier than in 90 days
                contracts = filter(lambda x: x.Expiry > self.Time + timedelta(90), chain.Value)
                
                # if there is any contract, trade the front contract
                if len(contracts) == 0: continue            
                front = sorted(contracts, key = lambda x: x.Expiry, reverse=True)[0]
                self.MarketOrder(front.Symbol , 1)
        # else:
        #     self.Liquidate()


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