Overall Statistics
namespace QuantConnect 
{   
    public class BasicTemplateAlgorithm : QCAlgorithm
    {
    	public string[] Symbols = {"XLY","XLP","XLE","XLF","XLV","XLI","XLB","XLK","XLU"}; 
    	private Dictionary<string, double> Elo = new Dictionary<string, double>();
    	private Dictionary<string, RollingWindow<decimal>> Return = new Dictionary<string, RollingWindow<decimal>>();
    	private Dictionary<string, decimal> Price = new Dictionary<string, decimal>();
    	public Dictionary<string, double> StandardDevation = new Dictionary<string, double>();
 
        public override void Initialize() 
        {
            SetStartDate(2000, 1, 1);
            SetEndDate(DateTime.Now);
            SetCash(1000000);
            SetWarmup(250);
            
			foreach (var symbol in Symbols)
			{
				AddSecurity(SecurityType.Equity,symbol,Resolution.Daily);
				Elo[symbol] = 1500;
				Return[symbol] = new RollingWindow<decimal>(50);
				Price[symbol] = 0;
				StandardDevation[symbol] = 0.0;
				Securities[symbol].SetLeverage(10);
			} 
        }
        
        public void OnData(TradeBars data) 
        {
        	foreach (var symbol in Symbols)
        	{
        		if (!data.ContainsKey(symbol)) continue;
        		if (Time.DayOfWeek == DayOfWeek.Thursday)
        		{
        			var K = 2;
        			int C = 200;
        			
        			if (Price[symbol] != 0)
        			{
        				Return[symbol].Add(data[symbol].Close / Price[symbol]);
        			}
        			Price[symbol] = data[symbol].Close;
        			foreach (var sector in Symbols)
        			{
        				if (!Return[symbol].IsReady) continue;  if (!Return[sector].IsReady) continue;
        				StandardDevation[symbol] = Math.Sqrt(Return[symbol].Sum(d => Math.Pow(Convert.ToDouble(d - Return[symbol].Average()), 2)))/(Return[symbol].Count()-1); 
        				if (((double)(Return[symbol][0])/StandardDevation[symbol]) > ((double)(Return[sector][0])/StandardDevation[sector]))
        				{
        					Elo[symbol] = Elo[symbol] + ((K/2)*(1 + (Elo[sector] - Elo[symbol])/(C*2)));
        				}
        				if (((double)(Return[symbol][0])/StandardDevation[symbol]) < ((double)(Return[sector][0])/StandardDevation[sector]))
        				{
        					Elo[symbol] = Elo[symbol] + ((K/2)*(-1 + (Elo[sector] - Elo[symbol])/(C*2)));
        				}
        			}
        		}
        	}
        	string max = Elo.Aggregate((l, r) => l.Value > r.Value ? l : r).Key;
        	string min = Elo.Aggregate((l, r) => l.Value < r.Value ? l : r).Key;
        	
        	if (Time.DayOfWeek == DayOfWeek.Thursday)
        	{
        		foreach (var symbol in Symbols)
        		{
        			if (Portfolio[symbol].IsLong && symbol != max)
        			{
        				SetHoldings(symbol, 0, false);
        			}
        			if (Portfolio[symbol].IsShort && symbol != min)
        			{
        				SetHoldings(symbol, 0, false);
        			}
        			Plot("Elo's ", "Elo " + symbol, Elo[symbol]);
        		}
        		var Ea = 1/(1 + Math.Pow(10,(Elo[min]-Elo[max])/400));
        		var Eb = 1 - Ea;
        		var weight = (double)((Ea-Eb));
        		
        		var Ratio = (StandardDevation[max]/StandardDevation[min])+1;
        		var maxweight = (weight/Ratio);
        		if (Elo[max] != 1500 && Elo[min] != 1500 && Elo[max] != Elo[min] && !Portfolio[max].IsLong)
        		{
        			SetHoldings(max, (float)maxweight, false, "Long " + max + " Elo is " + Math.Round(Elo[max],2) + " Odds are " + Math.Round(Ea,2));
        		}
        		if (Elo[max] != 1500 && Elo[min] != 1500 && Elo[max] != Elo[min] && !Portfolio[min].IsShort)
        		{
        			SetHoldings(min, (float)-(weight-maxweight), false, "Short " + min + " Elo is " + Math.Round(Elo[min],2));
        		}
        	}
        }
    }
}