vn.py量化社区
By Traders, For Traders.
Member
avatar
加入于:
帖子: 25
声望: 0

(vnpy207) C:\ProgramData\Miniconda3\vnpy2.0.7>python run.py
Exception in thread Thread-5:
Traceback (most recent call last):
File "C:\ProgramData\Miniconda3\envs\vnpy207\lib\threading.py", line 926, in _
bootstrap_inner
self.run()
File "C:\ProgramData\Miniconda3\envs\vnpy207\lib\threading.py", line 870, in r
un
self._target(self._args, **self._kwargs)
File "C:\ProgramData\Miniconda3\vnpy2.0.7\vnpy\app\cta_backtester\engine.py",
line 163, in run_backtesting
self.result_df = engine.calculate_result()
File "C:\ProgramData\Miniconda3\vnpy2.0.7\vnpy\app\cta_strategy\backtesting.py
", line 317, in calculate_result
pre_close, start_pos, self.size, self.rate, self.slippage
File "C:\ProgramData\Miniconda3\vnpy2.0.7\vnpy\app\cta_strategy\backtesting.py
", line 1115, in calculate_pnl
turnover = trade.price
trade.volume * size
OverflowError: int too large to convert to float

跟踪到代码:
这里怎么修改?改为浮点型吗?

def calculate_pnl(

        turnover = trade.price * trade.volume * size
Administrator
avatar
加入于:
帖子: 2453
声望: 103

请检查是否size或者交易数量设置过大吧,float默认支持的位数还是很高的

Member
avatar
加入于:
帖子: 25
声望: 0

我是固定1手回测的,turnover 是整型, trade.price 和 trade.volume都是浮点型,size是整型,是不是可能溢出呢?

Administrator
avatar
加入于:
帖子: 2453
声望: 103

在这里catch到异常后,打印trade.price/trade.volume的数值,看看是多少?

© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3