From a220bc4e8f00923d3579dce7d124891122c0db51 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Tue, 9 Oct 2012 17:45:12 -0400 Subject: [PATCH] Removes expiration from orders. Expiration is something that way may want to have in the future, but this current is implementation is dropping orders that aren't meant to be expired. So removing expiration, so that all expected orders are executed. --- zipline/finance/slippage.py | 42 +++++++++++++++---------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/zipline/finance/slippage.py b/zipline/finance/slippage.py index f8719671..cb1978ee 100644 --- a/zipline/finance/slippage.py +++ b/zipline/finance/slippage.py @@ -80,36 +80,28 @@ class VolumeShareSlippage(object): direction = 1.0 for order in orders: - if(order.dt < event.dt): + open_amount = order.amount - order.filled - # orders are only good on the day they are issued + if(open_amount != 0): + direction = open_amount / math.fabs(open_amount) + else: + direction = 1 - if (order.dt.year, order.dt.day) < \ - (event.dt.year, event.dt.day): - continue + desired_order = total_order + open_amount - open_amount = order.amount - order.filled + volume_share = direction * (desired_order) / event.volume + if volume_share > self.volume_limit: + volume_share = self.volume_limit + simulated_amount = int(volume_share * event.volume * direction) + simulated_impact = (volume_share) ** 2 \ + * self.price_impact * direction * event.price - if(open_amount != 0): - direction = open_amount / math.fabs(open_amount) - else: - direction = 1 + order.filled += (simulated_amount - total_order) + total_order = simulated_amount - desired_order = total_order + open_amount - - volume_share = direction * (desired_order) / event.volume - if volume_share > self.volume_limit: - volume_share = self.volume_limit - simulated_amount = int(volume_share * event.volume * direction) - simulated_impact = (volume_share) ** 2 \ - * self.price_impact * direction * event.price - - order.filled += (simulated_amount - total_order) - total_order = simulated_amount - - # we cap the volume share at configured % of a trade - if volume_share == self.volume_limit: - break + # we cap the volume share at configured % of a trade + if volume_share == self.volume_limit: + break orders = [x for x in orders if abs(x.amount - x.filled) > 0