quantopian/zipline — pull request #386 by humdings (2014-08-26 06:54:49+00:00)
Title: ENH: new api method: add_event

This is another version of a time/event management api.

This version allows users to schedule functions to be called with (context, data) args at frequencies other than the backtest frequency. Right now the functions are called before the regular handle_data routine, but after could make sense, it would allow people to set context variables.

Example workflow
```
def func_a(context, data):
# stuff

def func_b(context, data):
# other stuff ...

def func_c(context, data):
# ...

def initialize(context):

# Set functions to be called every 20 min
add_event(freq='20T', functions=[func_a, func_b])

# For once/day events, specify a 'when' function
add_event(time_func=BeforeClose(minutes=5), functions=[func_c])

def handle_data(context, data):
# Nothing to be done
pass
```