backtrader.feeds.pandafeed module¶
Pandas Data Feed Module - Pandas DataFrame integration.
This module provides data feeds for loading market data from Pandas DataFrames.
- Classes:
PandasDirectData: Uses DataFrame tuples as data source. PandasData: Uses DataFrame columns as data source.
Example
>>> import pandas as pd
>>> df = pd.read_csv('data.csv')
>>> data = bt.feeds.PandasData(dataname=df)
>>> cerebro.adddata(data)
- class backtrader.feeds.pandafeed.PandasDirectData[source]¶
Bases:
DataBaseUses a Pandas DataFrame as the feed source, iterating directly over the tuples returned by “itertuples”.
This means that all parameters related to lines must have numeric values as indices into the tuples
Note
The
datanameparameter is a Pandas DataFrameA negative value in any of the parameters for the Data lines indicates it’s not present in the DataFrame it is
- datafields = ['datetime', 'open', 'high', 'low', 'close', 'volume', 'openinterest']¶
- __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).
- frompackages = ()¶
- packages = ()¶
- class backtrader.feeds.pandafeed.PandasData[source]¶
Bases:
DataBaseUses a Pandas DataFrame as the feed source, using indices into column names (which can be “numeric”)
This means that all parameters related to lines must have numeric values as indices into the tuples
Params:
nocase(default True) case-insensitive match of column names
Note
The
datanameparameter is a Pandas DataFrameValues possible for datetime
None: the index contains the datetime
-1: no index, autodetect column
>= 0 or string: specific colum identifier
For other lines parameters
None: column not present
-1: autodetect
>= 0 or string: specific colum identifier
- datafields = ['datetime', 'open', 'high', 'low', 'close', 'volume', 'openinterest']¶
- __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).
- frompackages = ()¶
- packages = ()¶