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/

    Backtrader: AttributeError: 'Cerebro' object has no attribute '_exactbars'

    General Discussion
    2
    3
    49
    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.
    • B
      BryanPyHK last edited by

      I got an error "AttributeError: 'Cerebro' object has no attribute '_exactbars'. What is going wrong with my program?

      dataframe is like this:
      2edb3498-f16e-4bd8-8aab-b8cd24f31564-image.png
      My code is like this:

      dataframe = pd.DataFrame(stock_data, columns=[
      'date', 'open', 'high', 'low', 'close', 'volume'])
      dataframe["date"] = pd.to_datetime(dataframe["date"])

      class pandaDataFeed(bt.feeds.PandasData):
      #lines =('line_name/newparameter')
      params = (
      ('fromdate', dt.datetime(2005, 1, 1)),
      ('todate', dt.datetime.now()),
      ('dtformat', '%Y-%m-%d'),
      ('datetime', None),
      ('open', 'open'),
      ('high', 'high'),
      ('low', 'low'),
      ('close', 'close'),
      ('volume', 'volume')
      )

      data = pandaDataFeed(dataname=dataframe)
      cerebro.adddata(data)

      cerebro.run

      cerebro.plot()

      Pierre Cilliers 0 1 Reply Last reply Reply Quote 0
      • Pierre Cilliers 0
        Pierre Cilliers 0 @BryanPyHK last edited by

        @bryanpyhk

        Where to you initialise Cerebro? Add your entire code here then we can help

        B 1 Reply Last reply Reply Quote 0
        • B
          BryanPyHK @Pierre Cilliers 0 last edited by

          @pierre-cilliers-0

          The entire code is like that.

          backtrader_demo

          Test areas

          1. Data Feed from MySQL

          from future import(absolute_import, division,
          print_function, unicode_literals)

          import datetime
          import os.path
          import sys

          import backtrader as bt
          import numpy as np

          import mysql.connector
          import MySQLCredentials as mc

          import pandas
          from pprint import pprint

          Data to MySQL

          connection = mysql.connector.connect(
          host=mc.host,
          port=mc.port,
          user=mc.user,
          password=mc.password,
          database='stock_db')

          cerebro = bt.Cerebro()

          Datas are selected from TABLE in MySQL

          temp_table = "goog"

          CREATE db table "stock_temp"

          sql = """SELECT * FROM """ + temp_table + """;"""
          cursor.execute(sql)
          stock_data = cursor.fetchall()

          dataframe = pd.DataFrame(stock_data, columns=[
          'date', 'open', 'high', 'low', 'close', 'volume'])
          dataframe["date"] = pd.to_datetime(dataframe["date"])

          class pandaDataFeed(bt.feeds.PandasData):
          #lines =('line_name/newparameter')
          params = (
          ('fromdate', dt.datetime(2005, 1, 1)),
          ('todate', dt.datetime.now()),
          ('dtformat', '%Y-%m-%d'),
          ('datetime', None),
          ('open', 'open'),
          ('high', 'high'),
          ('low', 'low'),
          ('close', 'close'),
          ('volume', 'volume')
          )

          data = pandaDataFeed(dataname=dataframe)
          cerebro.adddata(data)

          cerebro.run

          cerebro.plot()

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