VeighNa量化社区
你的开源社区量化交易平台
yuanhuei's Avatar
Member
离线
84 帖子
声望: 2

是vnpy\examples\vn_trader下的run.py吗?这个我跑起来的是vn_trader

设置一个断点调试一下就知道了,只有自己最了解自己写的代码

因为是把策略拷贝到专门的目录C:\Users\yuanhui\strategies下面,在vnpy\app\cta_strategy下面的策略文件中设置断点没用了。

请问有什么方法可以来设置调试

请教一下,CtaTemplate模块也是可以一个策略创建多个针对不同品种的实例吧,那也是实现了组合策略的结果吧。
是不是Portfolio Strategy可以在一份代码内部统一进行调度处理,灵活性更大了。而CtaTemplate的多个实例是分开跑的,没有统一的调度和处理

增加了一个参数,可以计算了。一个是布林线窗口,一个是宽度。
setting.add_parameter("bollWindow15min", 25, 30, 1)
setting.add_parameter("entryDev15min", 2, 3, 1)

最后的结果如下,这个结果对应选择的布林窗口长度和宽度是多少?是不是没有给出来

gen nevals mean std min max
0 100 [0.24559157] [0.05948886] [0.14323401] [0.31978118]
1 100 [0.29981093] [0.02575085] [0.24949448] [0.31978118]
2 100 [0.31978118] [0.] [0.31978118] [0.31978118]
3 100 [0.31978118] [0.] [0.31978118] [0.31978118]
4 100 [0.31978118] [0.] [0.31978118] [0.31978118]
5 100 [0.31978118] [0.] [0.31978118] [0.31978118]
6 100 [0.31978118] [0.] [0.31978118] [0.31978118]
7 100 [0.31978118] [0.] [0.31978118] [0.31978118]
8 100 [0.31978118] [0.] [0.31978118] [0.31978118]
9 100 [0.31978118] [0.] [0.31978118] [0.31978118]
10 100 [0.31978118] [0.] [0.31978118] [0.31978118]
11 100 [0.31978118] [0.] [0.31978118] [0.31978118]
12 100 [0.31978118] [0.] [0.31978118] [0.31978118]
13 100 [0.31978118] [0.] [0.31978118] [0.31978118]
14 100 [0.31978118] [0.] [0.31978118] [0.31978118]
15 100 [0.31978118] [0.] [0.31978118] [0.31978118]
16 100 [0.31978118] [0.] [0.31978118] [0.31978118]
17 100 [0.31978118] [0.] [0.31978118] [0.31978118]
18 100 [0.31978118] [0.] [0.31978118] [0.31978118]
19 100 [0.31978118] [0.] [0.31978118] [0.31978118]
20 100 [0.31978118] [0.] [0.31978118] [0.31978118]
21 100 [0.31978118] [0.] [0.31978118] [0.31978118]
22 100 [0.31978118] [0.] [0.31978118] [0.31978118]
23 100 [0.31978118] [0.] [0.31978118] [0.31978118]
24 100 [0.31978118] [0.] [0.31978118] [0.31978118]
25 100 [0.31978118] [0.] [0.31978118] [0.31978118]
26 100 [0.31978118] [0.] [0.31978118] [0.31978118]
27 100 [0.31978118] [0.] [0.31978118] [0.31978118]
28 100 [0.31978118] [0.] [0.31978118] [0.31978118]
29 100 [0.31978118] [0.] [0.31978118] [0.31978118]
30 100 [0.31978118] [0.] [0.31978118] [0.31978118]
2021-01-14 09:41:30.001315 遗传算法优化完成,耗时1954秒

setting.add_parameter("bollWindow15min", 25, 30, 1)

用的是布林线窗口参数,开始25,结束30,步进1. 逻辑上应该没有问题啊

这个会是我策略的原因吗?还是bug.
description

File "c:\Users\yuanh\Documents\GitHub\vnpy\examples\add_by_yh\backtesting_yh.py", line 45, in <module>
engine.run_ga_optimization(setting)
 File "c:\Users\yuanh\Documents\GitHub\vnpy\vnpy\app\cta_strategy\backtesting.py", line 760, in run_gaoptimization
