From da9d599afdbbe85ac5de33f2a7c9481b5e2af822 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Tue, 9 Apr 2013 11:44:16 -0400 Subject: [PATCH] BUG: Fix floored results in trade commission calculations. When the cost basis was set to an integer the division in the calculation would floor down to the nearest integer. Ensuring that the number is a float during PerTrade's init will ensure that the calculation doesn't use integer division. Do the conversion to float in init rather than calculate, so that calling the builtin `float` is not added to any inner loops. --- zipline/finance/commission.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zipline/finance/commission.py b/zipline/finance/commission.py index 662144ed..b7737f05 100644 --- a/zipline/finance/commission.py +++ b/zipline/finance/commission.py @@ -48,7 +48,9 @@ class PerTrade(object): share count. $5.00 per trade is fairly typical of discount brokers. """ - self.cost = cost + # Cost needs to be floating point so that calculation using division + # logic does not floor to an integer. + self.cost = float(cost) def calculate(self, transaction): """