MAINT: Make commission methods coarse.

In preparation for removal of widespread events, change the commission
methods to use params for sid and cost, instead of an event, for
compatibility with lazy branch.

co-author: @jbredeche <jean@quantopian.com>
This commit is contained in:
Eddie Hebert
2015-12-17 14:42:10 -05:00
parent 71395d4ea1
commit 7eae960b21
4 changed files with 15 additions and 14 deletions
+2 -2
View File
@@ -198,9 +198,9 @@ class PerformancePeriod(object):
def handle_cash_payment(self, payment_amount):
self.adjust_cash(payment_amount)
def handle_commission(self, commission):
def handle_commission(self, cost):
# Deduct from our total cash pool.
self.adjust_cash(-commission.cost)
self.adjust_cash(-cost)
def adjust_cash(self, amount):
self.period_cash_flow += amount
+4 -4
View File
@@ -165,7 +165,7 @@ class Position(object):
self.amount = total_shares
def adjust_commission_cost_basis(self, commission):
def adjust_commission_cost_basis(self, sid, cost):
"""
A note about cost-basis in zipline: all positions are considered
to share a cost basis, even if they were executed in different
@@ -176,9 +176,9 @@ class Position(object):
all shares in a position.
"""
if commission.sid != self.sid:
if sid != self.sid:
raise Exception('Updating a commission for a different sid?')
if commission.cost == 0.0:
if cost == 0.0:
return
# If we no longer hold this position, there is no cost basis to
@@ -187,7 +187,7 @@ class Position(object):
return
prev_cost = self.cost_basis * self.amount
new_cost = prev_cost + commission.cost
new_cost = prev_cost + cost
self.cost_basis = new_cost / self.amount
def __repr__(self):
@@ -317,11 +317,10 @@ class PositionTracker(object):
position.update(txn)
self._update_asset(sid)
def handle_commission(self, commission):
def handle_commission(self, sid, cost):
# Adjust the cost basis of the stock if we own it
if commission.sid in self.positions:
self.positions[commission.sid].\
adjust_commission_cost_basis(commission)
if sid in self.positions:
self.positions[sid].adjust_commission_cost_basis(sid, cost)
def handle_split(self, split):
if split.sid in self.positions:
+6 -4
View File
@@ -314,11 +314,13 @@ class PerformanceTracker(object):
self.cumulative_performance.record_order(event)
self.todays_performance.record_order(event)
def process_commission(self, event):
def process_commission(self, commission):
sid = commission.sid
cost = commission.cost
self.position_tracker.handle_commission(event)
self.cumulative_performance.handle_commission(event)
self.todays_performance.handle_commission(event)
self.position_tracker.handle_commission(sid, cost)
self.cumulative_performance.handle_commission(cost)
self.todays_performance.handle_commission(cost)
def process_benchmark(self, event):
if self.sim_params.data_frequency == 'minute' and \