quantopian/zipline — pull request #285 by colin1alexander (2014-03-17 23:58:08+00:00)
Title: Transforms - ATR

Hi.

I use ATR so frequently to size positions and set stops, limits, etc., that I thought it would be useful to have it as a simple transform, basically a property of the security. The history doesn't matter, only the current value at the current point in time.

For example,

stop_price = data[stock].price - 2 * data[stock].atr(20)

is much cleaner than:

# Set up the ATR indicator.
atr_data = ta.ATR(timeperiod=20)
=======

def handle_data(context, data):
...
stop_price = data[stock].price - 2 * atr_data(data)[stock]

I had a go at the simple transform, but I'll need some guidance putting together the test. Namely how do I set up my test data history of high, low and close prices to use for my assert calculations?

Thanks.