Overall Statistics
Total Trades
24
Average Win
0%
Average Loss
0%
Compounding Annual Return
4.864%
Drawdown
11.100%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0.59
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.028
Beta
0.61
Annual Standard Deviation
0.086
Annual Variance
0.007
Information Ratio
-1.274
Tracking Error
0.061
Treynor Ratio
0.083
Total Fees
$24.00
namespace QuantConnect 
{   
    public class BasicTemplateAlgorithm : QCAlgorithm
    {
    	private DateTime nextDate;
    	private int period = 61;
    	private decimal targetTradeVolume = 1000m;
    	
        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.Minute);
            
            nextDate = StartDate.AddDays(-1);
        }

        public void OnData(TradeBars data) 
        {   
            if (Time > nextDate) 
            {   
            	nextDate = nextDate.AddDays(period);
            	
            	var price = data["SPY"].Price;
            	var minTradeQuantity = 1 + (int)(targetTradeVolume / price);
            	
            	var quantity = 1;
            	
            	quantity = Math.Max(quantity, minTradeQuantity);
            	
            	// Do not add to the position if less than target volume
            	var volume = quantity * price;
            	if (volume < targetTradeVolume) return;
            	
                //Order function places trades: enter the string symbol and the quantity you want:
                Order("SPY",  quantity);
                
                //Debug sends messages to the user console: "Time" is the algorithm time keeper object 
                Debug(string.Format("{0} -> Purchased {1} shares of SPY at ${2}. Trade Volume: ${3}", 
                    Time.ToShortDateString(), 
                    quantity, 
                    price.ToString("0.00"), 
                    volume.ToString("0.00")));
                
            }
        }
    }
}