quantopian/zipline — pull request #368 by humdings (2014-07-08 15:51:28+00:00)
Title: ENH: Support for management of periodic events

I have been using a class similar to this for managing events that don't need to occur on every bar that has gotten good feedback from the community in forum posts. This is a first stab at adding it to Zipline.

The primary piece of code is the EventManager class, it helps to manage the trading days between events, and to make sure they don't get executed more than a certain number of times in a trading day.

The EventManager class accepts a rule function which is called for a final entry decision when all other criteria has been met. I added some common rules that can be used as stand alone checks or as rules for the EventManager.

Some rules require parameters at initialization so I used classes with __call__ methods so they can be passed to the EventManager and work the same as if a function was passed.

Example Usage:
This will buy 10 shares of Apple every other day on the 20th and 21st minute minute of the trading day.
```
after_market_open = EventManager(period=2,
max_daily_hits=2,
rule_func=AfterOpen(minutes=20))

def initialize(context):
context.event = after_market_open

def handle_date(context, data):
dt = get_datetime()
if context.event.signal(dt):
print dt
order('AAPL', 10)
```