Commit Graph

4650 Commits

Author SHA1 Message Date
Scott Sanderson 16e3cb50cc PERF: Use vectorized assignment into dataframe.
This is a dramatic speedup (~25% in local benchmarks) for history calls
with a large number of assets and a short window length.
2016-10-26 21:10:40 -04:00
Scott Sanderson a252bb1e3f PERF: Refactor AdjustedArrayWindow.
Make `__next__` and `seek` share code instead of seek() calling
`__next__`.  This avoids having to make a large number of integer
comparisons and `asanyarray` calls when seeking more than one tick
forward.
2016-10-26 17:32:27 -04:00
Scott Sanderson 57a0822b60 BUG: Return NaT instead of None in daily reader. 2016-10-26 17:32:27 -04:00
Scott Sanderson 52b71af848 PERF: Vectorize assignments in get_history_window. 2016-10-26 17:32:27 -04:00
Scott Sanderson fc153999e2 PERF: Remove attribute access in inner loop. 2016-10-26 17:32:27 -04:00
Scott Sanderson a1f771c1fa MAINT: Auto-rebuild templated cython files. 2016-10-26 16:44:07 -04:00
Scott Sanderson eb2b10554b PERF: Try cache on scalar asset lookups.
This provides a 15% speedup for an algo that calls `data.current` with
1000 every minute.
2016-10-26 15:22:28 -04:00
Eddie Hebert 3f85140bf9 Merge pull request #1552 from quantopian/fix-session-last-traded
BUG: Fix session from minute reader's last traded.
2016-10-24 14:21:15 -04:00
Eddie Hebert 18096f750a BUG: Fix session from minute reader's last traded.
The last traded dt provided from the session bar reader which resamples
from minutes should provide a dt that is a session label, not one that
is at the minute frequency.
2016-10-24 13:58:58 -04:00
Eddie Hebert 546cb138ec Merge pull request #1551 from quantopian/prevent-occlusion-of-key-error-in-history
MAINT: Prevent hiding of KeyError in adjustments.
2016-10-24 12:05:22 -04:00
Eddie Hebert 202b557c48 MAINT: Prevent hiding of KeyError in adjustments.
If a KeyError occurred in the adjustment logic, the exception would be
swallowed by the try block, which was intended to just check whether or
not there was an adjustment reader adjusted.

Discovered when some logic in a futures adjustment reader were failing
because of a mismatch of minute and session labels, which resulted in no
adjustments during windows when there should have been.
2016-10-24 11:33:00 -04:00
Eddie Hebert 0d10a20551 Merge pull request #1549 from quantopian/speedup-resample
PERF: Speedup minute to session sampling.
2016-10-24 10:25:51 -04:00
Eddie Hebert e82fef41dd PERF: Speedup minute to session sampling.
The minute to session sampling reading was creating two DataFrame
objects, the first to hold the minute data, and then a second returned
by the `DataFrame.groupby` to sample down to sessions.

Instead use the arrays returned by the minute readers `load_raw_arrays`
and implement sampling logic which takes advantage that the minutes
being passed start with the first minute of the first session and end
with the last minute of the last session.

On my machine this takes the tests in `test/test_continuous_futures`
from ~4.0 to about ~0.1 seconds.
2016-10-24 09:59:22 -04:00
Maya Tydykov eff2428068 Merge pull request #1547 from quantopian/fix-asset-selection-bug
BUG: create adjustments based on ordered assets instead of set
2016-10-24 08:56:19 -04:00
Maya Tydykov 086ea6be6b TST: update adjustment tests - add gaps between sids
TST: add a seed for permuting
2016-10-21 16:53:56 -04:00
Maya Tydykov 4ea60c2843 BUG: pass the entire list of assets 2016-10-21 16:23:38 -04:00
Maya Tydykov 5e5339285f BUG: create adjustments based on ordered assets instead of set 2016-10-21 16:23:38 -04:00
Eddie Hebert 71d6aa7a15 Merge pull request #1548 from quantopian/continuous-future-adjusted-history
ENH: Add adjusted history for continuous futures.
2016-10-21 11:22:54 -04:00
Eddie Hebert ce37ea64a9 ENH: Add adjusted history for continuous futures.
Add `.adj('mul')` and `.adj('add')` methods on ContinuousFuture, which
when used with `history`, will calculate and apply adjustments so that
the values are adjusted to account for discounts and premiums during
rolls.

Example usage in an algo:

