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.

示例

>>> 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[源代码]

基类:CSVDataBase

Parses 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 object

  • The lines parameters (datetime, open, high ...) take numeric values

    A value of -1 indicates absence of that field in the CSV source

  • If time is present (parameter time >=0), the source contains separated fields for date and time, which will be combined

  • nullvalue

    Value 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 type int representing the number of seconds since Jan 1st, 1970

    • 2: The value is a Unix timestamp of a type float

    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()[源代码]

Start the Generic CSV data feed.

Sets up datetime conversion based on dtformat parameter.

frompackages = ()
packages = ()
class backtrader.feeds.csvgeneric.GenericCSV[源代码]

基类:CSVFeedBase

Generic CSV feed class.

Wrapper class for GenericCSVData feed functionality.

DataCls

GenericCSVData 的别名