Overall Statistics
Total Trades
24
Average Win
1.18%
Average Loss
-0.63%
Compounding Annual Return
166.763%
Drawdown
3.100%
Expectancy
1.171
Net Profit
8.898%
Sharpe Ratio
5.504
Probabilistic Sharpe Ratio
88.603%
Loss Rate
25%
Win Rate
75%
Profit-Loss Ratio
1.89
Alpha
0.697
Beta
-0.304
Annual Standard Deviation
0.14
Annual Variance
0.02
Information Ratio
6.509
Tracking Error
0.154
Treynor Ratio
-2.532
Total Fees
$0.00
Estimated Strategy Capacity
$7200000.00
Lowest Capacity Asset
USDCAD 8G
class Futures_CSV(QCAlgorithm):

    def Initialize(self):
        self.SetCash(100000)
        self.SetStartDate(2021, 6, 1)
        self.SetTimeZone('America/New_York')
        
        #CAD Futureshttps://www.quantconnect.com/project/8692527#
        self.symbol = self.AddData(Difference, "Difference", Resolution.Minute).Symbol
        
        self.SetBrokerageModel(BrokerageName.OandaBrokerage)
        
        self.AddForex("USDCAD", Resolution.Minute, Market.Oanda)
        

    def OnData(self, data):
        if data.ContainsKey(self.symbol):
            self.Plot("Difference", "CLOSE", data[self.symbol].GetProperty('CLOSE'))
        
            #Entry
            if data[self.symbol].Value <= -0.0015 and not self.Portfolio.Invested:
                    self.SetHoldings("USDCAD", -10)  
            elif data[self.symbol].Value >= 0.0015 and not self.Portfolio.Invested:
                    self.SetHoldings("USDCAD", 10) 
            else:
                pass
             
                
            #Exit
            if self.Portfolio["USDCAD"].IsLong and data[self.symbol].Value <= 0:
                    self.Liquidate()
            elif self.Portfolio["USDCAD"].IsShort and data[self.symbol].Value >= 0:
                    self.Liquidate()
            else:
                pass  
          
 
class Difference(PythonData):

    def GetSource(self, config, date, isLive):
        source = "https://raw.githubusercontent.com/LeonidNID/Quantconnect/master/Difference_MINUTES_SHORTENED.csv"
        return SubscriptionDataSource(source, SubscriptionTransportMedium.RemoteFile);


    def Reader(self, config, line, date, isLive):
        # If first character is not digit, pass
        if not (line.strip() and line[0].isdigit()): return None

        data = line.split(',')
        difference = Difference()
        difference.Symbol = config.Symbol
        difference.Time = datetime.strptime(data[1], '%Y-%m-%dT%H:%M:%S')
        difference.Value = float(data[2])
        difference["CLOSE"] = float(data[2])
        
        return difference