halloffame=hof
File "C:\vnstudio\Lib\site-packages\deap\algorithms.py", line 316, in eaMuPlusLambda
offspring = varOr(population, toolbox, lambda
, cxpb, mutpb)
File "C:\vnstudio\Lib\site-packages\deap\algorithms.py", line 234, in varOr
ind1, ind2 = toolbox.mate(ind1, ind2)
File "C:\vnstudio\Lib\site-packages\deap\tools\crossover.py", line 51, in cxTwoPoint
cxpoint2 = random.randint(1, size - 1)
File "C:\vnstudio\Lib\random.py", line 222, in randint
return self.randrange(a, b+1)
File "C:\vnstudio\Lib\random.py", line 200, in randrange
raise ValueError("empty range for randrange() (%d,%d, %d)" % (istart, istop, width))

builtins.ValueError: empty range for randrange() (1,1, 0)

之前我是2.1.3版本的,是弹出一个界面显示的,我升级到2.1.8,现在就没有弹出界面,而是调出了浏览器,但是显示不出来图像

浏览器输出:
http://127.0.0.1:57254/
嗯… 无法访问此页面127.0.0.1 已拒绝连接。
在 Web 中搜索 127 0 0 1
ERR_CONNECTION_REFUSED

这是啥原因

于是自己安装plotly,但是总是不成功,是什么原因,如何解决呢?

(VN Studio) C:\vnstudio>pip install plotly==4.14.2
Collecting plotly==4.14.2
Downloading plotly-4.14.2-py2.py3-none-any.whl (13.2 MB)
|█ | 419 kB 2.5 kB/s eta 1:23:32ERROR: Exception:
Traceback (most recent call last):
File "c:\vnstudio\lib\site-packages\pip_vendor\urllib3\response.py", line 438, in _error_catcher
yield
File "c:\vnstudio\lib\site-packages\pip_vendor\urllib3\response.py", line 519, in read
data = self._fp.read(amt) if not fp_closed else b""
File "c:\vnstudio\lib\site-packages\pip_vendor\cachecontrol\filewrapper.py", line 62, in read
data = self.__fp.read(amt)
File "c:\vnstudio\lib\http\client.py", line 447, in read
n = self.readinto(b)
File "c:\vnstudio\lib\http\client.py", line 491, in readinto
n = self.fp.readinto(b)
File "c:\vnstudio\lib\socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "c:\vnstudio\lib\ssl.py", line 1052, in recv_into
return self.read(nbytes, buffer)
File "c:\vnstudio\lib\ssl.py", line 911, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\vnstudio\lib\site-packages\pip_internal\cli\base_command.py", line 224, in _main
status = self.run(options, args)
File "c:\vnstudio\lib\site-packages\pip_internal\cli\req_command.py", line 180, in wrapper
return func(self, options, args)
File "c:\vnstudio\lib\site-packages\pip_internal\commands\install.py", line 321, in run
reqs, check_supported_wheels=not options.target_dir
File "c:\vnstudio\lib\site-packages\pip_internal\resolution\resolvelib\resolver.py", line 122, in resolve
requirements, max_rounds=try_to_avoid_resolution_too_deep,
File "c:\vnstudio\lib\site-packages\pip_vendor\resolvelib\resolvers.py", line 445, in resolve
state = resolution.resolve(requirements, max_rounds=max_rounds)
File "c:\vnstudio\lib\site-packages\pip_vendor\resolvelib\resolvers.py", line 339, in resolve
failure_causes = self._attempt_to_pin_criterion(name, criterion)
File "c:\vnstudio\lib\site-packages\pip_vendor\resolvelib\resolvers.py", line 207, in _attempt_to_pin_criterion
criteria = self._get_criteria_to_update(candidate)
File "c:\vnstudio\lib\site-packages\pip_vendor\resolvelib\resolvers.py", line 198, in _get_criteria_to_update
for r in self._p.get_dependencies(candidate):
File "c:\vnstudio\lib\site-packages\pip_internal\resolution\resolvelib\provider.py", line 172, in get_dependencies
for r in candidate.iter_dependencies(with_requires)
File "c:\vnstudio\lib\site-packages\pip_internal\resolution\resolvelib\provider.py", line 171, in <listcomp>
r
File "c:\vnstudio\lib\site-packages\pip_internal\resolution\resolvelib\candidates.py", line 257, in iter_dependencies
requires = self.dist.requires() if with_requires else ()
File "c:\vnstudio\lib\site-packages\pip_internal\resolution\resolvelib\candidates.py", line 239, in dist
self._prepare()
File "c:\vnstudio\lib\site-packages\pip_internal\resolution\resolvelib\candidates.py", line 226, in _prepare
dist = self._prepare_distribution()
File "c:\vnstudio\lib\site-packages\pip_internal\resolution\resolvelib\candidates.py", line 319, in _prepare_distribution
self._ireq, parallel_builds=True,
File "c:\vnstudio\lib\site-packages\pip_internal\operations\prepare.py", line 480, in prepare_linked_requirement
return self._prepare_linked_requirement(req, parallel_builds)
File "c:\vnstudio\lib\site-packages\pip_internal\operations\prepare.py", line 505, in _prepare_linked_requirement
self.download_dir, hashes,
File "c:\vnstudio\lib\site-packages\pip_internal\operations\prepare.py", line 257, in unpack_url
hashes=hashes,
File "c:\vnstudio\lib\site-packages\pip_internal\operations\prepare.py", line 130, in get_http_url
from_path, content_type = download(link, temp_dir.path)
File "c:\vnstudio\lib\site-packages\pip_internal\network\download.py", line 163, in call
for chunk in chunks:
File "c:\vnstudio\lib\site-packages\pip_internal\cli\progress_bars.py", line 168, in iter
for x in it:
File "c:\vnstudio\lib\site-packages\pip_internal\network\utils.py", line 88, in response_chunks
decode_content=False,
File "c:\vnstudio\lib\site-packages\pip_vendor\urllib3\response.py", line 576, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "c:\vnstudio\lib\site-packages\pip_vendor\urllib3\response.py", line 541, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "c:\vnstudio\lib\contextlib.py", line 130, in exit
self.gen.throw(type, value, traceback)
File "c:\vnstudio\lib\site-packages\pip_vendor\urllib3\response.py", line 443, in _error_catcher
raise ReadTimeoutError(self._pool, None, "Read timed out.")
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

