backtrader.flt module

Filter Module - Data filtering for backtrader.

This module provides the base Filter class for data filtering operations. Filters can be applied to data feeds to modify or filter bars during backtesting.

Classes:

Filter: Base class for data filters.

示例

>>> class MyFilter(bt.Filter):
...     def next(self, data):
...         # Modify data bar
...         pass
class backtrader.flt.Filter[源代码]

基类:ParameterizedBase

Base class for data filters in backtrader.

Filters process data bars and can modify or reject them. Subclasses should override the next() method to implement custom filtering logic.

_firsttime

Tracks if this is the first call.

This class has been refactored from MetaParams to the new ParameterizedBase system for Day 36-38 of the metaprogramming removal project.

__init__(data_, **kwargs)[源代码]

Initialize the Filter.

参数:
  • data -- The data feed to filter.

  • **kwargs -- Additional keyword arguments for parameters.

__call__(data)[源代码]

Process a data bar through the filter.

参数:

data -- The data feed being filtered.

nextstart(data)[源代码]

Called on the first bar before filtering starts.

参数:

data -- The data feed being filtered.

备注

Override this method to perform one-time initialization.

next(data)[源代码]

Process each data bar.

参数:

data -- The data feed being filtered.

备注

Subclasses must override this method to implement filtering logic.