Overall Statistics
Total Trades
110
Average Win
0.62%
Average Loss
-0.62%
Compounding Annual Return
0.721%
Drawdown
7.900%
Expectancy
0.203
Net Profit
6.968%
Sharpe Ratio
0.218
Loss Rate
40%
Win Rate
60%
Profit-Loss Ratio
1.01
Alpha
0.039
Beta
-1.548
Annual Standard Deviation
0.036
Annual Variance
0.001
Information Ratio
-0.337
Tracking Error
0.036
Treynor Ratio
-0.005
Total Fees
$265.11
from QuantConnect.Data import SubscriptionDataSource
from QuantConnect.Python import PythonData
from datetime import date, timedelta, datetime

class RamandanEffect(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2009,5,5)  #Set Start Date
        self.SetEndDate(2018,9,15)    #Set End Date
        self.SetCash(100000)           #Set Strategy Cash
        self.SetBenchmark("SPY")
        
        self.all_symbols = ["TUR","UAE","EGPT","EWM","KSA",
                            "QAT","EIDO","PKF"]
                            
        for symbol in self.all_symbols:
            self.AddEquity(symbol, Resolution.Daily)
            
        self.AddData(Ramadan, "RD", Resolution.Daily)
        self.ramadan = self.Securities["RD"].Symbol
        self.start = None
        self.end = None

    def OnData(self, data):
        if data.ContainsKey(self.ramadan): 
            self.start = datetime.strptime(data[self.ramadan].Start, '%m/%d/%Y')
            self.end = datetime.strptime(data[self.ramadan].End, '%m/%d/%Y')
        if not self.start: return
        if not self.end: return    
        if not self.Portfolio["TUR"].Invested and self.Time > self.start:
            allocation = 1/len(self.all_symbols)
            for sym in self.all_symbols:
                self.SetHoldings(sym, allocation)
        if self.Portfolio["TUR"].Invested and self.Time > self.end:
            self.Liquidate()
            self.start = None
            self.end = None
    

class Ramadan(PythonData):
    
    def GetSource(self, config, date, isLiveMode):
        return SubscriptionDataSource("https://www.dropbox.com/s/j5zmzq4iuxcrhon/ramadan.csv?dl=1", SubscriptionTransportMedium.RemoteFile)
    
    def Reader(self, config, line, date, isLiveMode):
        ramadan = Ramadan()
        ramadan.Symbol = config.Symbol
        data = line.split(',')
        ramadan.Time = datetime.strptime(data[0], '%m/%d/%Y')
        ramadan["Start"] = data[0]
        ramadan["End"] = data[1]
        return ramadan