Overall Statistics
Total Trades
123
Average Win
0.69%
Average Loss
-0.55%
Compounding Annual Return
19.835%
Drawdown
4.600%
Expectancy
0.188
Net Profit
7.116%
Sharpe Ratio
1.944
Probabilistic Sharpe Ratio
70.465%
Loss Rate
48%
Win Rate
52%
Profit-Loss Ratio
1.26
Alpha
0.106
Beta
0.337
Annual Standard Deviation
0.082
Annual Variance
0.007
Information Ratio
0.03
Tracking Error
0.09
Treynor Ratio
0.472
Total Fees
$455.10
class UncoupledVentralPrism(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2017, 1, 1)
        self.SetEndDate(2017, 5, 19)
        self.SetCash(100000)
        
        equity = self.AddEquity("SPY")
        future = self.AddFuture(Futures.Indices.SP500EMini)
        future.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(60))
        
        self.sma5 = self.SMA(equity.Symbol, 5)
        self.sma9 = self.SMA(equity.Symbol, 9)
        
        self.Schedule.On(self.DateRules.EveryDay("SPY"), \
                         self.TimeRules.AfterMarketOpen(equity.Symbol, 10), \
                         self.Trade)


    def Trade(self):
        if self.Portfolio.Invested:
            return
        
        for chain in self.CurrentSlice.FutureChains:
            contracts = [contract for contract in chain.Value if contract.Expiry > self.Time + timedelta(days=5)]
            sorted_contracts = sorted(contracts, key=lambda x: x.Expiry)
            if len(sorted_contracts) == 0:
                continue
            contract = sorted_contracts[0]
            quantity = 2 if self.sma5 > self.sma9 else -2
            self.MarketOrder(contract.Symbol, quantity)
            
    def OnEndOfDay(self):
        self.Liquidate()