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

这个会是我策略的原因吗?还是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)

Member
avatar
加入于:
帖子: 92
声望: 7

randrange() (1,1, 0)

参数范围有问题

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

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

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

Member
avatar
加入于:
帖子: 2015
声望: 133

参数步进不能填0。并且,使用遗传算法跑优化,要最少两个,才能生成样本空间,不然也会报错。

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

增加了一个参数,可以计算了。一个是布林线窗口,一个是宽度。
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秒

Member
avatar
加入于:
帖子: 2015
声望: 133

可以去看run_ga_optimization函数,这个有输出results的

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

沪公网安备 31011502017034号