Data for Multiple Securities
Dimitar Dimitrov last edited by
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,
import 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()
btdata feed object. In your script
datais a list of data feed objects, but not a single data feed object. Each data feed should be added to
adddatacall. Search the forum, look up the docs and articles, this was discussed tons of times and described well.