Overall Statistics
Total Orders
15
Average Win
0%
Average Loss
0%
Compounding Annual Return
2.962%
Drawdown
5.700%
Expectancy
0
Start Equity
25000
End Equity
33407.78
Net Profit
33.631%
Sharpe Ratio
0.085
Sortino Ratio
0.122
Probabilistic Sharpe Ratio
16.328%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.009
Beta
-0.08
Annual Standard Deviation
0.028
Annual Variance
0.001
Information Ratio
-0.488
Tracking Error
0.159
Treynor Ratio
-0.029
Total Fees
$0.00
Estimated Strategy Capacity
$2400000.00
Lowest Capacity Asset
USDTRY 8G
Portfolio Turnover
0.03%
# region imports
from AlgorithmImports import *
# endregion

class ForexCarryTradeAlgorithm(QCAlgorithm):

    def Initialize(self):

        self.SetStartDate(2014, 5, 1) 
        self.SetEndDate(2024, 4, 1)  
        self.SetCash(25000)
        
        rate_symbol_by_ticker = {
            "USDEUR": "BCB/17900",  # Euro Area
            "USDZAR": "BCB/17906",  # South Africa
            "USDAUD": "BCB/17880",  # Australia
            "USDJPY": "BCB/17903",  # Japan
            "USDTRY": "BCB/17907",  # Turkey
            "USDINR": "BCB/17901",  # India
            "USDCNY": "BCB/17899",  # China
            "USDMXN": "BCB/17904",  # Mexico
            "USDCAD": "BCB/17881"   # Canada
        }
        self._top = -1 
        self.symbols = {}
        for ticker, rate_symbol in rate_symbol_by_ticker.items():
            forex_symbol = self.AddForex(ticker, Resolution.Daily, Market.Oanda).Symbol
            data_symbol = self.AddData(NasdaqDataLink, rate_symbol, Resolution.Daily, TimeZones.Utc, True).Symbol
            self.symbols[str(forex_symbol)] = data_symbol
            
        self.Schedule.On(self.DateRules.MonthStart("USDEUR"), self.TimeRules.BeforeMarketClose("USDEUR"), self.Rebalance)

    def Rebalance(self):
        top_symbols = sorted(self.symbols, key = lambda x: self.Securities[self.symbols[x]].Price)
        
    
        self.SetHoldings(top_symbols[0],self._top)
        self.SetHoldings(top_symbols[4],-self._top/5)
        self.SetHoldings(top_symbols[5],-self._top/5)
        self.SetHoldings(top_symbols[6],-self._top/5)
        self.SetHoldings(top_symbols[7],-self._top/5)
        self.SetHoldings(top_symbols[8],-self._top/5)
               
      

    def OnData(self, data):
        pass
    
#class QuandlRate(PythonQuandl):
    
#    def __init__(self):
#        self.ValueColumnName = 'Value'