Overall Statistics
Total Trades
147
Average Win
0.61%
Average Loss
-0.71%
Compounding Annual Return
4.206%
Drawdown
9.100%
Expectancy
0.070
Net Profit
1.577%
Sharpe Ratio
0.359
Probabilistic Sharpe Ratio
32.721%
Loss Rate
42%
Win Rate
58%
Profit-Loss Ratio
0.86
Alpha
0.057
Beta
-0.11
Annual Standard Deviation
0.11
Annual Variance
0.012
Information Ratio
-0.892
Tracking Error
0.131
Treynor Ratio
-0.36
Total Fees
$543.90
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)


    def OnData(self, data):
        if self.Portfolio.Invested:
            return
        
        for chain in data.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()