Commit Graph
570 Commits
Author SHA1 Message Date
Delaney Granizo-Mackenzie c6596e2ee2 ENH: Added versioning logic to objects.
In order to be able to load from saved state generated by old
code, we need to have a notion of the version of the saved state.
2015-03-04 14:17:12 -05:00
Delaney Granizo-Mackenzie 64eed84bff MAINT: Added pickle protocol methods into zipline.
Added pickle support to many zipline methods. This will enable
them to be serialized.
2015-03-04 14:17:12 -05:00
Dale Jung 98ee8efe3d BUG: Added sorting back to orders. This isn't a functional bug so much
as it is a backwards compat. Without sorting the orders are filled by
order date. With sorting the orders are moved to back of queue after
partil fills. If all orders are fully filled, there is no
deviation. Also there is no portfolio difference as this is about
assigning fills to equivalent orders.
2015-02-27 08:19:41 -05:00
Dale JungandEddie Hebert 69815d1695 PRF: limit the subset of orders we check for bookkeeping 2015-02-27 05:06:02 -05:00
Dale JungandEddie Hebert 4c5f38d7b1 MAINT: There is no place where orders are put in out of place 2015-02-27 05:06:02 -05:00
Dale JungandEddie Hebert 7a5af8a098 ENH/PRF: Allow SlippageModels to alert that no more liquidity exists and
to stop processing orders
2015-02-27 05:06:02 -05:00
Eddie Hebert faf856a736 MAINT: Print benchmark return value to assertion message.
For when the attempted midnight fails, print more information about the
returns for debugging.
2015-02-26 13:43:15 -05:00
Eddie Hebert a0bd57555d MAINT: Provide a function to create the position calc containers.
For use in a function that wraps de-serialization, to call instead of
creating the OrderedDicts from a module outside of the object.

So that the other module does not need to the internals of this object,
also to ensure that the cythonized OrderedDict is used, when available.

This need should be superseded with serialization versioning.
2015-02-25 13:41:50 -05:00
Eddie Hebert 1054134bd9 BUG: Fix div by 0 error due to changed return type.
When calculate_positions_value used np.dot, the return type was a
np.float64. Which allows the use of 0.0 in division to not raise an
exception.

Fix by expliciting creating an np.float64 with 0 value.
2015-02-23 11:57:07 -05:00
Eddie Hebert 83b0e51b59 BUG: Fix missed cache invalidations on assignment.
_position_values needs to be invalidated on every assignment.
2015-02-23 11:57:07 -05:00
Eddie Hebert eda323dcd4 ENH: Performance period compatibility with internal serialization.
Add a set_positions method so that the serialization process can rebuild
from just the positions, since the last_sale and amounts are derivable
from those values.

Also, use the private naming convention for last sale price and amount
members, so that those members are ignored by the serialization process.
2015-02-23 11:57:07 -05:00
Dale JungandEddie Hebert 25c762138e PERF: Use cached list of price and volume value.
Reduce the number of times the multiplication is done for the
position values to once per bar.
2015-02-23 11:57:07 -05:00
Dale JungandEddie Hebert 913fbb0568 PERF: Replaced use of a pandas.Series for dict-like duties to a cython
based OrderedDict. Series/ndarray can only be sped up so much because
they weren't designed for fast iterative mutations.

This also cut down on the # of intermediate Series being generated
during perf stat generation. Things like s[s > 0] will create a new
Series for s > 0.

Moved cython to requirements.txt and added cyordereddict
2015-02-23 11:57:07 -05:00
Delaney Granizo-Mackenzie 68c41eab1c Merge pull request #470 from quantopian/remove-overnight-minutes
BUG: Changed benchmark returns to only contain market minutes.
2015-02-19 12:29:28 -05:00
Dale JungandEddie Hebert b3bc7e166d BUG: Remove sid entry from open_orders when there are none.
TST: updated tests for new open_orders behavior
2015-02-19 11:22:54 -05:00
Delaney Granizo-Mackenzie 2853830264 BUG: Changed benchmark returns to only contain market minutes.
The series was being generated as all minutes between two times.
It should be only the trading minutes.
2015-02-18 16:42:26 -05:00
Dale JungandEddie Hebert 33cef17396 PERF: make next_window_start faster 2015-02-10 16:34:32 -05:00
Thomas Wiecki a7188187e6 DEV Add preemptive check that benchmark return exists. 2015-02-10 14:54:52 +01:00
fawce 1ab082102a first edition of leveraged etf list 2015-02-05 13:57:28 -05:00
fawce 909b412e9b modified do not order guard to take an iteratble or a container
container allows for dynamic restrictions, necessary for a
point in time implementation of the restricted list.
2015-02-05 13:56:46 -05:00
fawce 52f78fcbc7 restricted list trading control added. 2015-02-05 13:56:45 -05:00
Eddie Hebert 4255016747 PERF: Add a wrapper around Series to speed up perf tracker bottleneck.
Alleviates bottleneck caused re-indexing into a pd.Series during a tight
loop, by keeping track of the index value into the underlying `.values`
in a lookup table.

Based on suggestion from @dalejung
2015-02-03 12:57:32 -05:00
fawce ec055b62bc Merge pull request #464 from quantopian/expand_perf_packet
adding net leverage, long/short exposure, long/short position count
2015-01-08 17:33:22 -05:00
fawce 7ed5461f8f de-linting 2015-01-07 21:47:01 -05:00
fawce 7668858c17 adding net leverage, long/short exposure, long/short position count
to performance packets.
2015-01-06 22:33:28 -05:00
Thomas Wiecki 6a41faf474 MAINT: Make beta calculation robust to missing values.
Risk calculations are robust to nans, except for
beta which calls numpy with the complete list of
algorithm_returns. If nans are present the result
of covar will be nan.

