From 98ea3dd12bcbd9d61f15914b585d6f5ec813cb09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Rodr=C3=ADguez=20Chatruc?= Date: Mon, 16 Mar 2020 12:12:49 -0300 Subject: [PATCH] Fixed exit costs being computed incorrectly and filter tests not working --- backtester/backtester.py | 4 ++-- backtester/test/datahandler/test_filter.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backtester/backtester.py b/backtester/backtester.py index 3200397..07392b0 100644 --- a/backtester/backtester.py +++ b/backtester/backtester.py @@ -371,7 +371,7 @@ class Backtest: self._options_inventory = self._options_inventory.append(entries, ignore_index=True) self.trade_log = self.trade_log.append(entries, ignore_index=True) - self.current_cash += options_allocation - total_costs[0] * qty[0] + self.current_cash += options_allocation - np.sum(entries['totals']['cost'] * entries['totals']['qty']) def _execute_option_exits(self, date, options): """Exits option positions according to `self._options_strategy`. @@ -395,7 +395,7 @@ class Backtest: filter_masks.append(flt(current_options_quotes[i]) | missing_contracts_mask) fields = self._signal_fields((~leg.direction).value) - current_options_quotes[i] = current_options_quotes[i].reindex(columns=fields.keys()) + current_options_quotes[i] = current_options_quotes[i].reindex(columns=fields.values()) current_options_quotes[i].rename(columns=fields, inplace=True) current_options_quotes[i].columns = pd.MultiIndex.from_product([[leg.name], current_options_quotes[i].columns]) diff --git a/backtester/test/datahandler/test_filter.py b/backtester/test/datahandler/test_filter.py index 76b401f..c334b7b 100644 --- a/backtester/test/datahandler/test_filter.py +++ b/backtester/test/datahandler/test_filter.py @@ -1,4 +1,4 @@ -from backtester.datahandler import Field +from backtester.datahandler.schema import Field def test_strike_eq_100():