Commit Graph
89 Commits
Author SHA1 Message Date
jfkirk 67c56f768b ENH: Adds auto-closing feature and implements for Futures 2015-07-31 10:38:44 -04:00
jfkirk 16ab46b69c DEV: Uses ValueError when PerformanceTracker.to_dict receives invalid emission type 2015-07-21 16:06:52 -04:00
jfkirk 8d5bfd3c91 BUG: Aligns performance packet generation between minute and daily modes 2015-07-21 13:25:39 -04:00
Eddie Hebert 27ab36deb2 MAINT: Remove references to minute risk.
The minutely calculation of risk metrics had been removed with a
previous patch, remove vestigial references.

Remove a test which tested the behavior of updating the second minute of
a day.

Remove the logic that changed the datetime index of the risk metrics
depending on emission rate, now only trading_days are needed.

Remove `returns_frequency` parameter since both minute and daily
data frequency always use daily returns.
2015-07-15 15:36:35 -04:00
jfkirk efa6d8dbce ENH: Adds a perf tracker method to handle SIDs leaving the universe 2015-07-09 17:03:21 -04:00
Eddie Hebert 7a1a6ddb37 PERF: Reduce time spent indexing in risk cumulative update.
Instead of using the pandas.Series datetime index for every single
vector, get the index at the beginning of the update loop based on the
dt and then use that index to set the values.

Also, since the dt lookup is no longer needed, store the values as numpy
arrays, which are more lightweight.

Locally, this patch cuts out about 60% of the time spent in the update
method.
2015-07-01 10:52:02 -04:00
jfkirkandJohn Ricklefs 9291a89599 BUG: Prevents payout of dividend on final trading close 2015-06-24 21:45:55 -04:00
Eddie Hebert 3da3cbe7e7 MAINT: Remove position proxy.
Use explicit references to the performance tracker instead of the proxy
lookup.

Mainly a putative change, which surfaced when reasoning about places
where the position tracker and period need access to the last sale
price.
2015-06-16 16:57:41 -04:00
jfkirk 3ee3a1226b BUG: Fixes handling of CLOSE_POSITION events for Futures 2015-06-11 11:40:54 -04:00
jfkirk 13180d5348 PERF: Removes unnecessary and expensive caching of values and exposures 2015-06-11 11:35:49 -04:00
jfkirk 7e5c638eb8 PERF: Removes asset lookups on every transaction 2015-06-11 11:35:49 -04:00
jfkirk 1b98d23b91 PERF: Removes asset lookups on ever trade event 2015-06-11 11:35:49 -04:00
jfkirk b84ac01cbf ENH: Adds futures trading and asset management logic to TradingAlgorithm and performance classes 2015-06-11 11:35:49 -04:00
warren-oneill 77fb100ae6 adding type as variable to create_test_panel 2015-06-04 15:50:41 +02:00
warren-oneill 44fbdff4ac added CLOSE_POSITION as source type, added pt.close_position_event(), added process_close_postion(), added close processing to tradesimulation, added unittest for close_position_event 2015-06-04 14:23:46 +02:00
Stewart Douglas b24bd561e7 BUG: Stop account_needs_update from blocking performance updates
Referencing context.account in handle_data() can block updates to account,
portfolio and performance metrics, which can cause unintended changes in
financial performance. Additionally, since context.account metrics are not
updating frequenctly enough (daily, rather than minutely) algos which base
decisions on these metrics can have undesired behavior.

To address this we do not base our decision to update performance on the
state of account_needs_update.

When we call get_account() from the market and minute close methods, we
set the performance_needs_update parameter to False since we just updated
performance.

_get_account() is renamed to _update_account() since the method does not
return account information.

Also remove redundant asset_needs_update = True lines.
2015-05-28 11:15:40 -04:00
warren-oneill 064d973ec2 pass day instead of market_open to next_open_and_closes and use day instead of market_close for benchmark index 2015-05-26 16:17:55 +02:00
Eddie Hebert 1e76be611b MAINT: Remove unused method on performance period.
set_positions is no longer referenced.
2015-05-15 23:31:28 -04:00
Eddie Hebert 9e57198e16 MAINT: Remove unused property on performance period.
The last sale prices property is no longer referenced elsewhere.
2015-05-14 15:46:17 -04:00
Eddie Hebert dba0a99a16 PERF: Use specific methods for processing events.
By having both the trade simulation main loop route events to "process"
methods based on event type and the process methods also checking event
type, there was some duplicated effort in doing that comparison many
times.

