Overall Statistics
Total Trades
306
Average Win
9.50%
Average Loss
-8.61%
Compounding Annual Return
-95.717%
Drawdown
93.700%
Expectancy
-0.054
Net Profit
-83.910%
Sharpe Ratio
-0.273
Probabilistic Sharpe Ratio
10.427%
Loss Rate
55%
Win Rate
45%
Profit-Loss Ratio
1.10
Alpha
-0.59
Beta
2.808
Annual Standard Deviation
1.69
Annual Variance
2.855
Information Ratio
-0.302
Tracking Error
1.676
Treynor Ratio
-0.164
Total Fees
$2334.70
Estimated Strategy Capacity
$180000000.00
Lowest Capacity Asset
NQ W3ZT7JIZT81T
import datetime

class CalmMagentaSnake(QCAlgorithm):
    
    #openPeriod = 0
    #closePeriod = 0

    def Initialize(self):
        #set timezone to ET
        self.SetTimeZone("America/New_York")
        
        self.openPeriod = 0
        self.closePeriod = 0
        
        #algo basics
        self.SetStartDate(2015, 1, 1)
        #self.SetEndDate(2021, 12, 31)
        self.SetEndDate(2015, 7, 31)
        self.SetCash(100000)
        
        #add NASDAQ100 Emini future security object and filter to frontmonth only 
        self.NQ = self.AddFuture(Futures.Indices.NASDAQ100EMini, Resolution.Minute)
        self.NQ.SetFilter(timedelta(0), timedelta(90))
        
        self.front_NQ = None
    
        #close out all open positions at market close
        self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.BeforeMarketClose(self.NQ.Symbol, 0), self.ClosePositions)

    def OnData(self, data):
        #filter for specific future contract data object
        for chain in data.FutureChains.Values:
            if self.front_NQ is None or ((self.front_NQ.Expiry-self.Time).days <= 1):
                contracts = list(filter(lambda x: x.Expiry >= self.Time + timedelta(days = 10), chain.Contracts.Values))
                self.front_NQ = sorted(contracts, key = lambda x: x.Expiry)[0]
                #self.front_NQ = self.front_NQ.Symbol
        
        if self.front_NQ is None:
            return
        
        now = self.Time
        
        if now.hour == 9 and now.minute == 31:
            self.closePeriod = self.Securities[self.front_NQ.Symbol].Close
        
        if now.hour == 16 and now.minute == 00:
            self.openPeriod = self.Securities[self.front_NQ.Symbol].Open
            
        if self.closePeriod == 0 or self.openPeriod == 0:
            return
    
        change = (self.closePeriod - self.openPeriod) / self.openPeriod

        if now.hour == 9 and now.minute == 32 and change >= 0:
            self.SetHoldings(self.front_NQ.Symbol, 1)
        elif now.hour == 9 and now.minute == 32 and change < 0:
            self.SetHoldings(self.front_NQ.Symbol, -1)
        
    def ClosePositions(self):
        self.Liquidate()