[英]How to check fed data in backtrader?
import backtrader as bt
cerebro = bt.Cerebro()
data = bt.feeds.GenericCSVData(
dataname='data.csv',
# Do not pass values before this date
fromdate=dt.datetime(2000, 1, 1),
# Do not pass values after this date
todate=dt.datetime.now().date(),
datetime=0,
high=5,
low=6,
open=4,
close=8,
volume=10,
openinterest=-1
)
cerebro.adddata(data)
How to check wheater data is fed properly?如何检查小麦数据是否正确喂食? Such as print open
and close
?比如打印open
和close
? How to plot it (candle)?如何plot呢(蜡烛)?
You can see your data by printing a log from next
.您可以通过从next
打印日志来查看您的数据。 This is a standard setup I use.这是我使用的标准设置。
class TestPositions(bt.Strategy):
def __init__(self):
pass
def log(self, txt, dt=None):
""" Logging function fot this strategy"""
dt = dt or self.data.datetime[0]
if isinstance(dt, float):
dt = bt.num2date(dt)
print("%s, %s" % (dt, txt))
def print_signal(self):
self.log(
f"o {self.datas[0].open[0]:7.2f} "
f"h {self.datas[0].high[0]:7.2f} "
f"l {self.datas[0].low[0]:7.2f} "
f"c {self.datas[0].close[0]:7.2f} "
f"v {self.datas[0].volume[0]:7.0f} "
)
def next(self):
self.print_signal()
To plot you just use cerebro.plot()
after you run cerebro.对于 plot,您只需在运行 cerebro 后使用cerebro.plot()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.