backtrader.filters.datafilter module¶
Data Filter Module - Generic data filtering.
This module provides the DataFilter for filtering bars from a data source based on a callable function.
- Classes:
DataFilter: Filters bars based on a filter function.
Example
>>> data = bt.feeds.GenericCSVData(dataname='data.csv')
>>> data.addfilter(bt.filters.DataFilter(funcfilter=my_filter_func))
>>> cerebro.adddata(data)
- class backtrader.filters.datafilter.DataFilter[source]¶
Bases:
AbstractDataBaseThis class filters out bars from a given data source. In addition to the standard parameters of a DataBase, it takes a
funcfilterparameter which can be any callableLogic:
funcfilterwill be called with the underlying data sourceIt can be any callable
Return value
True: current data source bar values will be usedReturn value
False: current data source bar values will discard
- preload()[source]¶
Preload data from the underlying data source.
If the underlying data is not preloaded, loads it completely. Copies timeframe and compression settings from the source data after it has started (some sources do autodetection).
This method ensures all necessary data is available before processing.
- frompackages = ()¶
- packages = ()¶