不好意思问这个问题!
我有一个CSV,看起来像:
date,volume,open,close,high,low
2020-11-12 13:38:00,100,1.85,1.85,1.85,1.85
2020-11-12 13:58:00,100,1.85,1.85,1.85,1.85
2020-11-12 14:03:00,100,1.85,1.85,1.85,1.85
...我试着利用后台交易者的数据:
import backtrader as bt
# from strategies import AverageTrueRange
# Instantiate Cerebro engine
cerebro = bt.Cerebro()
data = bt.feeds.GenericCSVData(
dataname='data/BBIG.csv',
timeframe=bt.TimeFrame.Minutes,
datetime=0,
high=4,
low=5,
open=2,
close=3,
volume=1,
)
cerebro.adddata(data)
cerebro.run()
cerebro.plot(
style='candlestick'
)但我不断地发现以下错误:
IndexError: list index out of range backtrader知道我做错什么了吗?
更新:
如果我将datetime更改为'-1‘,则会得到另一个错误:
ValueError: time data '1.85' does not match format '%Y-%m-%d %H:%M:%S'发布于 2022-04-26 09:45:17
尝试一下,将openinterest=-1添加到GenericCSVData中。
data = bt.feeds.GenericCSVData(
dataname='data/BBIG.csv',
timeframe=bt.TimeFrame.Minutes,
datetime=0,
high=4,
low=5,
open=2,
close=3,
volume=1,
openinterest=-1,
)我不熟悉背投。
但是我发现GenericCSVData的源代码中有以下代码:
params = (
('nullvalue', float('NaN')),
('dtformat', '%Y-%m-%d %H:%M:%S'),
('tmformat', '%H:%M:%S'),
('datetime', 0),
('time', -1),
('open', 1),
('high', 2),
('low', 3),
('close', 4),
('volume', 5),
('openinterest', 6),
)我只是尝试添加openinterest=-1并得到结果。
我认为类在默认情况下需要在BBIG.csv中使用openinterest列。
此外,我还有一个问题ImportError Cannot import name 'warnings' from 'matplotlib.dates是由https://stackoverflow.com/a/63974376/11004559解决的。
https://stackoverflow.com/questions/72010546
复制相似问题