From 8b848e8a9fa242b39f92f3a28faf89be10a6e456 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期五, 17 三月 2023 17:43:32 +0800
Subject: [PATCH] 首板策略优化

---
 trade/l2_trade_factor.py |  120 +++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 98 insertions(+), 22 deletions(-)

diff --git a/trade/l2_trade_factor.py b/trade/l2_trade_factor.py
index 8c6dc63..86c8e4a 100644
--- a/trade/l2_trade_factor.py
+++ b/trade/l2_trade_factor.py
@@ -11,6 +11,96 @@
 import limit_up_time_manager
 
 
+# 涓嬪崟鍙傛暟
+class L2PlaceOrderParamsManager:
+    # 鑾峰彇淇″彿杩炵画涔扮瑪鏁�
+    @staticmethod
+    def get_begin_continue_buy_count(volume_rate_index):
+        counts = [3, 3, 3, 2, 2, 2, 2]
+        if volume_rate_index >= len(counts):
+            volume_rate_index = -1
+        return counts[volume_rate_index]
+
+    # 鑾峰彇鏃堕棿璁$畻鑼冨洿锛岃繑鍥瀞
+    @staticmethod
+    def get_time_range(volume_rate_index):
+        ts = [pow(3, 1), pow(3, 1), pow(3, 1), pow(3, 2), pow(3, 2), pow(3, 3), pow(3, 3), pow(3, 3)]
+        if volume_rate_index >= len(ts):
+            volume_rate_index = -1
+        return ts[volume_rate_index]
+
+    # 鑾峰彇闇�瑕佺殑澶у崟涓暟
+    @staticmethod
+    def get_big_num_count(volume_rate_index):
+        counts = [4, 3, 2, 1, 1, 1, 1]
+        if volume_rate_index >= len(counts):
+            volume_rate_index = -1
+        return counts[volume_rate_index]
+
+    # 鑾峰彇瀹夊叏绗旀暟褰卞搷姣斾緥
+    @staticmethod
+    def get_safe_count_rate(volume_rate_index):
+        rates = [0, -0.1, -0.2, -0.4, -0.6, -0.8, -0.8, -0.8]
+        if volume_rate_index >= len(rates):
+            volume_rate_index = -1
+        return rates[volume_rate_index]
+
+    # 鑾峰彇m鍊煎奖鍝嶆瘮渚�
+    @staticmethod
+    def get_m_val_rate(volume_rate_index):
+        rates = [0.0, 0.0, 0.0, -0.3, -0.4, -0.5, -0.6, -0.7]
+        if volume_rate_index >= len(rates):
+            volume_rate_index = -1
+        return rates[volume_rate_index]
+
+
+# S鎾ゅ弬鏁�
+class SCancelParamsManager:
+    # 鍓旈櫎鍓嶅嚑鐨勭偣鐏ぇ鍗�
+    @staticmethod
+    def get_max_exclude_count(volume_rate_index):
+        counts = [5, 4, 3, 2, 1, 1, 1, 1]
+        if volume_rate_index >= len(counts):
+            volume_rate_index = -1
+        return counts[volume_rate_index]
+
+    # 鑾峰彇涔版椂闂磋寖鍥�(璺濈鎵ц浣�)锛岃繑鍥瀞
+    @staticmethod
+    def get_buy_time_range(volume_rate_index):
+        seconds = [pow(2, 1), pow(2, 2), pow(2, 3), pow(2, 4), pow(2, 4), pow(2, 5), pow(2, 6), pow(2, 6)]
+        if volume_rate_index >= len(seconds):
+            volume_rate_index = -1
+        return seconds[volume_rate_index]
+
+    # 鑾峰彇鎾ら攢姣斾緥
+    @staticmethod
+    def get_cancel_rate(volume_rate_index):
+        rates = [0.39, 0.49, 0.59, 0.69, 0.69, 0.79, 0.79, 0.79]
+        if volume_rate_index >= len(rates):
+            volume_rate_index = -1
+        return rates[volume_rate_index]
+
+
+# H鎾ゅ弬鏁�
+class HCancelParamsManager:
+
+    # 鑾峰彇鏈�澶х殑瑙傚療绗旀暟
+    @staticmethod
+    def get_max_watch_count(volume_rate_index):
+        counts = [40, 36, 32, 28, 24, 20, 16, 12]
+        if volume_rate_index >= len(counts):
+            volume_rate_index = -1
+        return counts[volume_rate_index]
+
+    # 鑾峰彇鎾ら攢姣斾緥
+    @staticmethod
+    def get_cancel_rate(volume_rate_index):
+        rates = [0.39, 0.49, 0.59, 0.69, 0.69, 0.79, 0.79, 0.79]
+        if volume_rate_index >= len(rates):
+            volume_rate_index = -1
+        return rates[volume_rate_index]
+
+
 class L2TradeFactorUtil:
     # 鑾峰彇鍩虹m鍊硷紝杩斿洖鍗曚綅涓哄厓
     @classmethod
