Thank you ! The problem was half solved with your solution, it gave me 23:59:00 at each line instead of the real time, the solution was to add a :
timeframe=bt.TimeFrame.Minutes in the GenericCSVData parameters
Thanks again !
Thank you ! The problem was half solved with your solution, it gave me 23:59:00 at each line instead of the real time, the solution was to add a :
timeframe=bt.TimeFrame.Minutes in the GenericCSVData parameters
Thanks again !
Hi, when an order is initiated in the backtest, does backtrader use the next data lines OHLCV to know if the order could have passed ? How does it know ?
Thank you ! The problem was half solved with your solution, it gave me 23:59:00 at each line instead of the real time, the solution was to add a :
timeframe=bt.TimeFrame.Minutes in the GenericCSVData parameters
Thanks again !
Update : The problem with the comma was an Excel thing, when I copy pasted it on an Text Editor there were commas at each line.
After that, I got an IndexError: array assignment index out of range, which was solved by adding more data, thanks to this thread : https://community.backtrader.com/topic/407/indexerror-array-assignment-index-out-of-range/3
My last problem is that I don't know how to show Hours-Minutes-Seconds when I launch the script, my log function is :
def log(self, txt, dt=None):
''' Logging function fot this strategy'''
dt = dt or self.datas[0].datetime.date(0)
print('%s, %s' % (dt.isoformat(), txt))
Backtrader shows me :
2019-06-30, Close, 295.65
2019-06-30, Close, 295.65
2019-06-30, Close, 295.85
But how can I have H-M-S too in the log function ?
@backtrader Yes that is the problem, I don't understand why the quote is here. I just followed the documentation of GenericCSVData, do you have an idea about why ?
Hi, I have a problem creating my own DataFeed
I used GenericCSVData to use my CSV file on Backtrader, but I get this error :
ValueError: time data '"2019-06-30T15-10-00' does not match format '%Y-%m-%dT%H-%M-%S'
Which doesn't make sense because it seems to be right.
I succeeded to make it working with a CSV years-months-day only, but not with hours-minutes-seconds, I don't understand why ? I think the problem might be this " which is near the 2019 in the error message, but I don't know how to erase it.
Here is the code :
modpath = os.path.dirname(os.path.abspath(sys.argv[0]))
datapath = os.path.join(modpath, 'backtrader/datas/yhoo.csv')
# Create a Data Feed
data = btfeed.GenericCSVData(
dataname=datapath,
nullvalue=0.0,
dtformat=('%Y-%m-%d'),
tmformat=('%H-%M-%S'),
datetime=0,
time=1,
open=2,
high=3,
low=4,
close=5,
volume=6,
openinterest=-1
)
Here is my CSV : https://ibb.co/sF47WV4
And here is the full error I get :
Starting Portfolio Value: 10000.00
Traceback (most recent call last):
File "G22.py", line 151, in <module>
cerebro.run()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/backtrader-1.9.70.122-py3.7.egg/backtrader/cerebro.py", line 1127, in run
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/backtrader-1.9.70.122-py3.7.egg/backtrader/cerebro.py", line 1212, in runstrategies
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/backtrader-1.9.70.122-py3.7.egg/backtrader/feed.py", line 688, in preload
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/backtrader-1.9.70.122-py3.7.egg/backtrader/feed.py", line 479, in load
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/backtrader-1.9.70.122-py3.7.egg/backtrader/feed.py", line 710, in _load
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/backtrader-1.9.70.122-py3.7.egg/backtrader/feeds/csvgeneric.py", line 114, in _loadline
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/_strptime.py", line 577, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/_strptime.py", line 359, in _strptime
(data_string, format))
ValueError: time data '"2019-06-30T15-10-00' does not match format '%Y-%m-%dT%H-%M-%S'