【发布时间】:2020-01-14 10:21:09
【问题描述】:
请帮助解决这个错误,这是我在将自己的 csv 数据提供给反向交易者时遇到的错误。
数据样本如下
我是 python 和 python 社区的新手
错误:
C:\Python\python.exe C:\Users\harif\PycharmProjects\untitled\venv\learning\dataframe1.py 回溯(最近一次通话最后): 文件“C:\Users\harif\PycharmProjects\untitled\venv\learning\dataframe1.py”,第 32 行,在 fromdate=datetime(2, 10, 2016), ValueError: day is out of range for month
进程以退出代码 1 结束
import backtrader as bt
# Create a subclass of Strategy to define the indicators and logic
class SmaCross(bt.Strategy):
# list of parameters which are configurable for the strategy
params = dict(
pfast=10, # period for the fast moving average
pslow=30 # period for the slow moving average
)
def __init__(self):
sma1 = bt.ind.SMA(period=self.p.pfast) # fast moving average
sma2 = bt.ind.SMA(period=self.p.pslow) # slow moving average
self.crossover = bt.ind.CrossOver(sma1, sma2) # crossover signal
def next(self):
if not self.position: # not in the market
if self.crossover > 0: # if fast crosses slow to the upside
self.buy() # enter long
elif self.crossover < 0: # in the market & cross to the downside
self.close() # close long position
cerebro = bt.Cerebro() # create a "Cerebro" engine instance
# Create a data feed
data = bt.feeds.GenericCSVData(dataname=r'C:\Hard_Drive\Tick_Data\tickdata_2\sp.csv',
fromdate=datetime(2, 10, 2016),
todate=datetime(1, 10, 2019))
print(data)
# cerebro.adddata(data) # Add the data feed
# cerebro.addstrategy(SmaCross) # Add the trading strategy
# cerebro.run() # run it all
# cerebro.plot() # and plot it with a single command
【问题讨论】:
标签: python-3.x