Overall Statistics
fed_dates = [
'1990-02-07',
'1990-03-27',
'1990-05-15',
'1990-07-03',
'1990-08-21',
'1990-10-02',
'1990-11-13',
'1990-12-18',
'1991-02-06',
'1991-03-26',
'1991-05-14',
'1991-07-03',
'1991-08-20',
'1991-10-01',
'1991-11-05',
'1991-12-17',
'1992-02-05',
'1992-03-31',
'1992-05-19',
'1992-07-01',
'1992-08-18',
'1992-10-06',
'1992-11-17',
'1992-12-22',
'1993-02-03',
'1993-03-23',
'1993-05-18',
'1993-07-07',
'1993-08-17',
'1993-09-21',
'1993-11-16',
'1993-12-21',
'1994-02-04',
'1994-03-22',
'1994-05-17',
'1994-07-06',
'1994-08-16',
'1994-09-27',
'1994-11-15',
'1994-12-20',
'1995-02-01',
'1995-03-28',
'1995-05-23',
'1995-07-06',
'1995-08-22',
'1995-09-26',
'1995-11-15',
'1995-12-19',
'1996-01-31',
'1996-03-26',
'1996-05-21',
'1996-07-03',
'1996-08-20',
'1996-09-24',
'1996-11-13',
'1996-12-17',
'1997-02-05',
'1997-03-25',
'1997-05-20',
'1997-07-02',
'1997-08-19',
'1997-09-30',
'1997-11-12',
'1997-12-16',
'1998-02-04',
'1998-03-31',
'1998-05-19',
'1998-07-01',
'1998-08-18',
'1998-09-29',
'1998-11-17',
'1998-12-22',
'1999-02-03',
'1999-03-30',
'1999-05-18',
'1999-06-30',
'1999-08-24',
'1999-10-05',
'1999-11-16',
'1999-12-21',
'2000-02-02',
'2000-03-21',
'2000-05-16',
'2000-06-28',
'2000-08-22',
'2000-10-03',
'2000-11-15',
'2000-12-19',
'2001-01-31',
'2001-03-20',
'2001-05-15',
'2001-06-27',
'2001-08-21',
'2001-10-02',
'2001-11-06',
'2001-12-11',
'2002-01-30',
'2002-03-19',
'2002-05-07',
'2002-06-26',
'2002-08-13',
'2002-04-24',
'2002-11-06',
'2002-12-10',
'2003-01-29',
'2003-03-18',
'2003-05-06',
'2003-06-25',
'2003-08-12',
'2003-09-16',
'2003-10-28',
'2003-12-09',
'2004-01-28',
'2004-03-16',
'2004-05-04',
'2004-06-30',
'2004-08-10',
'2004-09-21',
'2004-11-10',
'2004-12-14',
'2005-02-02',
'2005-03-22',
'2005-05-03',
'2005-06-30',
'2005-08-09',
'2005-09-20',
'2005-11-01',
'2005-12-13',
'2006-01-31',
'2006-03-28',
'2006-05-10',
'2006-06-29',
'2006-08-08',
'2006-09-20',
'2006-10-25',
'2006-12-12',
'2007-01-31',
'2007-03-21',
'2007-05-09',
'2007-06-28',
'2007-08-07',
'2007-09-18',
'2007-10-31',
'2007-12-11',
'2008-01-30',
'2008-03-18',
'2008-04-30',
'2008-06-25',
'2008-08-05',
'2008-09-16',
'2008-10-29',
'2008-12-16',
'2009-01-28',
'2009-03-18',
'2009-04-29',
'2009-06-24',
'2009-08-12',
'2009-09-23',
'2009-11-04',
'2009-12-16',
'2010-01-27',
'2010-03-16',
'2010-04-28',
'2010-06-23',
'2010-08-10',
'2010-09-21',
'2010-11-03',
'2010-12-14',
'2011-01-26',
'2011-03-15',
'2011-04-27',
'2011-06-22',
'2011-08-09',
'2011-09-21',
'2011-11-02',
'2011-12-13',
'2012-01-25',
'2012-03-13',
'2012-04-25',
'2012-06-20',
'2012-08-01',
'2012-09-13',
'2012-10-24',
'2012-12-12',
'2013-01-30',
'2013-03-20',
'2013-05-01',
'2013-06-19',
'2013-07-31',
'2013-09-18',
'2013-10-30',
'2013-12-18',
'2014-01-29',
'2014-03-19',
'2014-04-30',
'2014-06-18',
'2014-07-30',
'2014-09-17',
'2014-10-29',
'2014-12-17',
'2015-01-28',
'2015-03-18',
'2015-04-29',
'2015-06-17',
'2015-07-29',
'2015-09-17',
'2015-10-28',
'2015-12-16',
'2016-01-27',
'2016-03-16',
'2016-04-27',
'2016-06-15',
'2016-07-27',
'2016-09-21',
'2016-11-02',
'2016-12-14',
'2017-02-01',
'2017-03-15',
'2017-05-03',
'2017-06-14',
'2017-07-26',
'2017-09-20',
'2017-11-01',
'2017-12-13',
'2018-01-31',
'2018-03-21',
'2018-05-02',
'2018-06-13',
'2018-08-01',
'2018-09-26',
'2018-11-08',
'2018-12-19',
'2019-01-30',
'2019-03-20',
'2019-05-01',
'2019-06-19',
'2019-07-31',
'2019-09-18',
'2019-10-30',
'2019-12-11',
'2020-01-29',
'2020-03-18',
'2020-04-29',
'2020-06-10',
'2020-07-29',
'2020-09-16',
'2020-11-05',
'2020-12-16'
]
# 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.
#
# QC implementation:
#   - FED dates are imported from text file.

from fed_dates import fed_dates
from pandas.tseries.offsets import BDay

class MomentumFactorEffectinCountryEquityIndexes(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2000, 1, 1)
        self.SetCash(100000)
        
        self.SetBrokerageModel(BrokerageName.AlphaStreams)
        
        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
        self.SetExecution(ImmediateExecutionModel())
        
        self.symbol = self.AddEquity("SPY", Resolution.Minute).Symbol
        dates = [datetime.strptime(x, "%Y-%m-%d") - BDay(1) for x in fed_dates]
        
        self.Schedule.On(self.DateRules.On(dates), self.TimeRules.BeforeMarketClose(self.symbol, 1), self.DayBeforeFED)
    
    def DayBeforeFED(self):
        self.EmitInsights(Insight.Price(self.symbol, timedelta(minutes = 6.5*60 - 1), InsightDirection.Up, None, None, None, 1))