Problem loading genericCSVdata
-
Hi,
Trying to load some csv data,if __name__ == '__main__': cerebro = bt.Cerebro() # Add a strategy cerebro.addstrategy(TestStrategy) # Datas are in a subfolder of the samples. Need to find where the script is # because it could have been called from anywhere modpath = os.path.dirname(os.path.abspath(sys.argv[0])) datapath = os.path.join(modpath, 'data/gbpusd 1min data.csv') # Create a Data Feed data = btfeeds.GenericCSVData( dataname= datapath, fromdate=datetime.datetime(2017, 1, 1), todate=datetime.datetime(2017,1 , 2), nullvalue=0.0, dtformat=('%d.%m.%Y %H:%M:%S.%f'), datetime=0, high=1, low=2, open=3, close=4, volume=5, openinterest=-1) print(data.head()) print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue()) cerebro.run() print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
Getting Output:
AttributeError: 'Lines_LineSeries_DataSeries_OHLC_OHLCDateTime_Abst' object has no attribute 'head'
Does it mean the data has not loaded? Where did I go wrong(i did load btfeeds, datetime etc in the begining).
Thanks -
Since no one else has commented yet, I'll take a stab at it...
My first question is: "Is .head a valid attribute/method for GenericCSVData?" A quick search of the docs does not show anything, and I get the same error if I try it in my program. I suspect this is your problem. What are you trying to print?
Second, can python/backtrader parse file names with spaces in them? I've never tried it, so I'm not sure.
-
@mahbubk9 said in Problem loading genericCSVdata:
print(data.head())
@Ninjaneer is right on spot. What
head()
is supposed to mean is unknown but is for sure not part of the platform and not an attribute of the data feed, hence the error that exactly says that.@mahbubk9 said in Problem loading genericCSVdata:
Does it mean the data has not loaded? Where did I go wrong(i did load btfeeds, datetime etc in the begining).
Apparently it did actually load because there is no complain/exception indicating the contrary.
@Ninjaneer said in Problem loading genericCSVdata:
Second, can python/backtrader parse file names with spaces in them? I've never tried it, so I'm not sure.
Change the
separator
parameter to the data feed to be a space. At least it's worth a try. See Docs - Data Feeds Reference -
Thanks for the clarification.