Overall Statistics
Total Trades
360
Average Win
1.03%
Average Loss
-0.73%
Compounding Annual Return
1.535%
Drawdown
8.800%
Expectancy
0.274
Net Profit
41.077%
Sharpe Ratio
0.365
Probabilistic Sharpe Ratio
0.011%
Loss Rate
47%
Win Rate
53%
Profit-Loss Ratio
1.41
Alpha
0.009
Beta
0.036
Annual Standard Deviation
0.03
Annual Variance
0.001
Information Ratio
-0.302
Tracking Error
0.159
Treynor Ratio
0.31
Total Fees
$1824.10
Estimated Strategy Capacity
$310000000.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 AlgorithmImports import *

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))