Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    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?

    General Code/Help
    2
    2
    681
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      AliAskari last edited by

      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!

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors