From 2c266f1309da998119cfaf23cbe3aa0c370c7bb8 Mon Sep 17 00:00:00 2001 From: nanoric Date: Mon, 17 Sep 2018 21:30:48 -0400 Subject: [PATCH 1/2] =?UTF-8?q?[Add]=20=E5=B0=86ctaBacktesting.outputOptim?= =?UTF-8?q?izeResult=E5=88=86=E7=A6=BB=E4=BA=86=E5=87=BA=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/CtaBacktesting/runOptimization.py | 3 ++- vnpy/trader/app/ctaStrategy/ctaBacktesting.py | 15 ++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/examples/CtaBacktesting/runOptimization.py b/examples/CtaBacktesting/runOptimization.py index 81a01f28..32b19f01 100644 --- a/examples/CtaBacktesting/runOptimization.py +++ b/examples/CtaBacktesting/runOptimization.py @@ -48,6 +48,7 @@ if __name__ == '__main__': #engine.runOptimization(AtrRsiStrategy, setting) # 多进程优化,耗时:89秒 - engine.runParallelOptimization(AtrRsiStrategy, setting) + result = engine.runParallelOptimization(AtrRsiStrategy, setting) + engine.outputOptimizeResult(result) print(u'耗时:%s' %(time.time()-start)) \ No newline at end of file diff --git a/vnpy/trader/app/ctaStrategy/ctaBacktesting.py b/vnpy/trader/app/ctaStrategy/ctaBacktesting.py index cf06b61e..df5ba085 100644 --- a/vnpy/trader/app/ctaStrategy/ctaBacktesting.py +++ b/vnpy/trader/app/ctaStrategy/ctaBacktesting.py @@ -921,12 +921,8 @@ class BacktestingEngine(object): # 显示结果 resultList.sort(reverse=True, key=lambda result:result[1]) - self.output('-' * 30) - self.output(u'优化结果:') - for result in resultList: - self.output(u'参数:%s,目标:%s' %(result[0], result[1])) - return resultList - + return self.outputOptimizeResult(resultList) + #---------------------------------------------------------------------- def runParallelOptimization(self, strategyClass, optimizationSetting): """并行优化参数""" @@ -953,12 +949,13 @@ class BacktestingEngine(object): # 显示结果 resultList = [res.get() for res in l] - resultList.sort(reverse=True, key=lambda result:result[1]) + return resultList.sort(reverse=True, key=lambda result:result[1]) + + def outputOptimizeResult(self, resultList): self.output('-' * 30) self.output(u'优化结果:') for result in resultList: - self.output(u'参数:%s,目标:%s' %(result[0], result[1])) - + self.output(u'参数:%s,目标:%s' % (result[0], result[1])) return resultList #---------------------------------------------------------------------- From c1c9d93c8fcf1285191580b3c27297f598e939c5 Mon Sep 17 00:00:00 2001 From: nanoric <475647575@qq.com> Date: Mon, 17 Sep 2018 23:16:24 -0300 Subject: [PATCH 2/2] Update ctaBacktesting.py --- vnpy/trader/app/ctaStrategy/ctaBacktesting.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vnpy/trader/app/ctaStrategy/ctaBacktesting.py b/vnpy/trader/app/ctaStrategy/ctaBacktesting.py index df5ba085..fc86d441 100644 --- a/vnpy/trader/app/ctaStrategy/ctaBacktesting.py +++ b/vnpy/trader/app/ctaStrategy/ctaBacktesting.py @@ -949,7 +949,8 @@ class BacktestingEngine(object): # 显示结果 resultList = [res.get() for res in l] - return resultList.sort(reverse=True, key=lambda result:result[1]) + resultList.sort(reverse=True, key=lambda result:result[1]) + return resultList def outputOptimizeResult(self, resultList): self.output('-' * 30) @@ -1376,4 +1377,4 @@ def optimize(strategyClass, setting, targetName, except KeyError: targetValue = 0 return (str(setting), targetValue, d) - \ No newline at end of file +