Overall Statistics
namespace QuantConnect 
{   
    /*
    *   QuantConnect University: Full Basic Template:
    *
    *   The underlying QCAlgorithm class is full of helper methods which enable you to use QuantConnect.
    *   We have explained some of these here, but the full algorithm can be found at:
    *   https://github.com/QuantConnect/QCAlgorithm/blob/master/QuantConnect.Algorithm/QCAlgorithm.cs
    */
    public class BasicTemplateAlgorithm : QCAlgorithm
    {
        
        RollingWindow<TradeBar> history = new RollingWindow<TradeBar>(5);
        DateTime lastTrade = new DateTime();
        
        public override void Initialize()
        {
			
            //Start and End Date range for the backtest:
            SetStartDate(2013, 1, 1);         
            SetEndDate(DateTime.Now.Date.AddDays(-1)); 
            
            //Cash allocation
            SetCash(25000);
            
            //Add as many securities as you like. All the data will be passed into the event handler:
            AddSecurity(SecurityType.Equity, "SPY", Resolution.Daily);
        }

        //Data Event Handler: New data arrives here. "TradeBars" type is a dictionary of strings so you can access it by symbol.
        public void OnData(TradeBars data) 
        {   
            history.Add(data["SPY"]);
            
            if (history.IsReady && Time > lastTrade.AddDays(5))
            {
                var delta = history[0].Close - history.MostRecentlyRemoved.Close;
                
                var relative = delta / data["SPY"].Close;
                
                SetHoldings("SPY", 0.5m + relative);
                lastTrade = Time;
            }
        }
    }
}