wilsonfreitas / python-bizdays

Business days calculations and utilities
http://wilsonfreitas.github.io/python-bizdays/
MIT License
79 stars 34 forks source link

getdate unable to handle '1st bizday before 2nd fri' #31

Open RichardDale opened 2 years ago

RichardDale commented 2 years ago

In bizdays 1.0.2, in the getdate function, I'm unable to pass in '1st bizday before 2nd fri'

contractyear=2002
contractmonth=5
newltd=cal.getdate("1st bizday before 2nd fri",contractyear,contractmonth)

This shows:

  File ".../bizdays.py", line 888, in getdate
    dt = self._index.getdate(expr, year, month)
  File ".../bizdays.py", line 313, in getdate
    raise ValueError('Invalid reference day:', tok[4])
ValueError: ('Invalid reference day:', 'fri')

(Incidentally, the usage case for this is for futures market expiries - this one in particular is the 90 Day Bank Accepted Bills contract listed on the Australian Securities Exchange (formerly Sydney Futures Exchange).

Of course, I can do this is a nested fashion, as below, but it'd be nicer for the parser to handle this.

newltd=cal.offset(cal.getdate("2nd fri",contractyear,contractmonth),-1)
wilsonfreitas commented 2 years ago

Hi @RichardDale,

I took some time to investigate in the code. It is not implemented. I'm setting this issue as an enhancement and this will be available in future releases.

Thanks