```
from zipline.api import continuous_future

def initialize(context):
    context.cl_add = continuous_future('CL', offset=0, roll='calendar').adj('add')
    context.cl_mul = continuous_future('CL', offset=0, roll='calendar').adj('mul')
    context.cl = continuous_future('CL', offset=0, roll='calendar')
    schedule_function(print_history)

def print_history(context, data):
    frame = data.history([context.cl, context.cl_add, context.cl_mul],
                         ['price', 'sid'],
                         20,
                         '1d')
    print 'unadjusted'
    print frame.loc[:, :, context.cl]
    print 'adjusted add'
    print frame.loc[:, :, context.cl_add]
    print 'adjusted mul'
    print frame.loc[:, :, context.cl_mul]
```
2016-10-21 10:18:12 -04:00
Eddie Hebert bf7fdd9685 Merge pull request #1546 from quantopian/change-test-minute-markers
TST: Encode minutes in continuous future tests.
2016-10-19 13:28:27 -04:00
Eddie Hebert 9011d7b834 TST: Encode minutes in continuous future tests.
Include minutes (in addition to the days) in the price encoding for
continuous futures tests.

Need for different values minute to minute arose when working on tests
for adjusted values.
2016-10-19 11:40:53 -04:00
Eddie Hebert 6efe8e7edc Merge pull request #1544 from quantopian/remove-unused-adjustment-param
MAINT: Remove unused parameter.
2016-10-18 10:38:29 -04:00
Eddie Hebert ea749b081f MAINT: Remove unused parameter.
Was left in as an artifact of development branch.
2016-10-17 17:04:10 -04:00
Eddie Hebert e4150ca966 Merge pull request #1519 from quantopian/shimmed-load-adjustments
MAINT: Begin making a common adjustment interface.
2016-10-17 16:50:37 -04:00
Eddie Hebert 3d7d2c139b MAINT: Begin making a common adjustment interface.
Start making the equity adjustments calculations for the history loader
conform to the same method signature as `load_adjustments` provided by
`SQLiteAdjustmentReader, so that an `AdjustmentReader` interface can
begin to take form.

This prepares for creating a `DispatchAdjustmentReader` which will route
adjustment calculations for equities to the
`HistoryCompatibleUSEquityAdjustmentReader` and continuous futures to a
not yet implemented adjustment reader. All of these readers will share
the `load_adjustments` method.
2016-10-17 16:29:33 -04:00
Eddie Hebert 71765dd3f4 Merge pull request #1522 from quantopian/adjusted-array-perspective-offset
MAINT: Perspective offset for load adjustments.
2016-10-17 16:10:40 -04:00
Eddie Hebert 7d8768e2e4 MAINT: Limit perspective offset.
Limit the perspective offset to 1. There is a possibility that if a
consumer of the AdjustedArrayWindow does not fetch adjustments between
the end of the data window and the vantage points beyond the end of the
window.

Until that case has a solution, e.g. having the consumer of the
AdjustedArrayWindow include the perspective offset when calculating the
query for adjustments, limit the offsets to 1.
2016-10-17 15:08:11 -04:00
Scott Sanderson 62f24dcad7 MAINT: Alternate AdjustedArray boundary conditions.
Avoids the need for a special sentinel value, and means that we only
have to have one branch instead of two in the inner loop.
2016-10-17 14:23:39 -04:00
Scott Sanderson ce223db78c DOC: Fix typo in comment. 2016-10-17 14:23:39 -04:00
Scott Sanderson 68ffd694e3 MAINT: Use perspective_offset in more tests.
- Refactor `test_adjusted_array` to test a range of perspective_offsets in
  all tests.

- Make perspective_offset a parameter to `AdjustedArray.traverse`
  instead of `AdjustedArray`.
2016-10-17 14:23:39 -04:00
Eddie Hebert 34d4e4b974 MAINT: Perspective offset for load adjustments.
Add a perspective offset to `AdjustedArrayWindow` and `AdjustedArray`,
so that `HistoryLoader` does not need to twiddle with offsets to support
viewing the data from the bar after end of the window, (Which is the
case when a '1d' history window is retrieved in minute mode, which is
explained in the docstring for `HistoryLoader.history`)

Presently, this simplifies the logic in
`HistoryLoader._get_adjustments_in_range`, and other incoming
AdjustmentReader's, (e.g. the roll based adjustment reader for continous
futures.) This patch should also make it easier for history and pipeline
to converge on a singular `load_adjustments` method.
2016-10-17 14:23:39 -04:00
Eddie Hebert 837d8824de Merge pull request #1539 from quantopian/continuous-future-history
ENH: Add history for continuous futures.
2016-10-16 23:14:08 -04:00
Eddie Hebert 2f16c08dcd ENH: Add history for continuous futures.
Enable unadjusted history for continuous futures.

The history array is filled by the values for the underlying contracts,
where the contract used changes based on rolls.

e.g., if a `1d` history window was over the range
`2016-01-20` -> `2016-02-29` with contracts with a suffix of `F16` that
rolls at the beginning of the session on `2016-01-26`, `G16` on
`2016-02-26`, and `H16` on `2016-03-26`. The `2016-01-20` ->
`2016-01-25` portion would use the values for `F16', the `2016-01-26` ->
`2016-02-25` portion would use `G16` and the `2016-02-26` ->
`2016-02-29` portion would use `H16`.

