From 690278127ce659560bc9900dc8f6064191c0b67c Mon Sep 17 00:00:00 2001 From: edtechre Date: Fri, 17 Mar 2023 12:36:37 -0700 Subject: [PATCH] Guarantee exit dates are in sorted order. --- src/pybroker/strategy.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pybroker/strategy.py b/src/pybroker/strategy.py index 279207b..e50702a 100644 --- a/src/pybroker/strategy.py +++ b/src/pybroker/strategy.py @@ -1208,9 +1208,11 @@ def _run_walkforward( for sym in exec.symbols: sessions[ExecSymbol(exec.id, sym)] = {} if self._config.exit_on_last_bar: - exit_dates[sym] = df[df[DataCol.SYMBOL.value] == sym][ + sym_dates = df[df[DataCol.SYMBOL.value] == sym][ DataCol.DATE.value - ].values[-1] + ].values + sym_dates.sort() + exit_dates[sym] = sym_dates[-1] for train_idx, test_idx in self.walkforward_split( df=df, windows=windows,