Commit Graph

4673 Commits

Author SHA1 Message Date
Scott Sanderson 8ccdb48c40 DOC: Comment on outdated code. 2016-10-28 14:06:35 -04:00
Scott Sanderson b714a23b44 BUG: Raise SidsNotFound in retrieve_asset. 2016-10-28 14:05:49 -04:00
Richard Frank 7e505926b6 Merge pull request #1567 from bernoullio/master
MAINT: Restore @property decorator
2016-10-28 12:10:58 -04:00
keang 914dca1685 MAINT: Restore @property decorator
This will keep `opens`, `closes`, `early_closes`, etc to the
same pattern.
2016-10-28 23:25:53 +08:00
Scott Sanderson ac74a9dff5 Merge pull request #1561 from quantopian/micro-optimizations-2
Micro optimizations 2
2016-10-28 10:36:33 -04:00
Eddie Hebert e93087e452 Merge pull request #1565 from quantopian/fix-offset-history
BUG: Fix continuous future history with offsets.
2016-10-28 09:44:34 -04:00
Eddie Hebert 8876092d29 BUG: Protect against contract offset at end of range. (#1564)
This boundary case was exposed with internal fixture data which used a
continuous future with a contract chain of size one.
2016-10-27 16:48:34 -04:00
Eddie Hebert c25da8f442 BUG: Fix continuous future history with offsets.
Apply offset value when writing out the rolls in a continuous future
which is offset from the primary.
2016-10-27 16:23:03 -04:00
Eddie Hebert e07d5a202a Merge pull request #1563 from quantopian/use-same-session-for-contract-closes
BUG: Use proxy for settlement on future adjustments.
2016-10-27 13:31:12 -04:00
Eddie Hebert e1bafe1ecc BUG: Use proxy for settlement on future adjustments.
Instead of using the difference between the session close of the front
contract before the roll and and the open of back contract on the
beginning of the roll, use the close of both at the end of the session
before the roll.

The closes of the session prior to roll is in lieu of settlement data.
2016-10-27 12:40:59 -04:00
Scott Sanderson 48c725b5ea PERF: Call concatenate directly instead of hstack.
Avoids a couple function calls in a hot path.
2016-10-26 23:49:48 -04:00
Scott Sanderson 0cbc2ca388 PERF: Don't round until after we hstack. 2016-10-26 23:30:12 -04:00
Scott Sanderson 1e889987eb MAINT/PERF: Remove redundant method call.
`_get_minute_window_data` was just forwarding its input to a method with
the same signature.
2016-10-26 23:28:34 -04:00
Scott Sanderson d18080553b PERF: Pull out loop-invariant code.
This shaves off 20 out of 160 seconds for an algorithm that makes a
large number of large universe, short window_length `history()` calls.
2016-10-26 23:27:33 -04:00
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
Paul Sutherland 0fbf7b428b DEV delete old *.c and *.so files with rebuild-cython.sh for Darwin/OSX (#1560) 2016-10-26 19:08:36 -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 82cbac85c2 Merge pull request #1558 from quantopian/add-detail-to-history-calendar-mismatch
MAINT: Add more info to history calendar KeyError.
2016-10-26 15:12:08 -04:00
Eddie Hebert 9294e39ea0 MAINT: Add more info to history calendar KeyError.
There have been cases where the requested start or end date is not in
the history calendar.

Add the beginning and of the calendar to the KeyError to give more
detail to figure out root cause.
2016-10-26 14:41:37 -04:00
Eddie Hebert 642e404982 Merge pull request #1556 from quantopian/volume-based-rolls
ENH: Volume based rolls for futures.
2016-10-25 15:21:41 -04:00
Eddie Hebert 473c8fddba ENH: Volume based rolls for futures.
Add roll style which takes the volume of the contracts into account.
If the volume moves from the front to the back before the auto close
date, the roll is put at that session.

Also, factors out some of the common logic shared with calendar based rolls.
2016-10-25 14:08:21 -04:00
Eddie Hebert 7e3e00c772 Merge pull request #1555 from quantopian/return-nan-from-bcolz-daily-reader
MAINT: Return nan from daily bcolz get_value.
2016-10-25 11:49:51 -04:00
Eddie Hebert a823cceabc MAINT: Return nan from daily bcolz get_value.
Match the behavior of the minute bar reader, now that the session and
minute bar readers share a common interface.

isnull is slightly slower than checking against -1; however, n cases
where we check against illiquid trades in a tight loop, volume is
checked which is not using nan. The change here should be marginal with
regards to performance.
2016-10-25 11:25:09 -04:00
Eddie Hebert 426c2070c8 Merge pull request #1553 from quantopian/change-start-date-of-cf-tests
TST: Make test dates aligned with test data.
2016-10-25 11:16:07 -04:00
Eddie Hebert fa63fa6dd5 TST: Make test dates aligned with test data.
Move dates queried near beginning of test data so that the range of data
covered does not extend beyond the beginning of the range.
i.e. the windows were covering 2016-01-25, which had no test data generated.
(Does not matter for the calendar based rolls, but is needed for volume
based rolls.)

Also, make room for having the first roll to be a day before the first auto
close by moving the first contracts auto close date back a day.

In preparation for testing volume rolls.
2016-10-25 10:21:23 -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