Overall Statistics
Total Orders
75
Average Win
1.49%
Average Loss
-1.18%
Compounding Annual Return
6.581%
Drawdown
10.600%
Expectancy
0.037
Start Equity
100000.00
End Equity
137557.20
Net Profit
37.557%
Sharpe Ratio
0.186
Sortino Ratio
0.226
Probabilistic Sharpe Ratio
29.161%
Loss Rate
54%
Win Rate
46%
Profit-Loss Ratio
1.27
Alpha
0.016
Beta
-0.069
Annual Standard Deviation
0.058
Annual Variance
0.003
Information Ratio
-0.409
Tracking Error
0.162
Treynor Ratio
-0.154
Total Fees
$0.00
Estimated Strategy Capacity
$29000000.00
Lowest Capacity Asset
USDTRY 8G
Portfolio Turnover
1.32%
Drawdown Recovery
483
#region imports
from AlgorithmImports import *
#endregion
# https://quantpedia.com/Screener/Details/8
# Create an investment universe consisting of several currencies (15). 
# Go long 3 currencies with strongest 12 month momentum against USD and 
# go short 3 currencies with lowest 12 month momentum against USD.


class FXMomentumAlgorithm(QCAlgorithm):

    def initialize(self):
        self.set_start_date(self.end_date - timedelta(5*365))
        self.set_cash(100000)
        self.settings.automatic_indicator_warm_up = True

        # choose 21 forex pairs with the USD
        tickers = ["AUDUSD", "EURUSD", "GBPUSD", "NZDUSD", "GBPUSD", "USDCNH", "USDCZK", 
                   "USDDKK", "USDHKD", "USDHUF", "USDINR", "USDJPY", "USDMXN", "USDNOK", 
                   "USDPLN", "USDSAR", "USDSEK", "USDSGD", "USDTHB", "USDTRY", "USDZAR"]

        for ticker in tickers:
            forex = self.add_forex(ticker, Resolution.MINUTE, Market.OANDA)
            forex.momp = self.momp(forex.symbol, 252, Resolution.DAILY)

        # Rebalance the portfolio monthly 
        self.schedule.on(self.date_rules.month_start("EURUSD"), self.time_rules.after_market_open("EURUSD"), self._rebalance)

    def _rebalance(self):
        # Pick 3 ETFs with strongest momentum and weight them equally.
        to_long = sorted(self.securities.values(), key=lambda s: s.momp)[-3:]
        targets = [PortfolioTarget(f.symbol, 1/3, f'{f.momp.current.value:.4f}') for f in to_long]
        self.set_holdings(targets, liquidate_existing_holdings=True)