Indicator might be wrong when applying filter on backtesting data
robin2008 opened this issue · comments
The backtest
method supports between_time
and days
to filter data
between_time: ``tuple[str, str]`` of times of day e.g.
('9:30', '16:00') used to filter the backtesting data
(inclusive).
days: Days (e.g. ``"mon"``, ``"tues"`` etc.) used to filter the
backtesting data.
And when walkforward
, then data sources seems to be filtered first and then computing indicators:
pybroker/src/pybroker/strategy.py
Lines 1204 to 1222 in 6b659b5
It means that the indicator calculation is based on the filtered discrete BAR data, although this could reduce the caculation, but I guess this is not an expected behavior as most of the indicators are senstive to the continuity of time series data.
Hi @robin2008,
This is the intended behavior. By default, you should compute indicators on the same data that you execute with your strategy.
If you want to compute indicators on unfiltered data, then you can omit the between_time
filter and instead filter using ctx.dt in your execution function.