Dear all,
I am trying to implement an algorithm which buys/sells stocks in a weekly basis. Currently I am using tradingcalendar module to tell if the previous day is the last trading day of the week:
trade_days = calendar.get_trading_days(pd.Timestamp('2000-01-01',tz="US/Eastern"),get_datetime('US/Eastern'))
if trade_days[-1].isocalendar()[1] <> trade_days[-2].isocalendar()[1]:
If it is, then I will buy the stocks on the market open.
However, I would love to try to buy the stocks before the market close of the last trading day of the week. The problem is: Friday is not always the last trading day and sometimes the markets are not closed at 4pm.
Does anyone have any suggestions? Thanks a lot in advance!!