pandas www.example.com不支持TV数据馈送Backtesting.py?

kq0g1dla  于 2023-06-20  发布在  其他
关注(0)|答案(1)|浏览(97)

我尝试使用交易视图数据源进行回测分析,我遇到了一个问题,www.example.com只需要OHLC和(可选)Volume进行分析,我来这里寻求帮助:backtesting.py only need OHLC and (optionally) Volume for analysis, and I come here ask for help for the issue:

class RsiOscillator(Strategy):



ma_bound = ma
rsi_window = rsi

# Do as much initial computation as possible
def init(self):
    self.rsi = self.I(ta.rsi, pd.Series(self.data.Close), self.rsi_window)

# Step through bars one by one
# Note that multiple buys are a thing here
def next(self):
    if crossover(self.rsi > ma_bound):
        self.position.open()
    elif crossover(self.ma_bound, self.rsi):
        self.buy()

bt = Backtest(petr4_data, RsiOscillator, cash=10_000)
stats = bt.run()
bt.plot()

ValueError Traceback(most recent call last)Cell In [48],line 22 19 elif crossover(self.ma_bound,self.rsi):20 www.example.com()---> 22 bt = Backtest(petr4_data,RsiOscillator,cash = 10_000,commission =.002)23 stats = www.example.com()24 bt. plot()self.buy () ---> 22 bt = Backtest(petr4_data, RsiOscillator, cash=10_000, commission=.002) 23 stats = bt.run () 24 bt.plot()
File~\anaconda3\lib\site-packages\backtesting\backtesting.py:1067,in Backtest. init(self,data,strategy,cash,commission,margin,trade_on_close,hedging,exclusive_orders)1065 raise ValueError('OHLC data is empty')1066 if len(data. columns. intersection('Open ',' High','Low',' Close','Volume'})!= 5:-> 1067 raise ValueError("data must be a pandas. DataFrame with columns" 1068 "'Open','High',' Low','Close',and(optional)' Volume'")1069 if data 'Open ',' High','Low',' Close'. isnull(). values. any():1070 raise ValueError('Some OHLC values are missing(NaN).'1071'请使用df. dropna()或'1072'将这些行剥离,然后使用df. interpolate()或其他方法填充它们。
ValueError:data必须是pandas. DataFrame,列为“Open”、“High”、“Low”、“Close”和(可选)“Volume”
我试图使用的DF带有日期时间,OHLC和卷,我试图重新排序或删除,但py仍然不接受。
我该怎么办?

k0pti3hp

k0pti3hp1#

我在使用modin.pandas而不是pandas时遇到了同样的错误。之所以引发它,是因为此Assert会产生False:

len(petr4_data.columns.intersection({'Open', 'High', 'Low', 'Close', 'Volume'})) != 5

请执行这三个语句,并将每个输出发布在这里:

petr4_data.head()
print(petr4_data.dtypes)
print(type(petr4_data))

相关问题