This is fixed by filtering out nans in
algorithm_returns.
2015-01-02 16:00:37 +01:00
Jeremiah LowinandThomas Wiecki 82c94b1dc4 DOC: Fix typo in midnight 2015-01-01 13:54:04 +01:00
John Ricklefs 994f7ceee5 BUG: 'inf' is in Numpy, not Pandas. 2014-12-29 21:23:34 -05:00
John Ricklefs 96cbec3f54 BUG: Fix division-by-zero error if net_liquidation was 0.
Converted _net_liquidation_value to a property to
streamline it a bit, too.
2014-12-29 14:52:31 -05:00
fawce e1ce6ff34e Merge pull request #452 from quantopian/leverage
ENH: Adding Leverage to performance tracking
2014-12-24 11:20:04 -05:00
fawce 22cb6dcb40 added leverage and gross leverage to account.
added tests and conditions for account values.
2014-12-18 17:07:19 -05:00
Delaney Granizo-Mackenzie a0c041dca6 Merge pull request #451 from quantopian/risk-metrics-float-cast
BUG: Assigned dtypes to the cumulative risk metrics DataFrame.
2014-12-17 15:13:11 -05:00
Delaney Granizo-Mackenzie 05903a2031 BUG: Assigned dtypes to the cumulative risk metrics DataFrame. 2014-12-17 13:56:42 -05:00
fawce 0411627169 Modified get_environment to provide multiple fields. 2014-12-07 08:26:13 -05:00
Eddie Hebert eaea8e5317 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.
2014-12-04 12:08:00 -05:00
Joe Jevnik 82dffe8360 MAINT: Updates the add_trading_days to use the index of the date for a
more efficient means of jumping larger gaps of dates.

Adds a docstring to explain the usage of the function.
2014-11-17 13:16:30 -05:00
Joe Jevnik e3d8b1034e ENH: Replaces the simple transforms with history calls. Switches
transforms to quantopian syntax.

Adds the sid attribute to the siddata so it is aware of which security
it represents.
2014-11-17 13:16:30 -05:00
Joe Jevnik ca1569f22a ENH: Adds a closes_in_range and opens_in_range. 2014-11-03 16:26:40 -05:00
Joe Jevnik f8f7f2fc4c ENH: Allows history to be dynamic and grow the container at runtime.
Previously, all specs had to be pre-allocated by using the 'add_history'
function. This is now no longer required and instead serves as a hint to
the HistoryContainer to pre-allocate the space for the given spec.

History can grow by increasing the length for a frequency, adding a
frequency, or adding a field. It can grow with any combination of
these.

HistoryContainer now is aware of the data_frequency of the algorithm,
and no longer uses the daily_at_midnight flag; instead, this is the
default behavior.
2014-11-03 15:57:44 -05:00
Thomas Wiecki 820115f7be MAINT: Replace iterkv with iteritems.
iterkv is being deprecated as of pandas 0.14.
2014-10-22 17:25:37 +02:00
Brian Fink 50c5b73a7b add account object to context 2014-10-10 17:10:45 -04:00
Joe Jevnik 3c37704a5b ENH: Adds a new api method schedule_function.
schedule_function takes a date rule, a time rule, and a function and
will call the function, passing context and data only when the two rules
fire. This allows for code that is conditional to the datetime of the
algo.

This is implemented internally with `Event` objects which are pairings
of `EventRule`s and callbacks.

handle_data becomes a special event with a rule that always fires. This
makes the logic for handling events more complete and compact.
2014-10-06 13:42:36 -04:00
Delaney Granizo-Mackenzie 5488da0dc2 ENH: Well formed exception for any value passed to OrderStyle
This commit adds support for arbitrary objects in addition to NaN
and infinity values. The object well be returned in string format
as part of the error message.
2014-08-26 14:02:28 -04:00
Delaney Granizo-Mackenzie 15f33d3e9d BUG: Exception will be raised when nan value sent to order()
Previously order was not checking for nan values sent as
limit or stop prices. It will now raise a runtime exception
in the event that an attempt to order with a nan price is made.
2014-08-25 11:23:28 -04:00
John Ricklefs f13bbd5d76 ENH: Re-work the usage of _status on Order 2014-08-06 15:00:26 -04:00
John Ricklefs dd97292a94 TST: Add tests for behavior of rejected/held orders.
Also made a tweak to the handling of Order.status
for when a held order is filled (partial or full).
2014-08-06 15:00:26 -04:00
Brian FinkandJohn Ricklefs 65dea626a0 BUG: Clean up handling of reject() and hold() orders 2014-08-06 15:00:25 -04:00
John Ricklefs ec20b3be8a ENH: Add new order statuses for broker integration 2014-08-06 15:00:25 -04:00
Delaney Granizo-Mackenzie 0fd78cd54a BUG: Fixed random dips in returns as shown to user.
Previously the last sale price was not correctly being set on
positions when the transaction arrived before the trade event.
The last sale price was defaulted to zero and never updated. This resulted
in one holding stocks that were bough >>0 and now had value 0 from
the perspective of returns. The returns would display correctly again
when the next trade of that security happened. For most securities trading is
frequent enough that there's no issue, but for some illiquid ones it took
hours to fix itself.

Updated test_perf_tracking:TestPerformanceTracker.test_minute_tracker
This test was based on assuming that last_sale_price was zero,
allowing the sharpe ratio to be calculated. The sharpe ratio can no longer
be calculated for this specific tested scenario and the test has been changed
accordingly.
2014-07-29 11:07:13 -04:00
Scott Sanderson d610ea0a3b DOC: Rename 'guid' to 'id' in dividend tracking logic. 2014-07-18 15:04:20 -04:00