From 1b2f6739e94c75c1a07ace41ca130d52ca34af84 Mon Sep 17 00:00:00 2001 From: Richard Frank Date: Wed, 28 Nov 2012 19:42:57 -0500 Subject: [PATCH] Fixed floating-point error in volume share slippage model --- zipline/finance/slippage.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/zipline/finance/slippage.py b/zipline/finance/slippage.py index c0161d3b..1f1699f8 100644 --- a/zipline/finance/slippage.py +++ b/zipline/finance/slippage.py @@ -108,7 +108,15 @@ class VolumeShareSlippage(object): volume_share = min(direction * (desired_order) / event.volume, self.volume_limit) - simulated_amount = int(volume_share * event.volume * direction) + + if volume_share == self.volume_limit: + simulated_amount = \ + int(self.volume_limit * event.volume * direction) + else: + # we can fill the entire desired order + # let's not deal with floating-point errors + simulated_amount = desired_order + simulated_impact = (volume_share) ** 2 \ * self.price_impact * direction * event.price