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 continuous future current contract. #1529

Merged
merged 1 commit into from Oct 8, 2016

Conversation

Projects
None yet
5 participants
@ehebert
Member

ehebert commented Oct 7, 2016

Add the ability for an algorithm to request the current contract for a
future chain via data.current.

e.g.:

data.current(ContinuousFuture('CL', offset=0, roll='calendar'),
'contract')

Notes/Questions

  • Since ContinuousFuture will also be used in history and other places where Assets are used.
    The ContinuousFuture object provides sid and is_exchange_open.

    Ideally, there would be some base interface which would harden that duck typing. But would request that is something we do post making the other ContinuousFuture data methods work.

  • The sid calculation for the ContinuousFuture is intended to be consistent across simulations. However, would not recommend using that sid as something that would never change. If and when we add more custom sids, the struct packing format may need to change to allow more flexibility.

  • Choice of OrderedContracts structure was based on this notebook snippet on a chain of 254.

In [86]
%%cython
from numpy cimport int64_t, intp_t
cimport cython
@cython.boundscheck(False)
@cython.wraparound(False)
cpdef intp_t get_auto_close_loc(int64_t[:] auto_close_dates, int64_t dt_value):
    cdef intp_t i
    cdef int64_t val
    for i in range(auto_close_dates.shape[0]):
        val = auto_close_dates[i]
        if val > dt_value:
            break
    return i

In [87]
%%timeit
get_auto_close_loc(auto_close_dates, dt_value)
The slowest run took 18.09 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 659 ns per loop

In [11]
%%timeit
np.searchsorted(start_dates, dt_value, side='right')
The slowest run took 18.61 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 910 ns per loop

@ehebert ehebert force-pushed the current-contract branch from da30bac to 6a3f9c9 Oct 7, 2016

@coveralls

This comment has been minimized.

coveralls commented Oct 7, 2016

Coverage Status

Coverage increased (+0.01%) to 86.818% when pulling 6a3f9c9 on current-contract into eba02da on master.

return not (field in BASE_FIELDS and isinstance(asset, Asset))
return not (field in BASE_FIELDS and
(isinstance(asset, Asset) or
isinstance(asset, ContinuousFuture)))

This comment has been minimized.

@richafrank

richafrank Oct 7, 2016

Member

isinstance(asset, (Asset, ContinuousFuture))

This comment has been minimized.

@ehebert

ehebert Oct 7, 2016

Member

Right. Will fix.

"""
return {
'sid': self.sid,
'symbol': self.root_symbol,

This comment has been minimized.

@yankees714

yankees714 Oct 7, 2016

Contributor

Should this be 'root_symbol' instead of 'symbol', like the kwarg?

This comment has been minimized.

@ehebert

ehebert Oct 7, 2016

Member

Yes, will fix.

@classmethod
def from_dict(cls, dict_):
"""
Build an Asset instance from a dict.

This comment has been minimized.

@yankees714

yankees714 Oct 7, 2016

Contributor

Leftover Asset reference. We also refer to "asset" a few times below

return calendar.is_open_on_minute(dt_minute)
cdef class OrderedContracts(object):

This comment has been minimized.

@yankees714

yankees714 Oct 7, 2016

Contributor

Maybe just me, but confused me a bit since I first read this like "contracts that we have ordered"

This comment has been minimized.

@ehebert

ehebert Oct 7, 2016

Member

Definitely open to a better name.

This comment has been minimized.

@ehebert

ehebert Oct 7, 2016

Member

@yankees714 and I discussed SortedContracts as a possible candidate. May change that post merge.

@ehebert ehebert force-pushed the current-contract branch from 6a3f9c9 to 438e82d Oct 7, 2016

@coveralls

This comment has been minimized.

coveralls commented Oct 7, 2016

Coverage Status

Coverage increased (+0.01%) to 86.818% when pulling 438e82d on current-contract into eba02da on master.

@ehebert ehebert force-pushed the current-contract branch from 438e82d to 7004382 Oct 7, 2016

@coveralls

This comment has been minimized.

coveralls commented Oct 7, 2016

Coverage Status

Coverage increased (+0.01%) to 86.818% when pulling 7004382 on current-contract into eba02da on master.

@ehebert ehebert force-pushed the current-contract branch from 7004382 to 6184eae Oct 7, 2016

@coveralls

This comment has been minimized.

coveralls commented Oct 7, 2016

Coverage Status

Coverage increased (+0.01%) to 86.818% when pulling 6184eae on current-contract into eba02da on master.

ENH: Add continuous future current contract.
Add the ability for an algorithm to request the current contract for a
future chain via `data.current`.

e.g.:
```
data.current(ContinuousFuture('CL', offset=0, roll='calendar'),
'contract')
```

@ehebert ehebert force-pushed the current-contract branch from 6184eae to ec6f298 Oct 7, 2016

@coveralls

This comment has been minimized.

coveralls commented Oct 7, 2016

Coverage Status

Coverage increased (+0.06%) to 86.862% when pulling ec6f298 on current-contract into eba02da on master.

@ehebert ehebert merged commit 3ab251c into master Oct 8, 2016

2 checks passed

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

@ehebert ehebert deleted the current-contract branch Oct 8, 2016

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