Overall Statistics
Total Trades
356
Average Win
1.03%
Average Loss
-0.70%
Compounding Annual Return
1.646%
Drawdown
8.800%
Expectancy
0.307
Net Profit
44.226%
Sharpe Ratio
0.396
Probabilistic Sharpe Ratio
0.020%
Loss Rate
47%
Win Rate
53%
Profit-Loss Ratio
1.47
Alpha
0.01
Beta
0.035
Annual Standard Deviation
0.03
Annual Variance
0.001
Information Ratio
-0.299
Tracking Error
0.158
Treynor Ratio
0.341
Total Fees
$1808.96
Estimated Strategy Capacity
$340000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
# https://quantpedia.com/strategies/momentum-factor-effect-in-country-equity-indexes/
#
# The investor is invested in stocks during FOMC meetings (going long S&P 500 ETF, fund, future, or CFD on a close one day before the meeting and closing position on close after the meeting).
# Otherwise, he is invested in cash during the remaining days. The strategy has very low exposure to the stock market (8 days during the average year); therefore, it can be very easily leveraged
# to gain very significant returns.
#
# QC implementation:
#   - FED dates are imported from text file.

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

        # fed days
        csv_string_file = self.Download('data.quantpedia.com/backtesting_data/economic/fed_days.csv')
        dates = csv_string_file.split('\r\n')
        dates = [datetime.strptime(x, "%Y-%m-%d") - BDay(1) for x in 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))