Overall Statistics
namespace QuantConnect.MeanReversion
{
    public class MeanReversion : QCAlgorithm
    {
    	string symbol = "USDJPY";
        decimal open;
        decimal close;
        QuoteBar Weekly;
        double Return;
        
        string symbol1 = "USDCAD";
        decimal open1;
        decimal close1;
        QuoteBar Weekly1;
        double Return1;
    	
        public override void Initialize() 
        {
            SetStartDate(2016, 1, 1); 
            SetEndDate(2017, 6, 1);

            SetCash(1000);
            SetBrokerageModel(BrokerageName.OandaBrokerage);
            
            AddSecurity(SecurityType.Forex, symbol, Resolution.Daily);
            AddSecurity(SecurityType.Forex, symbol1, Resolution.Daily);
            
			var weeklyConsolidator = new QuoteBarConsolidator(TimeSpan.FromDays(7));
            weeklyConsolidator.DataConsolidated += WeeklyData;
            SubscriptionManager.AddConsolidator(symbol, weeklyConsolidator);
            
            var weeklyConsolidator1 = new QuoteBarConsolidator(TimeSpan.FromDays(7));
            weeklyConsolidator1.DataConsolidated += WeeklyData1;
            SubscriptionManager.AddConsolidator(symbol1, weeklyConsolidator1);
            
        }
        private void WeeklyData(object sender, QuoteBar consolidated)
        {
            	Weekly = consolidated;
            	
            	close = Weekly.Close;
            	open = Weekly.Open;
            	
            	Return = Math.Log(Convert.ToDouble(open)/Convert.ToDouble(close));
        }	
        private void WeeklyData1(object sender, QuoteBar consolidated)
        {
            	Weekly1 = consolidated;
            	
            	close1 = Weekly1.Close;
            	open1 = Weekly1.Open;
            	
            	Return1 = Math.Log(Convert.ToDouble(open1)/Convert.ToDouble(close1));
        }
        public void OnData(QuoteBars data) 
        {
        	var AverageReturn = (Return+Return1)/2;
        	var DemeanedReturn = Return-AverageReturn;
        	var DemeanedReturn1 = Return1-AverageReturn;
        	
        	Schedule.On(DateRules.Every(DayOfWeek.Monday), TimeRules.At(01, 00), () => 
                {
                	if (DemeanedReturn>0)
                	{
                		SetHoldings(symbol, -5, false, "Short " + symbol);
                		SetHoldings(symbol1, 5, false, "Long " + symbol1);
                	}
                	if (DemeanedReturn<0)
                	{
                		SetHoldings(symbol1, -5, false, "Short " + symbol1);
                		SetHoldings(symbol, 5, false, "Long " + symbol);
                	}
                });
            Schedule.On(DateRules.Every(DayOfWeek.Friday), TimeRules.At(16, 00), () => 
                {
                	if (DemeanedReturn>0)
                	{
                		SetHoldings(symbol, 0, false, "Close " + symbol);
                		SetHoldings(symbol1, 0, false, "Close " + symbol1);
                	}
                	if (DemeanedReturn<0)
                	{
                		SetHoldings(symbol1, 0, false, "Close " + symbol1);
                		SetHoldings(symbol, 0, false, "Close " + symbol);
                	}
                });
    	}
    }
}