Overall Statistics
Total Trades
288
Average Win
4.61%
Average Loss
-4.95%
Compounding Annual Return
-67.551%
Drawdown
79.900%
Expectancy
-0.169
Net Profit
-79.805%
Sharpe Ratio
-1.329
Loss Rate
57%
Win Rate
43%
Profit-Loss Ratio
0.93
Alpha
-0.666
Beta
0.131
Annual Standard Deviation
0.492
Annual Variance
0.242
Information Ratio
-1.492
Tracking Error
0.499
Treynor Ratio
-4.985
Total Fees
$0.00
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);
                	}
                });
    	}
    }
}