I'm using python's rrule to work out trading hours. It's easy for days, i'm using a slightly modified example I found on this very site:
def get_rset(start_date):
# Create a rule to recur every weekday starting today
r = rrule.rrule(rrule.DAILY,
byweekday=[rrule.MO, rrule.TU, rrule.WE, rrule.TH, rrule.FR],
dtstart=start_date)
# Create a rruleset
rs = rrule.rruleset()
# Attach our rrule to it
rs.rrule(r)
# Add holidays as exclusion days
for exdate in holidays:
rs.exdate(exdate)
return rs
The problem is while this works great for shares, I need to calculate forex dates differently. I need to work on an hourly basis, add in public holidays etc.
In UTC I believe the markets are open from 10pm Sunday to 10pm the following Friday.
To make this into a rrule I now need 6 different days with Sunday and Friday needing special hours and the remaining weekdays to be considered all hours. I'm pretty sure I need to mix rrule byday and byhour, but I can't any good examples on doing this.
Any help very welcome!