`pd.DateTimeIndex` 建议在 backtesting.py 库中
`pd.DateTimeIndex` is advised in backtesting.py library
我正在使用 backtesting.py 库 https://kernc.github.io/backtesting.py/doc/backtesting/index.html
这是什么错误?
用户警告:数据索引不是日期时间。假设简单的周期,但建议 'pd.DateTimeIndex'。 bt = Backtest(data, test2, cash=100000, commission=.002)
import pandas as pd
from backtesting import Strategy
from backtesting import Backtest
data = pd.read_csv('I:/algotrading/BTCUSDT.csv')
data.columns = ['Time','Open','High','Low','Close'];
class test2(Strategy):
def init(self):
pass
def next(self):
# OHLC
self.open = self.data.Open
self.high = self.data.High
self.low = self.data.Low
self.close = self.data.Close
if(self.close > self.open):
self.position.close()
self.buy()
elif(self.close < self.open):
self.position.close()
self.sell()
bt = Backtest(data, test2, cash=100000, commission=.002)
stats = bt.run()
print(stats)
bt.plot()
此代码需要 set_index。
data = pd.read_csv('BTCUSDT.csv', index_col='Time', parse_dates=True)
我正在使用 backtesting.py 库 https://kernc.github.io/backtesting.py/doc/backtesting/index.html
这是什么错误? 用户警告:数据索引不是日期时间。假设简单的周期,但建议 'pd.DateTimeIndex'。 bt = Backtest(data, test2, cash=100000, commission=.002)
import pandas as pd
from backtesting import Strategy
from backtesting import Backtest
data = pd.read_csv('I:/algotrading/BTCUSDT.csv')
data.columns = ['Time','Open','High','Low','Close'];
class test2(Strategy):
def init(self):
pass
def next(self):
# OHLC
self.open = self.data.Open
self.high = self.data.High
self.low = self.data.Low
self.close = self.data.Close
if(self.close > self.open):
self.position.close()
self.buy()
elif(self.close < self.open):
self.position.close()
self.sell()
bt = Backtest(data, test2, cash=100000, commission=.002)
stats = bt.run()
print(stats)
bt.plot()
此代码需要 set_index。
data = pd.read_csv('BTCUSDT.csv', index_col='Time', parse_dates=True)