Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weekmask issue with NYSE #207

Open
tvr101 opened this issue Jun 29, 2022 · 5 comments
Open

weekmask issue with NYSE #207

tvr101 opened this issue Jun 29, 2022 · 5 comments

Comments

@tvr101
Copy link

tvr101 commented Jun 29, 2022

Hi the NYSE weekmask includes saturday, but this causes issues when the holidays() method is called since the CustomBusinessDay object includes saturday as a valid business day without checking if after 1952, here is an example that roll sunday 6/26 back to saturday 6/25:

import pandas_market_calendars as mcal
nyse = mcal.get_calendar("NYSE")
holidays = nyse.holidays()
holidays.rollback("2022-06-26")

Timestamp('2022-06-25 00:00:00')

@Stryder-Git
Copy link
Collaborator

Hi @tvr101, what I sometimes do is this:

from pandas.tseries.offsets import CustomBusinessDay
import pandas_market_calendars as mcal
nyse = mcal.get_calendar("NYSE")

hols = CustomBusinessDay(holidays= nyse.adhoc_holidays, 
                          calendar= nyse.regular_holidays,
                          weekmask= "1111100")

hols.rollback("2022-06-26")
>> Timestamp('2022-06-24 00:00:00')

This has also bugged me a few times, I will try to have a look how this could be made more user friendly without losing the functionality. If you have any suggestions I'd be happy to hear them.

@pavelstovicek
Copy link

I found a workaround: use XNYS (Mic code for NYSE) instead of NYSE:

import pandas_market_calendars as mcal

nyse = mcal.get_calendar('NYSE')
xnys = mcal.get_calendar('XNYS')
print('NYSE weekmask', nyse.weekmask)
print('XNYS weekmask', xnys.weekmask)

returns

NYSE weekmask Mon Tue Wed Thu Fri Sat
XNYS weekmask Mon Tue Wed Thu Fri

But anyway, the issue should be corrected at NYSE calendar

@tvr101
Copy link
Author

tvr101 commented Aug 28, 2022

given that the weekmask has changed historically, and custombusinessday object doesnt support that level of functionaltiy (changing weekmasks), i think possibly the holidays() method should be deprecated. force users to use the pandas_market_calendar calendar object directly to figure out rollbacks.

@pavelstovicek
Copy link

I have not found how to get rollbacks with pandas_market_calendars. Can you give me help, please? I assumed the pandas_market_calendars should provide this functionality.

Basically, I need third trading day from given date.

What I am using currently:

from pandas.tseries.offsets import CustomBusinessDay
import pandas_market_calendars as mcal

mic = 'XNYS'
market_calendar = mcal.get_calendar(mic)
pandas_calendar = CustomBusinessDay(weekmask=market_calendar.weekmask,
                                    holidays=market_calendar.holidays().holidays)
date = pd.Timestamp('2022-09-12') + 3 * pandas_calendar
print(date)

@maread99
Copy link

maread99 commented Sep 13, 2022

Hi @pavelstovicek, not sure how this might be done within pandas_market_calendars, although you could use the session_offset method of the exchange_calendars calendar...

> import exchange_calendars as xcals
> xnys = xcals.get_calendar("XNYS")
> xnys.session_offset('2022-09-12', 3)
Timestamp('2022-09-15 00:00:00', freq='C')

If you need to be able to work forwards from a date that might not be a session then first use the date_to_session method to anchor the offset on a session.

The data will be the same as the "XNYS" calendar you're using (pandas_market_calendars mirrors this calendar from exchange_calendars). Worth noting that historically "XNYS" is probably less accurate than pandas_market_calendars' native "NYSE" calendar (at least further back than say 20 years ago).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants