How to load csv with unix timestamp as dates?
Serp last edited by Serp
I'm rellay new to algorithmic trading and will test around with this backtester, but to do this I need to know how to import a csv file not meeting the standard look.
The csv file looks like this:
unix timestamp, close, volume
What should I use for "dtformat" in GenericCSVData ?
And can I use parameters like "seperator" also in this GenericCSVData? I'm not sure, cause here https://www.backtrader.com/docu/datafeed.html it is written under the "Yahoo" feed, and I don't use Yahoo. So I'm not sure if those params are also valid for GenericCSVData.. ?
separatoris a common parameter to all
CSVbased data feeds. See: Docs - Data Feeds - Section: CSV Data Feeds Common parameters (the
Yahoomention is a leftover from the original version, to be corrected)
There is no support for a Unix timestamp right now, but the following should work
- Change the value of the token containing the Unix timestamp to a
datetimeand then back to a date string according to your chosen
- Store the changed token
- Go via
superto the original
_loadlinewhich will now have a string to parse in the given
This is probably the only needed thing in the subclass (untested)
def _loadline(self, linetokens): dtfield = linetokens[self.p.datetime] dtime = datetime.utcfromtimestamp(int(dtfield)) linetokens[self.p.datetime] = dtime.strftime(self.p.dtformat) return super(MyClassName, self)._loadline(linetokens)
The next release in any case will get some though as to best integrate that directly (probably by supporting passing an
Small release 22.214.171.124 issued which contains support code to do it without subclassing.
Added to the documentation
remroc last edited by