@@ -19,7 +109,7 @@
         if yi < 1:
             yi = 1
         m = 5000000 + (yi - 1) * 500000
-        return round(m * 0.7)
+        return round(m)
 
     # 鑾峰彇琛屼笟褰卞搷姣斾緥
     # total_limit_percent涓虹粺璁$殑姣斾緥涔嬪拰涔樹互100
@@ -204,7 +294,7 @@
         return zyltgb
 
     @classmethod
-    def compute_m_value(cls, code):
+    def compute_m_value(cls, code,volume_rate):
         zyltgb = global_util.zyltgb_map.get(code)
         if zyltgb is None:
             global_data_loader.load_zyltgb()
@@ -213,22 +303,12 @@
                 print("娌℃湁鑾峰彇鍒拌嚜鐢辨祦閫氬競鍊�")
                 return 10000000, ""
         zyltgb = cls.get_base_safe_val(zyltgb)
-        rate, msg = cls.compute_rate_by_code(code)
+        # 鏆傛椂娉ㄩ噴
+        # rate, msg = cls.compute_rate_by_code(code)
         # print("m鍊艰幏鍙栵細", code, round(zyltgb * rate))
-        return round(zyltgb * rate), msg
+        rate = L2PlaceOrderParamsManager.get_m_val_rate(volume_rate)
 
-    @classmethod
-    def get_h_cancel_min_count(cls, code):
-        volumn_day60_max, volumn_yest, volumn_today = cls.__get_volumns(code)
-        if volumn_day60_max is None or volumn_yest is None or volumn_today is None:
-            return constant.H_CANCEL_MIN_COUNT
-        rate = round(int(volumn_today) / max(int(volumn_day60_max), int(volumn_yest)), 2)
-        counts = [40, 36, 32, 28, 24, 20, 16]
-        rates = [0.3, 0.55, 0.8, 1.05, 1.3, 1.55, 10]
-        for index in range(0,len(rates)):
-            if rate < rates[index]:
-                return counts[index]
-        return counts[0]
+        return round(zyltgb * (1+rate)), ""
 
     # 鑾峰彇瀹夊叏绗旀暟
     @classmethod
@@ -293,12 +373,8 @@
     # print(L2TradeFactorUtil.get_safe_buy_count("003005"))
     # print(L2TradeFactorUtil.get_rate_factors("003004"))
     # print(L2TradeFactorUtil.factors_to_string("003004"))
-    print(L2TradeFactorUtil.get_safe_buy_count_by_gp(100000000 * 4))
-    print(L2TradeFactorUtil.get_safe_buy_count_by_gp(100000000 * 7))
-    print(L2TradeFactorUtil.get_safe_buy_count_by_gp(100000000 * 10))
-    print(L2TradeFactorUtil.get_safe_buy_count_by_gp(100000000 * 16))
-    print(L2TradeFactorUtil.get_safe_buy_count_by_gp(100000000 * 22))
-    print(L2TradeFactorUtil.get_safe_buy_count_by_gp(100000000 * 31))
+    for i in range(2, 151):
+        print(i, L2TradeFactorUtil.get_base_safe_val(100000000 * i))
     # print(L2TradeFactorUtil.get_limit_up_time_rate("11:30:00"))
     # print(L2TradeFactorUtil.get_limit_up_time_rate("13:00:00"))
     # print(L2TradeFactorUtil.get_limit_up_time_rate("13:48:00"))

--
Gitblit v1.8.0