Overall Statistics Total Trades 376 Average Win 1.04% Average Loss -0.75% Compounding Annual Return 1.837% Drawdown 10.800% Expectancy 0.315 Net Profit 53.915% Sharpe Ratio 0.433 Probabilistic Sharpe Ratio 0.025% Loss Rate 45% Win Rate 55% Profit-Loss Ratio 1.38 Alpha 0.011 Beta 0.035 Annual Standard Deviation 0.03 Annual Variance 0.001 Information Ratio -0.296 Tracking Error 0.158 Treynor Ratio 0.37 Total Fees \$1953.77 Estimated Strategy Capacity \$320000000.00 Lowest Capacity Asset SPY R735QTJ8XC9X Portfolio Turnover 4.34%
```# https://quantpedia.com/strategies/federal-open-market-committee-meeting-effect-in-stocks/
#
# 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
from datetime import datetime

class FederalOpenMarketCommitteeMeetingEffectinStocks(QCAlgorithm):

def Initialize(self) -> None:
self.SetStartDate(2000, 1, 1)
self.SetCash(100000)

self.market:Symbol = self.AddEquity("SPY", Resolution.Minute).Symbol

self.fed_days_symbol:Symbol = self.AddData(FedDays, 'fed_days', Resolution.Daily, TimeZones.NewYork).Symbol
self.SetWarmUp(1, Resolution.Daily)
FedDays.set_algo(self)

self.recent_day:int = -1

def OnData(self, data:Slice) -> None:
if self.IsWarmingUp: return

if self.fed_days_symbol in data and data[self.fed_days_symbol]:
self.Log(f"New FOMC meeting data arrived: {self.Time}; submitting an MOC order...")

# new fed day data arrived
quantity:float = self.CalculateOrderQuantity(self.market, 1.)
self.MarketOnCloseOrder(self.market, quantity)

self.recent_day = self.Time.day
else:
# other new minute resolution data arrived
if self.Portfolio[self.market].Invested:
if self.Time.day != self.recent_day:
self.recent_day = self.Time.day

self.Log(f"FOMC meeting day; submitting an MOC order to close opened position...")

self.MarketOnCloseOrder(self.market, -self.Portfolio[self.market].Quantity)

class FedDays(PythonData):
algo = None

@staticmethod
def set_algo(algo):
FedDays.algo = algo

def GetSource(self, config:SubscriptionDataConfig, date:datetime, isLiveMode:bool) -> SubscriptionDataSource:
if isLiveMode:
# FedDays.algo.Log(f"Edited GetSource date {FedDays.algo.Time}")
return SubscriptionDataSource("https://data.quantpedia.com/backtesting_data/economic/fed_days.json", SubscriptionTransportMedium.RemoteFile, FileFormat.UnfoldingCollection)

return SubscriptionDataSource("https://data.quantpedia.com/backtesting_data/economic/fed_days.csv", SubscriptionTransportMedium.RemoteFile)

def Reader(self, config:SubscriptionDataConfig, line:str, date:datetime, isLiveMode:bool) -> BaseData:
if isLiveMode:
try:

objects = []
end_time = None

for index, sample in enumerate(data):
custom_data = FedDays()
custom_data.Symbol = config.Symbol

custom_data.Time = (datetime.strptime(str(sample["fed_date"]), "%Y-%m-%d") - BDay(1)).replace(hour=9, minute=31)
# FedDays.algo.Log(f"{custom_data.Time}")

end_time = custom_data.Time
objects.append(custom_data)

return BaseDataCollection(end_time, config.Symbol, objects)

except ValueError: