Overall Statistics
Total Trades
4
Average Win
4.5%
Average Loss
0%
Compounding Annual Return
40.358%
Drawdown
17.300%
Expectancy
0
Net Profit
128.357%
Sharpe Ratio
1.415
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
-0.038
Beta
2.279
Annual Standard Deviation
0.265
Annual Variance
0.07
Information Ratio
1.237
Tracking Error
0.157
Treynor Ratio
0.164
Total Fees
$76.00
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;
            }
        }
    }
}