Using the same contracts as above, a `1m` history window over the range
(using a timezone of US/Eastern) `2016-01-25 4:00PM` -> `2016-01-25
7:00PM` would fill the `4:00PM` -> `6:00PM` portion with data for `F16`
and the `6:01PM` -> `7:00PM` portion with data for `G16`, since the
beginning of the `2016-01-26` session is `2016-01-25 6:01PM`.

Supports `1d` and `1m`.

Also adds the `sid` field to `history` to assist in showing the active
contract at each dt in the window.
2016-10-16 22:40:08 -04:00
Joe Jevnik 3f8a86dbb5 Merge pull request #1538 from quantopian/events-loader-query-fix
fix events loader blaze query
2016-10-13 15:49:57 -04:00
Joe Jevnik 95a56663d0 BUG: fix blaze query in ffill_query_in_range to correct issue in events loader 2016-10-13 15:27:44 -04:00
Scott Sanderson 8f85bef9fe Merge pull request #1537 from quantopian/allow-partials-in-assert-equal
BUG: Allow partials in assert_equal.
2016-10-12 19:28:35 -04:00
Scott Sanderson e1b8f34182 BUG: Allow partials in assert_equal. 2016-10-12 19:06:56 -04:00
Scott Sanderson 103993a8a8 Merge pull request #1536 from quantopian/allow-name-override-in-preprocessors
ENH: Name overrides in preprocessor factories.
2016-10-12 17:00:56 -04:00
Scott Sanderson cdfad2a54f ENH: Name overrides in preprocessor factories.
Allows ``__funcname`` to be passed to preprocessors like expect_types
and expect_dtypes to override the name displayed in error messages.
This is useful for providing clearer errors for ``__init__`` and
``__new__`` methods in classes.
2016-10-12 15:50:10 -04:00
Maya Tydykov 047313b516 Merge pull request #1535 from quantopian/small-updates-for-estimates
MAINT: small updates to fix deprecation warnings
2016-10-12 14:41:51 -04:00
Maya Tydykov e52d831a94 MAINT: small updates to fix deprecation warnings 2016-10-12 14:21:11 -04:00
Scott Sanderson 81b7d5eadc Merge pull request #1534 from quantopian/allow-kwargs-to-assert-equal-for-pandas-stuff
BUG/TEST: Forward kwargs to assert_series_equal.
2016-10-12 14:16:07 -04:00
Scott Sanderson dcf3124d26 BUG/TEST: Forward kwargs to assert_series_equal. 2016-10-11 21:29:41 -04:00
Eddie Hebert 7883f1fc06 Merge pull request #1533 from quantopian/current-chain
ENH: Add current chain for continuous futures.
2016-10-11 16:37:09 -04:00
Eddie Hebert c25b3d93f4 ENH: Add current chain for continuous futures.
Add `chain`field to current, as well as supporting methods in DataPortal
and OrderedContracts.

Enables the following example:

```
from zipline.api import continuous_future

def initialize(context):
    context.primary_cl = continuous_future('CL', offset=0, roll='calendar')
    schedule_function(print_current_chain)

def print_current_chain(context, data):
    chain = data.current_chain(context.primary_cl)
    print 'datetime={0}'.format(get_datetime())
    print 'primary={0}'.format(chain[0])
    print 'secondary={0}'.format(chain[1])
    print 'tertiary={0}'.format(chain[2])
```

```
datetime=2015-12-23 14:31:00+00:00
primary=Future(1058201602 [CLG16])
secondary=Future(1058201603 [CLH16])
tertiary=Future(1058201604 [CLJ16])
```

Also:
- make return types of OrderedContracts methods compatible across
architectures. (Noticed while adding `active_chain` method.)
- Add year suffix to future contract names in test data.
2016-10-11 16:16:16 -04:00
Joe Jevnik 70bd8e5f64 Merge pull request #1531 from quantopian/assert-slice-equal
TST: Adds assert_equal dispatch for slices
2016-10-11 11:14:23 -04:00
Maya Tydykov c0380f9d9b Merge pull request #1525 from quantopian/fix_estimates_overwrites_bug
Fix estimates overwrites bug
2016-10-10 09:02:40 -04:00
Maya Tydykov ea5b2b030c TST: add test condition to check for bug 2016-10-10 08:41:02 -04:00
Richard Frank 4c40d25be4 DOC: Updated example notebook for latest zipline cell magic 2016-10-09 22:12:20 -04:00
Scott Sanderson 7252a03d67 Merge pull request #1530 from quantopian/add-specific-assets
ENH: Add `SpecificAssets` filter.
2016-10-09 14:09:14 -04:00