Overall Statistics
Total Trades
230
Average Win
0.16%
Average Loss
-0.08%
Compounding Annual Return
10.570%
Drawdown
26.000%
Expectancy
1.556
Net Profit
46.856%
Sharpe Ratio
0.647
Loss Rate
16%
Win Rate
84%
Profit-Loss Ratio
2.03
Alpha
-0.023
Beta
1.051
Annual Standard Deviation
0.143
Annual Variance
0.02
Information Ratio
-0.246
Tracking Error
0.069
Treynor Ratio
0.088
Total Fees
$485.18
namespace QuantConnect 
{   
    /*
        I want to implement a 1/N algorithm where you distribute the funds available
        ( say $1,000,000) in buying the stocks (some 100 different varieties, so every
        stock should have $10,000 worth
    */
    public class RebalancingWith1NAlgorithm : QCAlgorithm
    {
    	private int _lastMonth = -1;
    	
        //Initialize the data and resolution you require for your strategy:
        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(1000000);
            
            //Add as many securities as you like. All the data will be passed into the event handler:
            AddSecurity(SecurityType.Equity, "SPY", Resolution.Daily);
            AddSecurity(SecurityType.Equity, "AAPL", Resolution.Daily);
            AddSecurity(SecurityType.Equity, "AIG", Resolution.Daily);
            AddSecurity(SecurityType.Equity, "BAC", Resolution.Daily);
            AddSecurity(SecurityType.Equity, "IBM", 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) 
        {   
        	// If not a new month, return
        	if(_lastMonth == Time.Month) return;
        	
        	// 1/N 
        	var weighting = 1m / Securities.Count;
			foreach(var security in Securities.Values)
			{
    			SetHoldings(security.Symbol, weighting);
			}
			
        	_lastMonth = Time.Month;
        	
        }
    }
}