For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Data for Multiple Securities
-
Hi guys,
I am trying to add data for multiple securities. I thought using a for loop could help, but it looks like something is wrong. It sais that "data" is not defined. If i define it as a DataFrame it does not work either. Can you please help?
Many thanks and regards,
Dimitarimport backtrader as bt import datetime import pandas_datareader as wb import pandas as pd if __name__=="__main__": cerebro = bt.Cerebro() symbols = ["SPY", "IWM", "QQQ", "EFA", "EEM","VNQ", "LQD", "GLD", "SHY", "IEF", "TLT", "AGG"] for i in symbols: data[i] = bt.feeds.YahooFinanceData(dataname=i, fromdate=datetime.datetime(2000,1,1), todate=datetime.datetime.today()) cerebro.adddata(data) cerebro.run() cerebro.plot()
-
In
cerebro.adddata(data)
data
should bebt
data feed object. In your scriptdata
is a list of data feed objects, but not a single data feed object. Each data feed should be added tocerebro
using separateadddata
call. Search the forum, look up the docs and articles, this was discussed tons of times and described well.