A particular case where this was noted in profiling was for the
`process_event` function which was checking if the type was not a trade
and returning early, when in a larger universe of stocks the value
returned False 99% of the time.

Instead provide separate process functions specific to each type,
e.g. e.g. `process_trade` and `process_transaction` and route traffic to
those functions in tradesimulation.

For a universe of 160 stocks on both no-op algo and an algo that rebuys
its universe every day, saw about a 10% increase locally.

Also:

- Add process_benchmark to blotter since internal subclass relies on
logic on benchmark, this allows the internal process_trade to be a
`pass`.

- Add warning on unrecoginzed event types.
2015-05-08 12:44:32 -04:00
Eddie Hebert 72ab9e74dd MAINT: Remove unused event_count from tracker.
event_count is not referenced anywhere, so remove extra bit of state
tracking.
2015-05-05 16:31:02 -04:00
Eddie Hebert 16a615f3f0 MAINT: Use setitem syntax instead of update for tracker dict addition.
Since only value is being changed, use the setitem brackets intsead of
calling updated.
2015-05-04 14:02:47 -04:00
Eddie Hebert 63dbea5da4 ENH: Remove unused minute risk containers.
The risk containers that are actually used for reports use the
'cumulative' style container which has an index of days, not minutes.

The minute containers and copying of data etc. were causing an expanding
memory footprint.
2015-05-04 13:56:29 -04:00
Eddie Hebert da0a5bbc3f MAINT: Remove dependence on intraday risk for benchmark returns.
The intraday_risk_metrics is being removed since the values are not
used; cumulative risk metrics with the last value updated to the latest
close has been used for some time.

Before the removal of intraday_risk_metrics, the position trackers
passing of benchmark returns to the cumulative risk metrics needs to no
longer depend on the calculations done by the intraday stats. So instead
use the all_benchmark_returns stored in the tracker directly.
2015-05-04 13:56:29 -04:00
Eddie Hebert d343e06593 BUG: Remove use of defaultdict leading to memory growth.
defaultdict behavior was adding and never releasing a list and Timestamp
every time to_dict was called.
2015-04-22 10:46:20 -04:00
Eddie Hebert ec63397d28 BUG: Stop addition of new list in orders_by_modified on every dt.
Remove use of defaultdict for orders_by_modified, which was causing an
empty list to be added every time to_dict was called with a specified
dt.

Nnoticed in the minute emission case when hunting another memory leak,
every simulation minute a new Timestamp and list was created and never
let go.
2015-04-22 10:40:08 -04:00
Brian Fink 8baf52fe01 ENH: Add max leverage account guard 2015-04-10 15:19:54 -04:00
Brian Fink 2f895bddcd ENH: Track max leverage as risk 2015-04-10 15:19:54 -04:00
Eddie Hebert 9bc40563b7 MAINT: Remove unused returns vector from perf tracker.
The returns Series in the perf tracker appears to be vestigial, so
remove.
2015-04-09 14:43:19 -04:00
Jonathan Kamens e942275108 STY: Flake8
Upgrade the version of the flake8, pep8, and mccabe PyPI packages, and
make the code changes necessary for compatibility with the updated
packages.
2015-03-19 17:21:25 -04:00
Dale JungandEddie Hebert 7892a6943f RFT: Remove Position management from PerformancePeriod. This cuts down
on the number of per-tick update that occur since they were duplicated
per each PerformancePeriod. Also opens up the path to cythonizing the
entire object
2015-03-18 22:48:14 -04:00
Delaney Granizo-Mackenzie f6f69e9106 MAINT: Updated iteritems for python3 compatibility 2015-03-05 14:05:24 -05:00
Delaney Granizo-Mackenzie a2bc6dd1f5 BUG: Fixed bug with returning non-primitive dicts. 2015-03-04 17:47:48 -05:00
Delaney Granizo-Mackenzie 8b3fce94a3 MAINT: Refactored serialization parent class out.
Previously the class SerializeableZiplineObject was used to
house basic __setstate__ and __getstate__ methods. It wasn't
really doing much that was helpful, so it is now gone.
2015-03-04 14:17:13 -05:00
Delaney Granizo-Mackenzie 0fd1efff5f BUG: Updated some bugs in serialization.
The state dictionaries weren't being copied, so the state version
label was being injected into the original object.
2015-03-04 14:17:13 -05:00
Delaney Granizo-Mackenzie ca210f0778 MAINT: Refactored serialization code. 2015-03-04 14:17:12 -05:00
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
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 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
Thomas Wiecki a7188187e6 DEV Add preemptive check that benchmark return exists. 2015-02-10 14:54:52 +01: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