New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add adjusted history for continuous futures. #1548

Merged
merged 1 commit into from Oct 21, 2016

Conversation

Projects
None yet
3 participants
@ehebert
Member

ehebert commented Oct 19, 2016

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]
@coveralls

This comment has been minimized.

coveralls commented Oct 19, 2016

Coverage Status

Coverage increased (+0.03%) to 86.921% when pulling ae56f74 on continuous-future-adjusted-history into 7c72eef on master.

# From Python docs.
a, b = tee(iterable)
next(b, None)
return izip(a, b)

This comment has been minimized.

@yankees714

yankees714 Oct 20, 2016

Contributor

Could also use sliding_window from toolz

This comment has been minimized.

@ehebert

ehebert Oct 21, 2016

Member

Good idea, will change over.

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]
```

@ehebert ehebert force-pushed the continuous-future-adjusted-history branch from ae56f74 to 5b425d5 Oct 21, 2016

@ehebert ehebert merged commit e68b772 into master Oct 21, 2016

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@coveralls

This comment has been minimized.

coveralls commented Oct 21, 2016

Coverage Status

Coverage increased (+0.07%) to 86.96% when pulling 5b425d5 on continuous-future-adjusted-history into 7c72eef on master.

@ehebert ehebert deleted the continuous-future-adjusted-history branch Oct 21, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment