Filters
This functionality is a relatively late addition to backtrader and had to be fitted to the already existing internals. This makes it to be not as flexible and 100% feature full as wished, but it can still serve the purpose in many cases.
这个功能是对backtrader一个相对较晚的添加,必须在现有的内部实现。这使得它不像预期的那样灵活和100%的功能,但它仍然可以在许多情况下达到目的。
Although the implementation tried to allow plug and play filter chaining, the pre-existing internals made it difficult to ensure that could always be achieved. As such, some filters may be chained and some others may not.
Purpose
Transform the values provided by a data feed to deliver a different data feedResampling (cerebro.resampledata
)
Here the filter transforms the timeframe
and compression
of the incoming data feed. For example:
在这里,过滤器转换传入数据提要的时间框架和压缩。例如
(Seconds, 1) -> (Days, 1)
That means that the original data feed is delivery bars with a resolution of 1 Second. The Resampling filter intercepts the data and buffers it until it can deliver a 1 Day bar. This will happen when a 1 Second bar from the next day is seen.
Replaying (cerebro.replaydata
)
For the same timeframes as above, the filter would use the 1 Second resolution bars to rebuild the 1 Day bar.
That means that the 1 Day bar is delivered as many times as 1 Second bars are seen, updated to contain the latest information.
This simulates, for example, how an actual trading day has developed.
对于与上述相同的时间段,过滤器将使用1秒分辨率条重建1天条形图。
这意味着,1天的条形图与1秒的条形图显示的次数一样多,更新后包含最新的信息。
例如,这模拟了实际交易日的发展情况。
Note
The length of the data, len(data)
and therefore the length of the strategy remain unchanged as long as the day doesn’t change.