0

我正在尝试使用 backtrader 制作一个 python 回测机器人,但我一直有这个错误,这是我的代码

import datetime as dt
from strategies import TestStrategy
import os.path
import sys

cerebro = backtrader.Cerebro()
cerebro.broker.setcash(50.0)

data = backtrader.feeds.YahooFinanceCSVData(
    dataname='DTST.csv',
    # Do not pass values before this date
    fromdate=dt.datetime(2020, 8, 31),
    # Do not pass values before this date
    todate=dt.datetime(2021, 8, 30),
    # Do not pass values after this date
    reverse=False)


cerebro.adddata(data)
cerebro.addstrategy(TestStrategy)
print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())

cerebro.run()

print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())```


4

0 回答 0