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

How to modify header names in the csv output of WriterFile?



  • By default the csv writer uses the indicator class name as the name of the header in the csv output, i.e.

    def __init__(self):
        self.fast_ma = bt.indicators.SimpleMovingAverage(self.datas[0], period=self.params.fast_ma)
        self.slow_ma = bt.indicators.SimpleMovingAverage(self.datas[0], period=self.params.slow_ma)
        self.fast_ma.csv = True
        self.slow_ma.csv = True
    

    in the csv file generated by

    cerebro.addwriter(bt.WriterFile, csv=True, out='some_file.csv')
    

    I am getting two columns with the same name SimpleMovingAverage. The same thing is valid for the plot but there is an extra plotname parameter that can be used to change the name of an indicator in plots

    self.fast_ma = bt.indicators.SimpleMovingAverage(self.datas[0], period=self.params.fast_ma, plotname='fast_ma')
    

    but this parameter doesn't modify the header name in the csv file.

    I looked in the code and there doesn't seem to be a method to do so. Is this supported?

    Thanks!


  • administrators

    There is currently no provision to modify the headers. Adding the parameter values was deemed excessive (the size of the output would have been gigantic)

    What you can count on: the indicators are added in the same order you instantiated them.