Find day of week from month and year

tryit joseph.steffl at medtronic.com
Wed Sep 14 13:10:56 EDT 2005


Laguna wrote:
> Hi Gurus,
>
> I want to find the expiration date of stock options (3rd Friday of the
> month) for an any give month and year. I have tried a few tricks with
> the functions provided by the built-in module time, but the problem was
> that the 9 element tuple need to be populated correctly. Can anyone
> help me out on this one?
>
> Thanks a bunch,
> Laguna
>
> Requirements:
>
> d0 = expiration(9, 2005) # d0 would be 16
> d1 = expiration(6, 2003) # d1 would be 20
> d2 = expiration(2, 2006) # d2 would be 17

>>> import calendar
>>> [y[4] for y in calendar.monthcalendar(2005, 9) if y[4]!=0][2]
16
>>> [y[4] for y in calendar.monthcalendar(2003, 6) if y[4]!=0][2]
20
>>> [y[4] for y in calendar.monthcalendar(2006, 2) if y[4]!=0][2]
17




More information about the Python-list mailing list