Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
153.758%
Drawdown
1.600%
Expectancy
0
Net Profit
1.284%
Sharpe Ratio
4.405
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.706
Beta
-0.744
Annual Standard Deviation
0.123
Annual Variance
0.015
Information Ratio
1.753
Tracking Error
0.184
Treynor Ratio
-0.73
Total Fees
$18.50
namespace Test
{
    public class TestAlgo : QCAlgorithm
    {
    	public RollingWindow<decimal> BidPrices = new RollingWindow<decimal>(4);
        public RollingWindow<decimal> AskPrices = new RollingWindow<decimal>(4);
        public RollingWindow<decimal> Volumes = new RollingWindow<decimal>(4);
		
        public override void Initialize() 
        {
            SetStartDate(2019, 09, 01);
            SetEndDate(DateTime.Now);
            SetCash(1000000);
            
            var futureSP500 = AddFuture(Futures.Indices.SP500EMini);
            futureSP500.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
			
			var benchmark = AddEquity("SPY");
            SetBenchmark(benchmark.Symbol);
        }
        
        public override void OnData(Slice slice)
        {
        	if (!Portfolio.Invested)
            {
                foreach (var chain in slice.FutureChains)
                {
                    // find the front contract expiring no earlier than in 90 days
                    var contract = (
                        from futuresContract in chain.Value.OrderBy(x => x.Expiry)
                        where futuresContract.Expiry > Time.Date.AddDays(90)
                        select futuresContract
                    ).FirstOrDefault();

                    // if found, perform logic
                    if (contract != null)
                    {
                    	BidPrices.Add(contract.BidPrice);
				        AskPrices.Add(contract.AskPrice);
				        Volumes.Add(contract.Volume);
				        
				        // This check is needed to prevent errors from accessing entries that do not exist
				        if (!BidPrices.IsReady || !AskPrices.IsReady || !Volumes.IsReady)
				        	continue;
				        
				        var Long = BidPrices[0] > AskPrices[1];
				        	
			        	if (Long)
							MarketOrder(contract.Symbol, 10);
                    }
                }
            }
        }
    }
}