Commit Graph

278 Commits

Author SHA1 Message Date
jkleint 82273e296f Propagate exceptions in loader to prevent variable reference before use
`data.loader.ensure_benchmark_data()` was trying to use data after an exception was raised loading it.  The code was logging and swallowing exceptions; this re-raises.
2016-09-23 15:55:55 -07:00
Andrew Daniels db0eabe82a PERF: Replace get_loc calls in calc_dividend_ratios with get_indexer (#1510)
We can make a single vectorized call outside of the loop, instead of
repeatedly calling get_loc inside it.
2016-09-22 19:05:43 -04:00
Andrew Daniels f1919dc3af BUG: Makes NoData{Before, After}Date subclass NoDataOnDate (#1507)
This allows us to catch and handle all three of these exceptions in
`calc_dividend_ratios`.
2016-09-22 11:43:43 -04:00
Andrew Daniels 96cc6b6588 MAINT: Adds option for minute bar writer to not write metadata
With the addition of the truncate function, there are cases where we'll
want to construct a BcolzMinuteBarWriter to call truncate, without
gathering all the metadata. This commit adds a write_metadata arg to its
init, which is True by default. If False is specified, no metadata is
written.

Requires adding logic to truncate to update end_session in metadata to
the truncate date.
2016-09-21 11:31:54 -04:00
Scott Sanderson a9faf94945 PERF: Remove or defer calls to get_loc on large indices.
Mitigation for https://github.com/quantopian/zipline/issues/1503.
2016-09-21 06:18:31 -04:00
Scott Sanderson ce76acce46 MAINT: Use df.resample().apply(). 2016-09-20 17:12:08 -04:00
Scott Sanderson 4ba064dae7 MAINT: Don't make datetime64 from tz-aware Timestamp.
It's slow and deprecated.
2016-09-20 17:12:07 -04:00
Scott Sanderson f24db9c30c DOC: Typo in comment. 2016-09-20 17:12:07 -04:00
Scott Sanderson b9c2e8c1c6 MAINT: Use sort_values instead of sort().
Sort is deprecated.
2016-09-20 17:12:07 -04:00
Scott Sanderson dafe49fcca MAINT: Fix failures/warnings in test_api_shim.py
- Fixes a warning on indexing with a float that ultimately came from
  pd.Timedelta.total_seconds().  Adds ``timedelta_to_integral_seconds``
  and ``timedelta_to_integral_minutes()`` functions and replaces various
  usages of ``int(delta.total_seconds())`` with them.

- Fixes a warnings triggered in ``_create_daily_stats`` from
  passing tz-aware datetimes to np.datetime64.
2016-09-20 17:12:07 -04:00
Jean Bredeche 8048cdcfb0 PERF: Be smarter about counting the number of minutes across a contiguous bunch of sessions. 2016-09-19 13:25:03 -04:00
Andrew Daniels 4a2faa3e13 ENH: Adds truncate method to BcolzMinuteBarWriter (#1499) 2016-09-19 13:02:48 -04:00
Eddie Hebert 6486e64530 Revert "Merge pull request #1490 from quantopian/use-load-adjustments-for-history"
This reverts commit 86c7635b45, reversing
changes made to c77f2b92df.

Some real world cases hit errors with this change, due to the new offset
logic attempting to create Adjustments with invalid parameters.

Will identify exact conditions that cause this error and add as a test
case before remerging.
2016-09-19 08:53:31 -04:00
Jean Bredeche a7f345e651 ENH: Switching from cachetools.LRUCache to lru-dict's LRU cache.
lru-dict is written in C and seems much more performant.
2016-09-16 11:03:13 -04:00
Eddie Hebert f2a1263d90 Merge pull request #1490 from quantopian/use-load-adjustments-for-history
MAiNT: Use load_adjustments for history.
2016-09-15 16:01:23 -04:00
Eddie Hebert 1d06a779b3 MAiNT: Use load_adjustments for history.
Instead of `HistoryLoader` containing separate adjustment calculation
logic, use `SQLiteAdjustmentReader.load_adjustments`.

This change required the addition of two offset parameters to
`load_adjustments` since the perspective on the data from within
`schedule_function` is skewed from how Pipeline looks at historical
data.

This is working towards creating an `AdjustmentReader` abc which
`SQLiteAdjustmentReader` and a upcoming continuous future adjustment
reader will share.
2016-09-15 15:32:10 -04:00
Jean Bredeche 0fd35e7fd1 ENH: Make reader.get_value raise NoDataOnDate if the date is not in the calendar.
DataPortal now catches the NoDataOnDate exception and returns nan for
OHLC and 0 for V.

Price is still forward filled, unchanged.
2016-09-14 22:21:43 -04:00
Jean Bredeche 2856fd0ecf MAINT: Add BarReader base class for both minute and session readers 2016-09-14 13:47:12 -04:00
Scott Sanderson ff1bc51bd1 STY: Fix flake8. 2016-09-07 21:58:15 -04:00
Scott Sanderson 85ce093270 MAINT: Updates from Joe's PR feedback. 2016-09-07 20:42:19 -04:00
Scott Sanderson a8a2cc1582 PERF: Remove module-scope calendar creations.
Remove module scope invocations of `get_calendar('NYSE')`, which cuts
zipline import time in half on my machine. This make the zipline CLI
noticeably more responsive, and it reduces memory consumed at import
time from 130MB to 90MB.

Before:

$ time python -c 'import zipline'

real    0m1.262s
user    0m1.128s
sys     0m0.120s

After:

$ time python -c 'import zipline'

real    0m0.676s
user    0m0.536s
sys     0m0.132s
2016-09-06 09:57:23 -04:00
Eddie Hebert 1269250dde MAINT: Remove unused data portal methods.
The apply adjustments behavior had been moved to the `HistoryLoader`
class.
2016-09-02 12:12:22 -04:00
Eddie Hebert baff6a84bc TST/BUG: Full coverage on resample module.
test_resample now fully covers the resample module.

Fix a bug exposed by increased coverage, where daily aggregation on
`high` would return `nan` for an asset instead of 1) during the
course of day `1d` history was called on non-consecutive minutes and 2)
either, a) the value for the previously inspected dt was `nan` or b)
there were only `nan`s between the previous and current dt.

