quantopian/zipline — pull request #443 by ehebert (2014-11-24 16:39:09+00:00)
Title: Remove bottleneck caused by unnecessary check of the position index.

Instead of checking the positions indexes every time either
`_position_amounts` or `_position_last_sale_prices` is updated, check
and grow the individual Series on each update.

This gain with this patch is by reducing the following bottlenecks:
- Checking both vectors when only one is updated.
- Using try/except to trigger the growth, instead of incurring the cost
of checking the Index contains on every update.

In testing this change results in about a 33% speedup of the
`update_last_sale` algorithm when run with a buy and hold algorithm with
160 equities, resulting in a 20% speedup overall.

## Further Context

The eventual goal here is to collapse the two position Series into a DataFrame, as prototyped here https://github.com/quantopian/zipline/tree/vectorize-positions, but the gain from this patch had a big enough gain to parts changed that it is worth pulling in before doing more volatile changes.