Backtrader Community

    • 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/

    Error in multi-core optimization

    General Code/Help
    4
    8
    704
    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.
    • Abhay Jindal
      Abhay Jindal last edited by

      1. I am getting the following error when I run multi-core optimization.
        AttributeError: Can't pickle local object 'GenericCSVData.start.<locals>.<lambda>'

      2. Also, how can I close all my open positions or get the total (realized+unrealized) profit after each optimization run? Currently, I am getting only the realized PnL using the following line in the stop function.
        round(self.broker.get_value(), 2)

      Anton Kozin vladisld 2 Replies Last reply Reply Quote 0
      • Anton Kozin
        Anton Kozin @Abhay Jindal last edited by

        @Abhay-Jindal said in Error in multi-core optimization:

        1. I am getting the following error when I run multi-core optimization.
          AttributeError: Can't pickle local object 'GenericCSVData.start.<locals>.<lambda>'

        I have the same problem. Could someone help with this issue?

        C 1 Reply Last reply Reply Quote 0
        • C
          chewbacca @Anton Kozin last edited by

          @Anton-Kozin Is the "raw" value a negative number?

          Anton Kozin 1 Reply Last reply Reply Quote 0
          • vladisld
            vladisld @Abhay Jindal last edited by

            @Abhay-Jindal said in Error in multi-core optimization:

            I am getting the following error when I run multi-core optimization.
            AttributeError: Can't pickle local object 'GenericCSVData.start.<locals>.<lambda>'

            It would be helpful if you could share your code.

            1 Reply Last reply Reply Quote 0
            • Anton Kozin
              Anton Kozin @chewbacca last edited by

              @chewbacca said in Error in multi-core optimization:

              @Anton-Kozin Is the "raw" value a negative number?

              What do you mean by the "raw" value? Could you make it more clear for me, please?

              I solved the problem by rewriting GenericCSVData class, i think that the reason why we get an error is that Pickle module has some problems with pickling lambda functions. Maybe its more better to use another pickling module (Dill for example) to deal with it.

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

                The lambda function inside the GenericCSVData is only used if the dtformat parameter is set to integer value (1 or 2) indicating that the datetime column contains timestamps instead of strings

                Is it really a case ? ( this is the reason I've asked to share the code )

                Anton Kozin 1 Reply Last reply Reply Quote 0
                • Anton Kozin
                  Anton Kozin @vladisld last edited by

                  @vladisld Yes, my data has timestamps in datetime column

                  data = bt.feeds.GenericCSVData(
                              dataname=datapath,
                              fromdate=datetime.datetime(2020, 8, 25),
                              todate=datetime.datetime(2020, 9, 8),
                              timeframe=bt.TimeFrame.Minutes,
                              compression=files[datapath],
                              dtformat=2,
                              reverse=False)
                  

                  Here is part of my code with data feed function. In fact, it won't help us much.

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

                    Issue was opened in backtrader2 project: https://github.com/backtrader2/backtrader/issues/39

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