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/

    Including data from a database

    General Code/Help
    3
    3
    1782
    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.
    • P
      predri last edited by

      I try to use time series from a SQL Database which I created. The problem is that this pandas.core.frame.DataFrame can not be used for the trading strategy. There is the following output:


      AttributeError Traceback (most recent call last)
      <ipython-input-18-482559afee4d> in <module>()
      18
      19
      ---> 20 cerebro.adddata(data0)
      21
      22 results=cerebro.run()

      C:\ProgramData\Anaconda2\lib\site-packages\backtrader\cerebro.pyc in adddata(self, data, name)
      756
      757 data._id = next(self._dataid)
      --> 758 data.setenvironment(self)
      759
      760 self.datas.append(data)

      C:\ProgramData\Anaconda2\lib\site-packages\pandas\core\generic.pyc in getattr(self, name)
      2670 if name in self._info_axis:
      2671 return self[name]
      -> 2672 return object.getattribute(self, name)
      2673
      2674 def setattr(self, name, value):

      AttributeError: 'DataFrame' object has no attribute 'setenvironment'

      B 1 Reply Last reply Reply Quote 0
      • L
        Laurent Michelizza last edited by

        It would be helpful to add some of your code for debugging. I don't load data from a database but from a csv file that I load in a panda DataFrame, so I suppose that there's a little issue along the way which we can't really find without any code.

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

          @predri said in Including data from a database:

          AttributeError: 'DataFrame' object has no attribute 'setenvironment'

          Yes. You cannot pass a DataFrame to cerebro and expect things to work.

          As pointed out by @Laurent-Michelizza, showing us what you do could be helpful.

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