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/

    setenvironment

    General Code/Help
    2
    2
    1409
    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
      ajreinke last edited by

      I am totally new to backtrader and created this very simple code based on the code on the homepage.

      import numpy as np
      import pandas as pd
      import matplotlib.pyplot as plt
      import pandas_datareader
      import datetime
      import pandas_datareader.data as web
      start = datetime.datetime(2012, 1, 1)
      end = datetime.datetime(2017, 1, 1)
      data = web.DataReader("MSFT",'google',start,end)
      from datetime import datetime
      import backtrader as bt
      class SmaCross(bt.SignalStrategy):
      params = (('pfast', 10), ('pslow', 30),)
      def init(self):
      sma1,
      sma2 = bt.ind.SMA(period=self.p.pfast),
      bt.ind.SMA(period=self.p.pslow)
      self.signal_add(bt.SIGNAL_LONG, bt.ind.CrossOver(sma1, sma2))
      cerebro = bt.Cerebro()
      cerebro.adddata(data)

      I get this error:

      /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6-32 /Users/Admin/IdeaProjects/HellowWorld/HelloWorld.py
      Traceback (most recent call last):
      File "/Users/Admin/IdeaProjects/HellowWorld/HelloWorld.py", line 21, in <module>
      cerebro.adddata(data)
      File "/Users/Admin/Downloads/backtrader-master/backtrader/cerebro.py", line 758, in adddata
      data.setenvironment(self)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/generic.py", line 3081, in getattr
      return object.getattribute(self, name)
      AttributeError: 'DataFrame' object has no attribute 'setenvironment'
      Process finished with exit code 1

      At this point I'm not sure if it has to do with my version of Python 3 or not.. Has anyone else had this issue?

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

        As posted it is unreadable. Can you repost following the instructions at the top of the forum? (On every page)

        For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
        
        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
        $(document).ready(function () { app.coldLoad(); }); }