mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-13 17:42:42 +08:00
DOC: Rename 'guid' to 'id' in dividend tracking logic.
This commit is contained in:
@@ -232,7 +232,7 @@ class PerformancePeriod(object):
|
||||
with fields drawn from zipline.protocol.DIVIDEND_PAYMENT_FIELDS.
|
||||
"""
|
||||
try:
|
||||
unpaid_dividend = self._unpaid_dividends.loc[dividend['guid']]
|
||||
unpaid_dividend = self._unpaid_dividends.loc[dividend['id']]
|
||||
return unpaid_dividend
|
||||
except KeyError:
|
||||
return zp.dividend_payment()
|
||||
|
||||
@@ -61,7 +61,7 @@ class Position(object):
|
||||
that we can pay out the correct amount on the dividend's pay date.
|
||||
"""
|
||||
assert dividend['sid'] == self.sid
|
||||
out = {'guid': dividend['guid']}
|
||||
out = {'id': dividend['id']}
|
||||
|
||||
# stock dividend
|
||||
if dividend['payment_sid']:
|
||||
|
||||
@@ -194,12 +194,15 @@ class PerformanceTracker(object):
|
||||
|
||||
def update_dividends(self, new_dividends):
|
||||
"""
|
||||
Update our dividend frame with new dividends.
|
||||
Update our dividend frame with new dividends. @new_dividends should be
|
||||
a DataFrame with columns containing at least the entries in
|
||||
zipline.protocol.DIVIDEND_FIELDS.
|
||||
"""
|
||||
|
||||
# Mark each new dividend with a unique integer id. This ensures that
|
||||
# we can differentiate dividends whose date/sid fields are otherwise
|
||||
# identical.
|
||||
new_dividends['guid'] = np.arange(
|
||||
new_dividends['id'] = np.arange(
|
||||
self._dividend_count,
|
||||
self._dividend_count + len(new_dividends),
|
||||
)
|
||||
@@ -207,7 +210,7 @@ class PerformanceTracker(object):
|
||||
|
||||
self.dividend_frame = pd.concat(
|
||||
[self.dividend_frame, new_dividends]
|
||||
).sort(['pay_date', 'ex_date']).set_index('guid', drop=False)
|
||||
).sort(['pay_date', 'ex_date']).set_index('id', drop=False)
|
||||
|
||||
def initialize_dividends_from_other(self, other):
|
||||
"""
|
||||
|
||||
+7
-8
@@ -47,7 +47,7 @@ DIVIDEND_FIELDS = [
|
||||
'sid',
|
||||
]
|
||||
# Expected fields/index values for a dividend payment Series.
|
||||
DIVIDEND_PAYMENT_FIELDS = ['guid', 'payment_sid', 'cash_amount', 'share_count']
|
||||
DIVIDEND_PAYMENT_FIELDS = ['id', 'payment_sid', 'cash_amount', 'share_count']
|
||||
|
||||
|
||||
def dividend_payment(data=None):
|
||||
@@ -55,26 +55,25 @@ def dividend_payment(data=None):
|
||||
Take a dictionary whose values are in DIVIDEND_PAYMENT_FIELDS and return a
|
||||
series representing the payment of a dividend.
|
||||
|
||||
Guids are assigned to each historical dividend in
|
||||
Ids are assigned to each historical dividend in
|
||||
PerformanceTracker.update_dividends. They are guaranteed to be unique
|
||||
integers with the context of a single simulation. If @data is non-empty, a
|
||||
guid is required to identify the historical dividend associated with this
|
||||
id is required to identify the historical dividend associated with this
|
||||
payment.
|
||||
|
||||
Additionally, if @data is non-empty, either data['cash_amount'] should be
|
||||
nonzero or data['payment_sid'] should be a security identifier and
|
||||
data['share_count'] should be nonzero.
|
||||
|
||||
The returned Series is given its guid value as a name so that concatenating
|
||||
payments results in a DataFrame indexed by guid. (Note, however, that the
|
||||
The returned Series is given its id value as a name so that concatenating
|
||||
payments results in a DataFrame indexed by id. (Note, however, that the
|
||||
name value is not used to construct an index when this series is returned
|
||||
by function called by `DataFrame.apply`. In such a case, pandas preserves
|
||||
by function passed to `DataFrame.apply`. In such a case, pandas preserves
|
||||
the index of the DataFrame on which `apply` is being called.)
|
||||
|
||||
"""
|
||||
return pd.Series(
|
||||
data=data,
|
||||
name=data['guid'] if data is not None else None,
|
||||
name=data['id'] if data is not None else None,
|
||||
index=DIVIDEND_PAYMENT_FIELDS,
|
||||
dtype=object,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user