backtrader.feeds.csvgeneric module¶
Generic CSV Data Feed Module - CSV file parsing.
This module provides the GenericCSVData feed for parsing CSV files with customizable column mappings for backtesting.
- Classes:
GenericCSVData: Parses CSV files with configurable column mappings.
Example
>>> data = bt.feeds.GenericCSVData(
... dataname='data.csv',
... datetime=0,
... open=1,
... high=2,
... low=3,
... close=4,
... volume=5
... )
>>> cerebro.adddata(data)
- class backtrader.feeds.csvgeneric.GenericCSVData[source]¶
Bases:
CSVDataBaseParses a CSV file according to the order and field presence defined by the parameters
Specific parameters (or specific meaning):
dataname: The filename to parse or a file-like objectThe lines parameters (datetime, open, high …) take numeric values
A value of -1 indicates absence of that field in the CSV source
If
timeis present (parameter time >=0), the source contains separated fields for date and time, which will be combinednullvalueValue that will be used if a value which should be there is missing (the CSV field is empty)
dtformat: Format used to parse the datetime CSV field. See the python strptime/strftime documentation for the format.If a numeric value is specified, it will be interpreted as follows
1: The value is a Unix timestamp of a typeintrepresenting the number of seconds since Jan 1st, 19702: The value is a Unix timestamp of a typefloat
If a callable is passed
It will accept a string and return a datetime.datetime python instance
tmformat: Format used to parse the time CSV field if “present” (the default for the “time” CSV field is not to be present)
- __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()[source]¶
Start the Generic CSV data feed.
Sets up datetime conversion based on dtformat parameter.
- frompackages = ()¶
- packages = ()¶
- class backtrader.feeds.csvgeneric.GenericCSV[source]¶
Bases:
CSVFeedBaseGeneric CSV feed class.
Wrapper class for GenericCSVData feed functionality.
- DataCls¶
alias of
GenericCSVData