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

how to do a drop-in replacement of "trading-calendars" with "exchange_calendars" in dependent packages to get around bug "TypeError: int() argument must be a string, a bytes-like object or a number, not 'NaTType' " ? #233

Closed
richlysakowski opened this issue Sep 17, 2022 · 1 comment

Comments

@richlysakowski
Copy link

I have a package that is dependent on trading-calendars, but trading-calendars has a bug that was fixed in exchange_calendars.
I don't have any idea how to fix the bug: NP_NAT = np.array([pd.NaT], dtype=np.int64)[0] TypeError: int() argument must be a string, a bytes-like object or a number, not 'NaTType'

The trading-calendars bug is as follows:

File "C:\ProgramData\Anaconda3\envs\topss\lib\site-packages\trading_calendars\calendar_helpers.py", line 6, in
NP_NAT = np.array([pd.NaT], dtype=np.int64)[0]
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NaTType'

The exchange_calendars package is a MAJOR overhaul of trading-calendars. The package exchange_calendars has 100s of code changes.

Below is the ONLY place where the trading-calendars` package is used in the dependent package that I am using.

Can anyone tell me what changes how to use exchange_calendars instead for the calculation done by the function get_market_year_fraction() below?

def get_market_year_fraction(start_date, end_date, adjustment):
    """Calculate the year fraction until the expiry date of an option in trading minutes.
  
    Parameters
    ----------
    start_date : string
        Inclusive start date for the time remaining [MM-DD-YYYY] ie: ('10-18-2020')
    end_date : string
        Inclusive end date for the time remaining [MM-DD-YYYY] ie: ('10-20-2020')
    adjustment : float
        [mins] An adjustment factor for handling intraday calculations 
    """
    mins = 390*len(get_calendar('XNYS').sessions_in_range(start_date, end_date)) + adjustment
    return mins/(252*390)
@maread99
Copy link
Collaborator

Hi @richlysakowski, the bug was fixed by #41. The offending line was changed to NP_NAT = pd.NaT.value.

As for using exchange_calendars, the sessions_in_range method hasn't changed so your function would be the same.

>>> import exchange_calendars as xcals
>>> start_date = "2022-07-21"
>>> end_date = "2022-07-23"
>>> xcals.get_calendar('XNYS').sessions_in_range(start_date, end_date)
DatetimeIndex(['2022-07-21', '2022-07-22'], dtype='datetime64[ns]', freq='C')

@maread99 maread99 closed this as completed Oct 3, 2022
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

2 participants