这个get_account在回测的时候不能使用吧,在BacktestingEngine里面没有找到这个函数

我在template下面这个send_order函数上设置断点,在策略的on_order和on_trade上也设置了断点,,奇怪的是send_order程序没有跑到这里,但是on_order上不停的收到好几个止损的挂单,说明不是我的策略发出的挂止损单的信号。不知道是哪里发出来的?
def send_order(
self,
direction: Direction,
offset: Offset,
price: float,
volume: float,
stop: bool = False,
lock: bool = False
):
"""
Send a new order.
"""
if self.trading:
vt_orderids = self.cta_engine.send_order(
self, direction, offset, price, volume, stop, lock
)
return vt_orderids
else:
return []

是的,开仓已经平仓是写在策略里面的,在on_trade和on_bar函数里面。逻辑上应该是没问题的,调试了半天,没找到原因。

这种情况重复出现,下面的7.16号,11,17号都出现了。这应该和策略没关系吧
datetime,orderid,tradeid,direction,offset,price,volume
2010-06-07 11:25:00+08:06,1,1,Direction.SHORT,Offset.OPEN,4020.4,14.0
2010-07-16 09:00:00+08:06,2,2,Direction.LONG,Offset.CLOSE,4063.4,14.0
2010-07-16 09:00:00+08:06,3,3,Direction.LONG,Offset.CLOSE,4058.0,14.0
2010-07-16 09:00:00+08:06,4,4,Direction.LONG,Offset.CLOSE,4058.0,14.0
2010-07-16 09:00:00+08:06,5,5,Direction.LONG,Offset.CLOSE,4058.0,14.0
2010-07-16 09:00:00+08:06,6,6,Direction.LONG,Offset.CLOSE,4058.0,14.0
2010-07-20 13:35:00+08:06,7,7,Direction.LONG,Offset.OPEN,4185.6,31.0
2010-08-23 09:15:00+08:06,8,8,Direction.SHORT,Offset.CLOSE,4273.6,31.0
2010-08-23 09:25:00+08:06,9,9,Direction.SHORT,Offset.CLOSE,4258.0,31.0
2010-09-06 09:00:00+08:06,10,10,Direction.LONG,Offset.OPEN,4471.0,56.0
2010-09-09 09:25:00+08:06,11,11,Direction.SHORT,Offset.CLOSE,4350.8,56.0
2010-11-05 09:00:00+08:06,12,12,Direction.LONG,Offset.OPEN,4650.0,22.0
2010-11-17 09:00:00+08:06,13,13,Direction.SHORT,Offset.CLOSE,4512.2,22.0
2010-11-17 09:00:00+08:06,14,14,Direction.SHORT,Offset.CLOSE,4526.4,22.0
2010-11-17 09:00:00+08:06,15,15,Direction.SHORT,Offset.CLOSE,4529.0,22.0
2010-11-17 09:00:00+08:06,16,16,Direction.SHORT,Offset.CLOSE,4529.0,22.0
2010-12-20 09:00:00+08:06,17,17,Direction.LONG,Offset.OPEN,4819.0,40.0
2010-12-27 09:00:00+08:06,18,18,Direction.SHORT,Offset.CLOSE,4722.4,40.0
2011-01-10 09:05:00+08:06,19,19,Direction.LONG,Offset.OPEN,4840.0,69.0
2011-02-21 09:00:00+08:06,20,20,Direction.SHORT,Offset.CLOSE,4974.0,69.0
2011-03-02 09:10:00+08:06,21,21,Direction.SHORT,Offset.OPEN,4800.4,25.0
2011-03-29 10:55:00+08:06,22,22,Direction.LONG,Offset.CLOSE,4800.8,25.0
2011-03-29 11:00:00+08:06,23,23,Direction.LONG,Offset.CLOSE,4808.8,25.0
2011-03-29 11:25:00+08:06,24,24,Direction.LONG,Offset.CLOSE,4819.8,25.0
2011-04-08 11:10:00+08:06,25,25,Direction.LONG,Offset.OPEN,4903.6,38.0

