From 6a0b0be02fb5d882ebc86a602805ce950e640828 Mon Sep 17 00:00:00 2001 From: 1122455801 Date: Fri, 29 Mar 2019 10:27:35 +0800 Subject: [PATCH 1/4] Create genetic_algorithm.ipynb --- .../strategies/boll_channel_strategy.py | 10 +++++----- .../strategies/double_ma_strategy.py | 6 +++--- .../strategies/dual_thrust_strategy.py | 18 +++++++++--------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/vnpy/app/cta_strategy/strategies/boll_channel_strategy.py b/vnpy/app/cta_strategy/strategies/boll_channel_strategy.py index 137d6b1d..02128986 100644 --- a/vnpy/app/cta_strategy/strategies/boll_channel_strategy.py +++ b/vnpy/app/cta_strategy/strategies/boll_channel_strategy.py @@ -13,7 +13,7 @@ from vnpy.app.cta_strategy import ( class BollChannelStrategy(CtaTemplate): """""" - author = '用Python的交易员' + author = "用Python的交易员" boll_window = 18 boll_dev = 3.4 @@ -32,10 +32,10 @@ class BollChannelStrategy(CtaTemplate): long_stop = 0 short_stop = 0 - parameters = ['boll_window', 'boll_dev', 'cci_window', - 'atr_window', 'sl_multiplier', 'fixed_size'] - variables = ['boll_up', 'boll_down', 'cci_value', 'atr_value', - 'intra_trade_high', 'intra_trade_low', 'long_stop', 'short_stop'] + parameters = ["boll_window", "boll_dev", "cci_window", + "atr_window", "sl_multiplier", "fixed_size"] + variables = ["boll_up", "boll_down", "cci_value", "atr_value", + "intra_trade_high", "intra_trade_low", "long_stop", "short_stop"] def __init__(self, cta_engine, strategy_name, vt_symbol, setting): """""" diff --git a/vnpy/app/cta_strategy/strategies/double_ma_strategy.py b/vnpy/app/cta_strategy/strategies/double_ma_strategy.py index cff6f518..ff88e264 100644 --- a/vnpy/app/cta_strategy/strategies/double_ma_strategy.py +++ b/vnpy/app/cta_strategy/strategies/double_ma_strategy.py @@ -11,7 +11,7 @@ from vnpy.app.cta_strategy import ( class DoubleMaStrategy(CtaTemplate): - author = '用Python的交易员' + author = "用Python的交易员" fast_window = 10 slow_window = 20 @@ -22,8 +22,8 @@ class DoubleMaStrategy(CtaTemplate): slow_ma0 = 0.0 slow_ma1 = 0.0 - parameters = ['fast_window', 'slow_window'] - variables = ['fast_ma0', 'fast_ma1', 'slow_ma0', 'slow_ma1'] + parameters = ["fast_window", "slow_window"] + variables = ["fast_ma0", "fast_ma1", "slow_ma0", "slow_ma1"] def __init__(self, cta_engine, strategy_name, vt_symbol, setting): """""" diff --git a/vnpy/app/cta_strategy/strategies/dual_thrust_strategy.py b/vnpy/app/cta_strategy/strategies/dual_thrust_strategy.py index 75cdd3df..2ca9dd37 100644 --- a/vnpy/app/cta_strategy/strategies/dual_thrust_strategy.py +++ b/vnpy/app/cta_strategy/strategies/dual_thrust_strategy.py @@ -14,13 +14,13 @@ from vnpy.app.cta_strategy import ( class DualThrustStrategy(CtaTemplate): """""" - author = u'用Python的交易员' + author = "用Python的交易员" fixed_size = 1 k1 = 0.4 k2 = 0.6 - barList = [] + bars = [] day_open = 0 day_high = 0 @@ -34,8 +34,8 @@ class DualThrustStrategy(CtaTemplate): long_entered = False short_entered = False - parameters = ['k1', 'k2', "fixed_size"] - variables = ['range', 'long_entry', 'short_entry', 'exit_time'] + parameters = ["k1", "k2", "fixed_size"] + variables = ["range", "long_entry", "short_entry", "exit_time"] def __init__(self, cta_engine, strategy_name, vt_symbol, setting): """""" @@ -45,7 +45,7 @@ class DualThrustStrategy(CtaTemplate): self.bg = BarGenerator(self.on_bar) self.am = ArrayManager() - self.barList = [] + self.bars = [] def on_init(self): """ @@ -78,12 +78,12 @@ class DualThrustStrategy(CtaTemplate): """ self.cancel_all() - self.barList.append(bar) - if len(self.barList) <= 2: + self.bars.append(bar) + if len(self.bars) <= 2: return else: - self.barList.pop(0) - last_bar = self.barList[-2] + self.bars.pop(0) + last_bar = self.bars[-2] if last_bar.datetime.date() != bar.datetime.date(): if self.day_high: From 3c884d9568e95bad756fe9514606a6e0e009b270 Mon Sep 17 00:00:00 2001 From: 1122455801 Date: Fri, 29 Mar 2019 12:55:57 +0800 Subject: [PATCH 2/4] Update multi_signal_strategy.py --- .../strategies/multi_signal_strategy.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/vnpy/app/cta_strategy/strategies/multi_signal_strategy.py b/vnpy/app/cta_strategy/strategies/multi_signal_strategy.py index 62b32090..b2f1f8b3 100644 --- a/vnpy/app/cta_strategy/strategies/multi_signal_strategy.py +++ b/vnpy/app/cta_strategy/strategies/multi_signal_strategy.py @@ -134,7 +134,7 @@ class MaSignal(CtaSignal): class MultiSignalStrategy(TargetPosTemplate): """""" - author = '用Python的交易员' + author = "用Python的交易员" rsi_window = 14 rsi_level = 20 @@ -145,9 +145,9 @@ class MultiSignalStrategy(TargetPosTemplate): signal_pos = {} - parameters = ['rsi_window', 'rsi_level', 'cci_window', - 'cci_level', 'fast_window', 'slow_window'] - variables = ['signal_pos', 'target_pos'] + parameters = ["rsi_window", "rsi_level", "cci_window", + "cci_level", "fast_window", "slow_window"] + variables = ["signal_pos", "target_pos"] def __init__(self, cta_engine, strategy_name, vt_symbol, setting): """""" @@ -210,9 +210,9 @@ class MultiSignalStrategy(TargetPosTemplate): def calculate_target_pos(self): """""" - self.signal_pos['rsi'] = self.rsi_signal.get_signal_pos() - self.signal_pos['cci'] = self.cci_signal.get_signal_pos() - self.signal_pos['ma'] = self.ma_signal.get_signal_pos() + self.signal_pos["rsi"] = self.rsi_signal.get_signal_pos() + self.signal_pos["cci"] = self.cci_signal.get_signal_pos() + self.signal_pos["ma"] = self.ma_signal.get_signal_pos() target_pos = 0 for v in self.signal_pos.values(): From 29fe0b072c315a1778ad0dae2d8701f2fa1d445e Mon Sep 17 00:00:00 2001 From: 1122455801 Date: Fri, 29 Mar 2019 12:56:04 +0800 Subject: [PATCH 3/4] Update multi_timeframe_strategy.py --- .../strategies/multi_timeframe_strategy.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/vnpy/app/cta_strategy/strategies/multi_timeframe_strategy.py b/vnpy/app/cta_strategy/strategies/multi_timeframe_strategy.py index 2b406a98..cb18cf04 100644 --- a/vnpy/app/cta_strategy/strategies/multi_timeframe_strategy.py +++ b/vnpy/app/cta_strategy/strategies/multi_timeframe_strategy.py @@ -12,7 +12,7 @@ from vnpy.app.cta_strategy import ( class MultiTimeframeStrategy(CtaTemplate): """""" - author = '用Python的交易员' + author = "用Python的交易员" rsi_signal = 20 rsi_window = 14 @@ -27,12 +27,12 @@ class MultiTimeframeStrategy(CtaTemplate): slow_ma = 0 ma_trend = 0 - parameters = ['rsi_signal', 'rsi_window', - 'fast_window', 'slow_window', - 'fixed_size'] + parameters = ["rsi_signal", "rsi_window", + "fast_window", "slow_window", + "fixed_size"] - variables = ['rsi_value', 'rsi_long', 'rsi_short', - 'fast_ma', 'slow_ma', 'ma_trend'] + variables = ["rsi_value", "rsi_long", "rsi_short", + "fast_ma", "slow_ma", "ma_trend"] def __init__(self, cta_engine, strategy_name, vt_symbol, setting): """""" From 8fa9f2ae9c362f0e0854b0ab6f1470be116fcd86 Mon Sep 17 00:00:00 2001 From: 1122455801 Date: Fri, 29 Mar 2019 12:56:44 +0800 Subject: [PATCH 4/4] Update test_strategy.py --- vnpy/app/cta_strategy/strategies/test_strategy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vnpy/app/cta_strategy/strategies/test_strategy.py b/vnpy/app/cta_strategy/strategies/test_strategy.py index 814ae57e..f0a31c3b 100644 --- a/vnpy/app/cta_strategy/strategies/test_strategy.py +++ b/vnpy/app/cta_strategy/strategies/test_strategy.py @@ -12,7 +12,7 @@ from time import time class TestStrategy(CtaTemplate): """""" - author = '用Python的交易员' + author = "用Python的交易员" test_trigger = 10