For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Formatting of output csv from bt.Writer



  • I am trying to collect some data points during backtest that I can process using Pandas. I am using bt.Writer to output my data feeds and indicators to a csv but the format is not very friendly to importing using pd.read_csv due to multiple duplicated column headers and extra lines that are not part of the csv.

    Is there a way to custom format the output of the csv from bt.Writer?


  • administrators

    @sfkiwi said in Formatting of output csv from bt.Writer:

    and indicators to a csv but the format is not very friendly to importing using pd.read_csv

    It was not meant to be pure csv output.

    @sfkiwi said in Formatting of output csv from bt.Writer:

    Is there a way to custom format the output of the csv from bt.Writer?

    Yes, subclassing Writer and customizing the output.



  • In order to read in as a dataframe what I really want is a row of headers that contain the labels for each data point and then each subsequent row represents the value at a point in time.

    I looked into subclassing bt.Writer but the Header and each line of values comes pre-populated from the Strategy and DataSeries classes and the way that it is formatted doesn't provide anyway of knowing where each indicator starts and ends.

    What I ended up doing instead was to override the getWriterHeaders and getWriterValues function in the Strategy. This allowed me to format the header and the values in the way I wanted.

    This works for the indicators and any data coming from the Strategy, however it doesn't solve the problem for the data series. I can't see any easy way to override these functions for the data series.