setenvironment
-
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 1At 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?
-
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/