simple-back icon indicating copy to clipboard operation
simple-back copied to clipboard

scheduling in strategies

Open MiniXC opened this issue 4 years ago • 0 comments

Currently, doing specific things on certain days or events leads to messy nested ifs. I propose we add a decorators for scheduling. The big task (as always) is naming things, I was thinking of the following syntax, but there might be better options.

@run(every='monday', on='open')
@run(every='day', on='close')
@run(every='firstdayofweek', on='open') # run on tuesday if market closed on monday
@run(on='open') # sensible default for every could be 'day'
@run(every='tuesday') # while on could default to ['open', 'close'] (open & close)
...

Another option that instead of replacing ifs inside strategies would make it easier to determine if certain conditions are met would be to introduce a ScheduleConditions class, e.g. with shorthand bt.schedule

if bt.schedule.monday:
  ...
if bt.schedule.open:
  ...
if bt.schedule.first_day_of.week:
  ...
if bt.schedule.first_day_of.month:
  ...
if bt.schedule.date == '2019-1-1':
  ...
if bt.schedule.event == 'open':
  ...

We could also pass schedule to strategies directly and get rid of day and event. Decorators could still work like this:

@run(Schedule.first_day_of.week)
...

Schedule could be static (it only depends on bt, no internal state) and e.g. bt.schedule.open could just be shorthand for Schedule.open(bt). Or we could use a scheduling library but they would almost certainly have to be modified for the specific market calendars we are using.

MiniXC avatar Jun 20 '20 12:06 MiniXC