Overall Statistics
Total Orders
232
Average Win
0.43%
Average Loss
-0.41%
Compounding Annual Return
1.071%
Drawdown
11.000%
Expectancy
0.351
Start Equity
100000
End Equity
116415.24
Net Profit
16.415%
Sharpe Ratio
-0.241
Sortino Ratio
-0.075
Probabilistic Sharpe Ratio
0.047%
Loss Rate
35%
Win Rate
65%
Profit-Loss Ratio
1.06
Alpha
-0.012
Beta
0.049
Annual Standard Deviation
0.03
Annual Variance
0.001
Information Ratio
-0.682
Tracking Error
0.139
Treynor Ratio
-0.149
Total Fees
$583.32
Estimated Strategy Capacity
$10000.00
Lowest Capacity Asset
QAT VQ6KGBSR66AT
Portfolio Turnover
0.45%
# 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.

from AlgorithmImports import *
from pandas.tseries.offsets import BDay

class RamadanEffect(QCAlgorithm):

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

        # Source: https://www.infoplease.com/calendars/holidays/islamic-holidays
        csv_string_file: str = self.Download('data.quantpedia.com/backtesting_data/calendar/ramadan_dates.csv')
        date_pairs_str: List[str] = csv_string_file.split('\r\n')
        self.date_ranges: List[List] = []

        for pair in date_pairs_str:
            split: List[str] = pair.split(';')
            
            self.date_ranges.append(
                pd.date_range(start=datetime.strptime(split[0], "%d.%m.%Y").date(), 
                end=datetime.strptime(split[1], "%d.%m.%Y").date())
            )

    def OnData(self, slice: Slice) -> None:
        if any(str(self.Time.date()) in self.date_ranges[i] for i in range(len(self.date_ranges))):
            # open trades
            if not self.Portfolio.Invested:
                portfolio: List[PortfolioTarget] = [
                    PortfolioTarget(symbol, 1. / len(self.symbols)) for symbol in self.symbols if symbol in slice and slice[symbol]
                ]
                self.SetHoldings(portfolio, True)
        else:
            # close trades
            if self.Portfolio.Invested:
                self.Liquidate()