backtrader.filters.datafiller module¶
Data Filler Filter Module - Gap filling for data feeds.
This module provides the DataFiller for filling gaps in data feeds when bars are missing.
- Classes:
DataFiller: Fills gaps in data with specified values.
示例
>>> data = bt.feeds.GenericCSVData(dataname='data.csv')
>>> data.addfilter(bt.filters.DataFiller())
>>> cerebro.adddata(data)
- class backtrader.filters.datafiller.DataFiller[源代码]¶
-
This class will fill gaps in the source data using the following information bits from the underlying data source
timeframe and compression are to dimension the output bars
sessionstart and sessionend
If a data feed has missing bars in between 10:31 and 10:34 and the timeframe is minutes, the output will be filled with bars for minutes 10:32 and 10:33 using the closing price of the last bar (10:31)
Bars can be missing amongst other things because
- Params:
fill_price(def: None): if None (or evaluates to False), the closing price will be used, else the passed value (which can be for example 'NaN' to have a missing bar in terms of evaluation but present in terms of timefill_vol(def: NaN): used to fill the volume with missing barsfill_oi(def: NaN): used to fill the openinterest with missing bars
- __init__(*args, **kwargs)¶
Initialize a LineMultiple instance.
Sets up the internal state for managing multiple lines, including line type indicator, lines collection, clock reference, and line iterator tracking.
- Initializes:
_ltype: Line type indicator (None for base LineMultiple). lines: Collection of line objects (creates if not exists). _clock: Clock reference for synchronization. _lineiterators: Dictionary tracking registered lineiterators. _minperiod: Minimum period requirement (defaults to 1).
- start()[源代码]¶
Start the data filler.
Initializes the fill bars queue and data bar flag. This method is called when the data feed starts processing.
- preload()[源代码]¶
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 = ()¶