GenericCSVData loading: alternative way to load partial data?



  • HEllo!
    My CSV data files are ~300K points length, e.g. full-year 1 minute bar EURUSD pair.
    For multiply backtest runs of a single strategy I need to randomly draw 2-4 days long ( ~3000 - 6000 points) sub-series from these files.
    One method to do it is use documented <fromdate> - <todate> method which gives only about 360 random entry points.
    Is there a method to define arbitrary start/stop datafeed points by array-like indexing?


  • administrators

    fromdate and todate can be actual datetime.datetime instances, which allows you to have a fine grained resolution down to microseconds to select where the actual management of the stream starts and stops. This should allow you to select the exact points you want to test. It may be slow in any case.

    @Андрей-Музыкин said in GenericCSVData loading: alternative way to load partial data?:

    Is there a method to define arbitrary start/stop datafeed points by array-like indexing?

    No. This is something that people look for because they are expecting a pandas like approach. That would actually prevent having data sources with unknown length (and therefore live data feeds). And that's why the indexing of 0 and -1 was chosen as it was chosen (See Docs - Platform Concepts)

    If you are purely backtesting you can do the following:

    • Load your data into a pandas.Dataframe
    • Use pandas indexing and slicing techniques to reduce the dataset to your desired values
    • Load the data stream into backtrader using PandasData


  • @backtrader - got it, thank you.


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.