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/

    Exporting the generated backtest result in csv format.

    General Discussion
    4
    6
    74
    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.
    • Abhishek Agrawal
      Abhishek Agrawal last edited by

      Exporting data in csv.
      Hey guys can u please help me on how to export the data of trades and all the details printed in the terminal to csv files.
      I want to export all my trades in csv files
      @run-out @ab_trader @backtrader

      1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld last edited by

        Take a look at the tradelist analyzer: https://community.backtrader.com/topic/1274/closed-trade-list-including-mfe-mae-analyzer

        1 Reply Last reply Reply Quote 0
        • A
          ab_trader last edited by

          IIRC everything printed to terminal by python script can be saved to text file when you run script:

          python your script.py > results.txt
          
          1 Reply Last reply Reply Quote 0
          • A
            ab_trader last edited by

            You may want to try Writer also
            https://www.backtrader.com/docu/writer/

            1 Reply Last reply Reply Quote 0
            • Abhishek Agrawal
              Abhishek Agrawal last edited by

              Thanks a lot guys. You guys are genius with Backtrader.
              I would like to know that can remove some extra details from csv file when using Writer.

              Like pnl ,tickers etc

              run-out 1 Reply Last reply Reply Quote 0
              • run-out
                run-out @Abhishek Agrawal last edited by

                @Abhishek-Agrawal said in Exporting the generated backtest result in csv format.:

                I would like to know that can remove some extra details from csv file when using Writer.
                Like pnl ,tickers etc

                If you are comfortable using pandas, you can use the following with the TradeList analyzer:

                import pandas as pd
                
                ...
                cerebro.addanalyzer(TradeList, _name="trade_list")
                strat = cerebro.run(tradehistory=True)
                ...
                
                # Save trade list.
                trade_list = strat[0].analyzers.getbyname("trade_list").get_analysis()
                df = pd.DataFrame(trade_list)
                df = df.drop(['pnl', 'pnl/bar', 'ticker'], axis=1)
                df.to_csv("trade_list.csv")
                
                1 Reply Last reply Reply Quote 2
                • 1 / 1
                • First post
                  Last post
                Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
                $(document).ready(function () { app.coldLoad(); }); }