`low` had a similar bug which was only triggered if the value for the
previously inspected dt was `nan`.
2016-09-01 16:41:45 -04:00
Eddie Hebert 59d06a1883 TST/BUG: Cover all reindex session public methods.
Increase coverage on `ReindexSessionBarReader` so that all methods which
are considered part of the interface are covered by `test_resample`.

Fix bug in `get_value`, exposed by increased coverage, where the
`NoDataOnDate` exception was bubbling from the bcolz reader all the way
up when a session which was a holidy on the underlying reader was passed
to the reindex reader. (The reindex reader should return nan/0 in that
case.)

Also, move location of data index exceptions so that they are agnostic
to bcolz/us_equity_pricing; since the exception is now used by the
resample module to fix aforementioned bug.
2016-09-01 11:51:00 -04:00
Eddie Hebert 1bebad5b68 TST: Fix get_last_traded_dt on bcolz daily reader.
Remove special handling for the last session of an asset, which was
moving the last traded back a session.

If the asset has data on a session, `get_last_traded_dt` should always
return that session if it is the parameter to the method.
2016-08-31 14:59:58 -04:00
Jean Bredeche a37141fb98 ENH: Avoid unnecessary work with missing data. 2016-08-30 17:16:08 -04:00
Andrew Daniels 60c485c1ed ENH: Adds table_len method to BcolzMinuteBarReader (#1436)
To get the length of the underlying table for a given sid.
2016-08-29 15:07:08 -04:00
Eddie Hebert 5dfd2286b3 BUG: Use session label instead of date for 1d.
`1d` history calls were failing on key errors when using the
`us_futures` calendar, because of timestamps occuring before a midnight
would present the wrong midnight (i.e. the midnight before the session,
instead of the following midnight, which is the label for the current
session.)

Tests will follow when bringing up coverage on resample and data portal
modules.
2016-08-29 13:25:14 -04:00
Eddie Hebert a4131ea84b ENH: Add asset dispatch to data portal.
Combine the equity and future readers into asset dispatch readers, so
that simulations that use both asset types can access data for each.

This patch enables `history` for future assets in algorithms; however,
it does not add extra coverage in the `test_data_portal` or `test_history`
to cover future assets. Those tests will follow, however putting this in
separately since it shows that the wrapping of the readers in the asset
dispatch reader does not break existing equity strategies.
2016-08-26 13:29:08 -04:00
Eddie Hebert 413ea3d9d5 MAINT: Add a reader which dispatches on asset type
Add `AssetDispatchSessionBarReader` and corresponding minute and session
bar version of that reader.
This reader routes requests to the appropriate reader based on the asset
type of the requested sids.

`load_raw_array` in the dispatch reader batches the sid by asset type
and then interleaves the results in the out arrays, so that the arrays
data corresponds with sids in the order that sids are passed to the
method, to meet the expected behavior of `load_raw_arrays`.

The dispatch redaer is intended for use by the data portal when using
both future and equities. The dispatch reader will also be passed to the
to the `HistoryLoader`s contained within the data portal, where the
batched `load_raw_arrays` will be used.

Also, BUG:
- Fix the return of `MinuteResampleSessionBarReader.load_raw_arrays` to
match all other readers.
- Use the input dt for the `MinuteResampleSessionBarReader.load_raw_arrays`
as a session label, instead of a minute dt, since it is a session bar
reader.
(Both of these bugs where discovered when using the resample reader for
future data in the dispatch tests.)
2016-08-25 16:29:45 -04:00
Eddie Hebert 0dd01650f1 Merge pull request #1432 from quantopian/reindex-reader
ENH: Add a reader base which reindexes results.
2016-08-25 09:34:06 -04:00
Eddie Hebert fc8cf38a6e ENH: Add a reader base which reindexes results.
Working towards history results which contain mixed asset types, add
a reader which makes `load_raw_arrays` return results indexed on the
session/minute ranges specified by the specified `trading_calendar`
instead of the calendar of the backing reader.

This reader will be used to make Equity readers align with Future
readers. It is intended for use as part of another reader (which will
dispatch queries based on asset type and then recombined results) which
will be passed to the `[Minute|Session]HistoryLoaders in the data portal.
2016-08-24 16:28:19 -04:00
Richard Frank cf6ec9fd73 BUG: More python3 compat 2016-08-24 15:32:31 -04:00
Richard Frank 419bd1e3b5 DEV: zipline ingest can downgrade the assets db
This lets us publish an "old" db version for the most recent release
of zipline, using the latest code base.
2016-08-24 15:32:30 -04:00
Richard Frank bc87ea4efb MAINT: Consolidate coercion to sqlite conn/eng 2016-08-24 13:24:07 -04:00
Eddie Hebert 7ac0978f0c Merge pull request #1431 from quantopian/spot-price-get-value
MAINT: Standardize reader get value methods.
2016-08-24 13:22:13 -04:00
Andrew Daniels acb2cf118e MAINT: Modifies minute bars to use a dict of OHLC ratios (#1428)
For scaling up pricing data before writing to bcolz, the writer now
accepts a dict mapping each sid to the ratio to use. It still accepts a
single ratio as default_ohlc_ratio, which is used as a fallback if no
mapping exists for a given sid. The default is OHLC_RATIO (1000).

This allows better handling of futures pricing data, where the required
precision across root symbols is not consistent.
2016-08-24 13:14:16 -04:00
Eddie Hebert a3c1f4ce36 MAINT: Standardize reader get value methods.
The daily/session bar reader's `spot_price` took the same parameters and
returned the same kind of output as the minute bar reader's `get_value`.

Standardize on one method to make a common interface, which may be
formally factored out in a later patch; to help enable writing reader
implementations or mixins which can be agnostic to the bar frequency.
2016-08-24 12:46:36 -04:00
Ana Ruelas 20f9241252 Merge pull request #1322 from quantopian/move_risk_calculations
Move risk calculations
2016-08-23 18:39:22 -04:00
Ana Ruelas f0af856c13 TST: Update to empyrical, increase test coverage
ENH: Resolve rebase conflict by using updated example_data.tar

TST: Increase test coverage for risk portion of zipline
2016-08-23 13:49:43 -04:00
Richard Frank f247bc8d05 BUG: Fixes zipline ingest with non-default bundle on python 2 2016-08-22 18:30:39 -04:00
Andrew Daniels 193b657bfe BUG: Fixes BcolzMinuteBarMetadata to read the version correctly (#1425)
We were mistakenly using the minute_per_day field.

We now expose from the metadata object the version from which the
metadata was read. This allows a new test that verifies the version is
read correctly.
2016-08-22 17:45:07 -04:00
Eddie Hebert 653865b34c Merge pull request #1413 from quantopian/normalize-equity-future-in-data-portal
MAINT: Remove future/equity distinction.
2016-08-18 23:50:36 -04:00
Eddie Hebert e3bd7e43be MAINT: Remove future/equity distinction.
In the data portal, remove methods that make a distinction between
future and equity asset type. Instead rely on the pricing reader
dispatching.

In support of incoming work which will upsample equity history arrays to
the larger future calendar.

Also, remove perf tracker tests which were using an equity
reader/writer, to be added back in later.
2016-08-18 16:18:32 -04:00
Eddie Hebert 8834d0c35d Merge pull request #1412 from quantopian/remove-unused-data-portal-members
MAINT: Remove unused data portal members.
2016-08-18 16:14:24 -04:00
Andrew Daniels 53ca68e8fb ENH: Pass calendar instance to BcolzMinuteBarWriter (#1406)
* First pass.

* Improvements and fixes

- Update usages of BcolzMinuteBarWriter
- Updates with rebuilt example data
- Expose calendar from BcolzMinuteBarMetadata instead of calendar_name
- Keep market_opens and market_closes in metadata for compatibility

* Store start_session and end_session in minute bcolz metadata

- start_session replaces first_trading_day
- Add end_session to limit to correct days

* For last_available_dt, get last close from calendar to maintain tz

* Bumps version and handles earlier versionson read

* Rebuilt example data on python 3

* Indicate metadata fields that are deprecated
2016-08-18 15:41:26 -04:00
Eddie Hebert 6c90a7c08b MAINT: Remove unused data portal members.
Remove members which are not referred to.
2016-08-18 14:38:35 -04:00
Eddie Hebert 1d22fab127 MAINT: Remove equity from history loader classname
Prepare for using history loaders with both equity and future data,
2016-08-18 14:10:00 -04:00
Eddie Hebert f14fcd9b07 ENH: Session bar reader resampled from minute data
Implement a `SessionBarReader` which uses a minute bar reader as a
backing source, resampling the minute bars into the box around the
corresponding session data.

Also, add future/CME test cases to resample suite.
2016-08-18 11:37:42 -04:00
Eddie Hebert 9e0e2c26a5 Merge pull request #1404 from quantopian/session-bar-fixup
MAINT: Use session bar reader interface.
2016-08-18 10:04:46 -04:00