ENH: Adds root_symbol attribute to Future class

Also update AssetFinder to handle root_symbol in meta data
This commit is contained in:
Andrew Daniels
2015-06-24 13:18:13 -04:00
parent 1ae6037a81
commit 46e7b06991
3 changed files with 13 additions and 1 deletions
+6
View File
@@ -230,6 +230,7 @@ class TestFuture(TestCase):
future = Future(
2468,
symbol='OMH15',
root_symbol='OM',
notice_date=pd.Timestamp('2014-01-20', tz='UTC'),
expiration_date=pd.Timestamp('2014-02-20', tz='UTC'),
contract_multiplier=500
@@ -244,6 +245,7 @@ class TestFuture(TestCase):
self.assertTrue("Future" in reprd)
self.assertTrue("2468" in reprd)
self.assertTrue("OMH15" in reprd)
self.assertTrue("root_symbol='OM'" in reprd)
self.assertTrue(("notice_date=Timestamp('2014-01-20 00:00:00+0000', "
"tz='UTC')") in reprd)
self.assertTrue("expiration_date=Timestamp('2014-02-20 00:00:00+0000'"
@@ -256,6 +258,7 @@ class TestFuture(TestCase):
def test_to_and_from_dict(self):
dictd = self.future.to_dict()
self.assertTrue('root_symbol' in dictd)
self.assertTrue('notice_date' in dictd)
self.assertTrue('expiration_date' in dictd)
self.assertTrue('contract_multiplier' in dictd)
@@ -264,6 +267,9 @@ class TestFuture(TestCase):
self.assertTrue(isinstance(from_dict, Future))
self.assertEqual(self.future, from_dict)
def test_root_symbol(self):
self.assertEqual('OM', self.future.root_symbol)
class AssetFinderTestCase(TestCase):
+6 -1
View File
@@ -224,6 +224,7 @@ cdef class Equity(Asset):
cdef class Future(Asset):
cdef readonly object root_symbol
cdef readonly object notice_date
cdef readonly object expiration_date
cdef readonly int contract_multiplier
@@ -231,6 +232,7 @@ cdef class Future(Asset):
def __cinit__(self,
int sid, # sid is required
object symbol="",
object root_symbol="",
object asset_name="",
object start_date=None,
object end_date=None,
@@ -240,6 +242,7 @@ cdef class Future(Asset):
object exchange="",
int contract_multiplier=1):
self.root_symbol = root_symbol
self.notice_date = notice_date
self.expiration_date = expiration_date
self.contract_multiplier = contract_multiplier
@@ -255,7 +258,7 @@ cdef class Future(Asset):
return 'Future(%d)' % self.sid
def __repr__(self):
attrs = ('symbol', 'asset_name', 'exchange',
attrs = ('symbol', 'root_symbol', 'asset_name', 'exchange',
'start_date', 'end_date', 'first_traded', 'notice_date',
'expiration_date', 'contract_multiplier')
tuples = ((attr, repr(getattr(self, attr, None)))
@@ -273,6 +276,7 @@ cdef class Future(Asset):
"""
return (self.__class__, (self.sid,
self.symbol,
self.root_symbol,
self.asset_name,
self.start_date,
self.end_date,
@@ -287,6 +291,7 @@ cdef class Future(Asset):
Convert to a python dict.
"""
super_dict = super(Future, self).to_dict()
super_dict['root_symbol'] = self.root_symbol
super_dict['notice_date'] = self.notice_date
super_dict['expiration_date'] = self.expiration_date
super_dict['contract_multiplier'] = self.contract_multiplier
+1
View File
@@ -44,6 +44,7 @@ ASSET_FIELDS = [
'sid',
'asset_type',
'symbol',
'root_symbol',
'asset_name',
'start_date',
'end_date',