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

在Jupyter做参数优化的时候出现问题:

2020-01-09 14:34:48.499169 逐日盯市盈亏计算完成
2020-01-09 14:34:48.500155 开始计算策略统计指标
gen nevals mean std min max
0 100 [7.74054611] [0.34501181] [7.19715305] [8.25334413]


ValueError Traceback (most recent call last)

<ipython-input-4-b458f6cb496e> in <module>
9 #setting.add_parameter("time_window", 5, 50, 2)
10
---> 11 engine.run_ga_optimization(setting)

c:\vnstudio\lib\site-packages\vnpy\app\cta_strategy\backtesting.py in run_ga_optimization(self, optimization_setting, population_size, ngen_size, output)
685 ngen,
686 stats,
--> 687 halloffame=hof
688 )
689

c:\vnstudio\lib\site-packages\deap\algorithms.py in eaMuPlusLambda(population, toolbox, mu, lambda, cxpb, mutpb, ngen, stats, halloffame, verbose)
314 for gen in range(1, ngen + 1):
315 # Vary the population
--> 316 offspring = varOr(population, toolbox, lambda
, cxpb, mutpb)
317
318 # Evaluate the individuals with an invalid fitness

c:\vnstudio\lib\site-packages\deap\algorithms.py in varOr(population, toolbox, lambda_, cxpb, mutpb)
232 if op_choice < cxpb: # Apply crossover
233 ind1, ind2 = list(map(toolbox.clone, random.sample(population, 2)))
--> 234 ind1, ind2 = toolbox.mate(ind1, ind2)
235 del ind1.fitness.values
236 offspring.append(ind1)

c:\vnstudio\lib\site-packages\deap\tools\crossover.py in cxTwoPoint(ind1, ind2)
45 size = min(len(ind1), len(ind2))
46 cxpoint1 = random.randint(1, size)
---> 47 cxpoint2 = random.randint(1, size - 1)
48 if cxpoint2 >= cxpoint1:
49 cxpoint2 += 1

c:\vnstudio\lib\random.py in randint(self, a, b)
220 """
221
--> 222 return self.randrange(a, b+1)
223
224 def _randbelow(self, n, int=int, maxsize=1<<BPF, type=type,

c:\vnstudio\lib\random.py in randrange(self, start, stop, step, _int)
198 return istart + self._randbelow(width)
199 if step == 1:
--> 200 raise ValueError("empty range for randrange() (%d,%d, %d)" % (istart, istop, width))
201
202 # Non-unit step argument supplied.

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

请问这是什么问题?

Administrator
avatar
加入于:
帖子: 2441
声望: 102

优化参数设置时,三个参数是:起始值、步进、结束值,你的结束值是0

Member
加入于:
帖子: 59
声望: 0

我的结束值不是0啊。这是我的设置:
setting = OptimizationSetting()

setting.set_target("return_drawdown_ratio")
setting.add_parameter("r1", 100, 110, 2)

setting.add_parameter("r2", 90, 100, 2)

setting.add_parameter("t1", 3, 12, 1)

setting.add_parameter("t2", 10, 30, 1)

setting.add_parameter("stop", 1, 10, 1)

setting.add_parameter("time_window", 5, 50, 2)

engine.run_ga_optimization(setting)

Administrator
avatar
加入于:
帖子: 2441
声望: 102
setting.add_parameter("r2", 90, 2, 100)

要这么写,参数里最后一个才是步进

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