Overall Statistics
Total Orders
1451
Average Win
0.97%
Average Loss
-1.24%
Compounding Annual Return
3.867%
Drawdown
65.400%
Expectancy
0.106
Start Equity
100000
End Equity
256778.97
Net Profit
156.779%
Sharpe Ratio
0.118
Sortino Ratio
0.127
Probabilistic Sharpe Ratio
0.000%
Loss Rate
38%
Win Rate
62%
Profit-Loss Ratio
0.78
Alpha
-0.017
Beta
0.905
Annual Standard Deviation
0.181
Annual Variance
0.033
Information Ratio
-0.192
Tracking Error
0.111
Treynor Ratio
0.024
Total Fees
$1637.14
Estimated Strategy Capacity
$140000.00
Lowest Capacity Asset
EWM R735QTJ8XC9X
Portfolio Turnover
2.31%
# https://quantpedia.com/strategies/momentum-factor-effect-in-country-equity-indexes/
#
# The investment universe consists of ETFs (funds) which invest in individual countries’ equity indexes. The top 5 countries with the best X – month 
# (where X depends on investors choice, studies show X to be best as 10-12) momentum are chosen as an investment, and portfolio is rebalanced once in a month.

from AlgorithmImports import *

class MomentumFactorEffectinCountryEquityIndexes(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2000, 1, 1)
        self.SetCash(100000)

        # Daily ROC data.
        self.perf = {}
        
        self.period = 6 * 21
        self.SetWarmUp(self.period, Resolution.Daily)
        
        self.symbols = [
                        "EWA",  # iShares MSCI Australia Index ETF
                        "EWO",  # iShares MSCI Austria Investable Mkt Index ETF
                        "EWK",  # iShares MSCI Belgium Investable Market Index ETF
                        "EWZ",  # iShares MSCI Brazil Index ETF
                        "EWC",  # iShares MSCI Canada Index ETF
                        "FXI",  # iShares China Large-Cap ETF
                        "EWQ",  # iShares MSCI France Index ETF
                        "EWG",  # iShares MSCI Germany ETF 
                        "EWH",  # iShares MSCI Hong Kong Index ETF
                        "EWI",  # iShares MSCI Italy Index ETF
                        "EWJ",  # iShares MSCI Japan Index ETF
                        "EWM",  # iShares MSCI Malaysia Index ETF
                        "EWW",  # iShares MSCI Mexico Inv. Mt. Idx
                        "EWN",  # iShares MSCI Netherlands Index ETF
                        "EWS",  # iShares MSCI Singapore Index ETF
                        "EZA",  # iShares MSCI South Africe Index ETF
                        "EWY",  # iShares MSCI South Korea ETF
                        "EWP",  # iShares MSCI Spain Index ETF
                        "EWD",  # iShares MSCI Sweden Index ETF
                        "EWL",  # iShares MSCI Switzerland Index ETF
                        "EWT",  # iShares MSCI Taiwan Index ETF
                        "THD",  # iShares MSCI Thailand Index ETF
                        "EWU",  # iShares MSCI United Kingdom Index ETF
                        "SPY",  # SPDR S&P 500 ETF
                        ]

        self.traded_count = 5

        for symbol in self.symbols:
            data = self.AddEquity(symbol, Resolution.Minute)
            data.SetFeeModel(CustomFeeModel())
            data.SetLeverage(5)
            
            self.perf[symbol] = self.ROC(symbol, self.period, Resolution.Daily)
            
        self.recent_month = -1
    
    def OnData(self, data):
        if self.IsWarmingUp:
            return

        if not (self.Time.hour == 9 and self.Time.minute == 31):
            return
        
        if self.Time.month == self.recent_month:
            return
        self.recent_month = self.Time.month
        
        sorted_by_momentum = sorted([x for x in self.perf.items() if x[1].IsReady and x[0] in data and data[x[0]]], key = lambda x: x[1].Current.Value, reverse = True)
        long = []

        if len(sorted_by_momentum) >= self.traded_count:
            long = [x[0] for x in sorted_by_momentum[:self.traded_count]]
            
        # trade execution
        invested = [x.Key for x in self.Portfolio if x.Value.Invested]
        for symbol in invested:
            if symbol not in long:
                self.Liquidate(symbol)
        
        for symbol in long:
            self.SetHoldings(symbol, 1 / len(long))
            
# Custom fee model
class CustomFeeModel(FeeModel):
    def GetOrderFee(self, parameters):
        fee = parameters.Security.Price * parameters.Order.AbsoluteQuantity * 0.00005
        return OrderFee(CashAmount(fee, "USD"))