Overall Statistics
Total Trades
136
Average Win
0.41%
Average Loss
-0.45%
Compounding Annual Return
0.022%
Drawdown
12.500%
Expectancy
0.016
Net Profit
0.161%
Sharpe Ratio
0.022
Probabilistic Sharpe Ratio
0.074%
Loss Rate
47%
Win Rate
53%
Profit-Loss Ratio
0.91
Alpha
-0.003
Beta
0.042
Annual Standard Deviation
0.035
Annual Variance
0.001
Information Ratio
-0.631
Tracking Error
0.147
Treynor Ratio
0.019
Total Fees
$335.04
Estimated Strategy Capacity
$9000.00
Lowest Capacity Asset
PAK VZY31PE0HILH
# https://quantpedia.com/strategies/ramadan-effect/
#
# The investment universe consists of countries for which stock market index data are available and in which the proportion of population the professing Muslim faith
# exceeded 50%. Most of the countries could be easily tracked via index ETFs. The research paper we use as an example uses 14 Muslim countries.
# Ramadan is the ninth month in the Islamic calendar, which is based on the motion of the moon. The Ramadan month could be calculated by using information on the
# lunar phases and sunset times from astronomical calendar or information about Ramadan dates from various public sources.
# The trading strategy is simple. The investor holds an equally weighted portfolio of ETFs during Ramadan month. He/she is otherwise invested in cash.

class RamadanEffect(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2015, 1, 1)
        self.SetCash(100000)
        
        self.symbols = ['TUR', 'GULF', 'GAF', 'PAK', 'UAE', 'QAT', 'EGPT', 'EWM', 'EIDO', 'KSA']
        for symbol in self.symbols:
            self.AddEquity(symbol, Resolution.Daily)

        csv_string_file = self.Download('data.quantpedia.com/backtesting_data/economic/ramadan_dates.csv')
        date_pairs_str = csv_string_file.split('\r\n')
        date_pairs = []
        for pair in date_pairs_str:
            split = pair.split(';')
            date_pairs.append([datetime.strptime(split[0], "%d.%m.%Y"), datetime.strptime(split[1], "%d.%m.%Y")])
            
        self.start_dates = [pair[0].date() for pair in date_pairs]
        self.end_dates = [pair[1].date() for pair in date_pairs]

    def OnData(self, data):
        # open trades
        if self.Time.date() in self.start_dates or self.Time.date()-timedelta(days=1) in self.start_dates:
            if not self.Portfolio.Invested:
                long = []
                for symbol in self.symbols:
                    if self.Securities[symbol].GetLastData() and (self.Time.date() - self.Securities[symbol].GetLastData().Time.date()).days < 5:
                        long.append(symbol)
                
                count = len(long)
                for symbol in long:
                    self.SetHoldings(symbol, 1 / count)
        
        # close trades
        if self.Time.date() in self.end_dates or self.Time.date()-timedelta(days=1) in self.end_dates:
            self.Liquidate()