Overall Statistics
Total Trades
219
Average Win
4.54%
Average Loss
-4.34%
Compounding Annual Return
0%
Drawdown
100.200%
Expectancy
-0.246
Net Profit
-100.219%
Sharpe Ratio
0.729
Probabilistic Sharpe Ratio
35.867%
Loss Rate
63%
Win Rate
37%
Profit-Loss Ratio
1.05
Alpha
4.28
Beta
0.076
Annual Standard Deviation
5.828
Annual Variance
33.968
Information Ratio
0.793
Tracking Error
5.838
Treynor Ratio
55.794
Total Fees
$0.00
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Indicators")
AddReference("QuantConnect.Common")
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
import numpy as np
from datetime import timedelta, datetime
import decimal

class RegressionChannelAlgorithm(QCAlgorithm):

    def Initialize(self):

        self.SetCash(1000)
        self.SetStartDate(2008,4,9)
        #self.SetEndDate(2019,4,9)
        self.symbols = ["EURNZD", "USDCAD", "NZDUSD", "CADSGD", "GBPCHF", "EURGBP"]
        slowperiod = 240
        self.SetWarmUp(slowperiod)
        for symbol in self.symbols:
            equity = self.AddForex(symbol, Resolution.Hour, Market.Oanda)
            self._spy = equity.Symbol
            #self._holdings = equity.Holdings
        self.ema1 = self.EMA("USDCAD", 10, Resolution.Daily) #[1],[3]
        self.ema2 = self.EMA("CADSGD", 10, Resolution.Daily)
        self.sma1 = IndicatorExtensions.Minus(self.ema1, self.ema2) 
        
        self.ema3 = self.EMA("EURNZD", 10, Resolution.Daily) #[0].[2]
        self.ema4 = self.EMA("NZDUSD", 10, Resolution.Daily)
        self.sma2 = IndicatorExtensions.Minus(self.ema3, self.ema4)
        
        self.ema5 = self.EMA("GBPCHF", 50, Resolution.Hour) #[4],[5]
        self.ema6 = self.EMA("EURGBP", 50, Resolution.Hour)
        self.sma3 = IndicatorExtensions.Minus(self.ema5, self.ema6)
        
        '''
        stockPlot = Chart("Trade Plot")
        stockPlot.AddSeries(Series("Buy", SeriesType.Scatter, 0)) 
        stockPlot.AddSeries(Series("Sell", SeriesType.Scatter, 0))
        stockPlot.AddSeries(Series("MinusSMA1", SeriesType.Line, 0))
        stockPlot.AddSeries(Series("lavern3", SeriesType.Line, 0))
        self.AddChart(stockPlot)
        '''
    def OnData(self, data):
        if self.IsWarmingUp: return
        if (not self.ema1.IsReady) or (not data.ContainsKey(self.symbols[0])) or (not data.ContainsKey(self.symbols[1])): return
        if (not self.ema2.IsReady) or ( not self.ema3.IsReady) or ( not self.ema4.IsReady) or ( not self.ema5.IsReady) or ( not self.ema6.IsReady): return 
        
        tolerance = decimal.Decimal(0.0100)
        tolerance2 = decimal.Decimal(0.0175)
        tolerance3 = decimal.Decimal(0.0070)
        lavern = (self.Securities["USDCAD"].Price - self.Securities["CADSGD"].Price)
        lavern2 = (self.Securities["EURNZD"].Price - self.Securities["NZDUSD"].Price)
        lavern3 = (self.Securities["GBPCHF"].Price - self.Securities["EURGBP"].Price)
        
        if not self.Portfolio[self.symbols[1]].Invested and lavern <= (self.sma1.Current.Value - tolerance):
            self.MarketOrder(self.symbols[1], 3000)
            self.MarketOrder(self.symbols[3], -3000)
            self.Plot("Trade Plot", "Buy", lavern)
        if self.Portfolio[self.symbols[1]].Invested and lavern >= (self.sma1.Current.Value + tolerance):
            self.MarketOrder(self.symbols[1], -3000)
            self.MarketOrder(self.symbols[3], 3000)
            self.Plot("Trade Plot", "Sell", lavern)
        
        if not self.Portfolio[self.symbols[0]].Invested and lavern2 <= (self.sma2.Current.Value - tolerance2):
            self.MarketOrder(self.symbols[0], -3000)
            self.MarketOrder(self.symbols[2], 3000)
            self.Plot("Trade Plot", "Buy", lavern2)
        if not self.Portfolio[self.symbols[0]].Invested and lavern2 >= (self.sma2.Current.Value + tolerance2):
            self.MarketOrder(self.symbols[0], 3000)
            self.MarketOrder(self.symbols[2], -3000)
            self.Plot("Trade Plot", "Sell", lavern2)
        if self.Portfolio[self.symbols[0]].Invested:
            if (self.sma2.Current.Value + 0.0005) >= lavern2 >= (self.sma2.Current.Value - 0.0005):
                self.Liquidate(self.symbols[0])
                self.Liquidate(self.symbols[2])
        self.Log("Unsettled Cash is: " + str(self.Portfolio.Cash))
        '''
        if not self.Portfolio[self.symbols[4]].Invested and lavern3 <= (self.sma3.Current.Value - tolerance3):
            self.MarketOrder(self.symbols[4], -3000)
            self.MarketOrder(self.symbols[5], 3000)
            self.Plot("Trade Plot", "Buy", lavern3)
        if not self.Portfolio[self.symbols[4]].Invested and lavern3 >= (self.sma3.Current.Value + tolerance3):
            self.MarketOrder(self.symbols[4], 3000)
            self.MarketOrder(self.symbols[5], -3000)
            self.Plot("Trade Plot", "Sell", lavern3)
        if self.Portfolio[self.symbols[4]].Invested:
            if (self.sma3.Current.Value + 0.0015) >= lavern3 >= (self.sma3.Current.Value - 0.0015):
                self.Liquidate(self.symbols[4])
                self.Liquidate(self.symbols[5])
        '''
        '''
        
        self.Plot("Trade Plot", "MinusSMA1", self.sma3.Current.Value)
        self.Plot("Trade Plot", "lavern3", lavern3)
        '''
    def OnEndOfDay(self):
        '''
        USD/CAD
        CAD/SGD
        
        EUR/GBP    0.05    -0.92    -0.91    -0.80    -0.91    -0.73    -0.46
        GBP/CHF    -0.43    -0.87    -0.92    -0.69    -0.92    -0.94    -0.69
        
        EUR/NZD    -0.59    -0.85    -0.88    -0.83    -0.67    -0.80    -0.69
        NZD/USD    -0.59    -0.85    -0.88    -0.83    -0.67    -0.80    -0.69
        self.Plot("Trade Plot", "USDCAD", self.Securities["USDCAD"].Price)
        #self.Plot("Trade Plot", "GBPAUD", self.Securities["GBPAUD"].Price)
        #if data[self._spy] is None: return
        #value = data[self.symbols[0]].Value
        '''