我查看了一下这里的K线,有一个隔日跳空。就是说价格跳过了之前的止损线,后面的那些重复的平仓单,是不是追单导致的啊?算不算是一个bug

问题比较奇怪,我是跑的日线策略,之前小时,15分钟策略都没有这个问题,不知道是不是这个原因。

我是在on_trade里面打印的。

调试能看到,开仓了14手,平仓了14手,但是后面还是不停收到平仓的消息,可能是什么问题?
下面是打印出来的trade消息,同一个时间的平仓消息不停的接收到。
datetime,orderid,tradeid,direction,offset,price,volume
2010-06-07 11:25:00+08:06,1,1,Direction.SHORT,Offset.OPEN,4020.4,14.0
2010-07-16 09:00:00+08:06,2,2,Direction.LONG,Offset.CLOSE,4063.4,14.0
2010-07-16 09:00:00+08:06,3,3,Direction.LONG,Offset.CLOSE,4058.0,14.0
2010-07-16 09:00:00+08:06,4,4,Direction.LONG,Offset.CLOSE,4058.0,14.0
2010-07-16 09:00:00+08:06,5,5,Direction.LONG,Offset.CLOSE,4058.0,14.0
2010-07-16 09:00:00+08:06,6,6,Direction.LONG,Offset.CLOSE,4058.0,14.0

自己记录了成交单调试了半天找到了问题了,self.pos记录的是对的。想了解下,CtaEngine里面没有记录sel.pos所对应的成交单的价格时间多空啥的吗?

我在策略里面记录下来了成交单,包括手数等。但是最后和self.pos对不上。哪里可以查询到self.pos对应的成交单,价格时间等

© 2015-2022 微信 18391752892
备案服务号:沪ICP备18006526号

沪公网安备 31011502017034号

【用户协议】
【隐私政策】
【免责条款】