添加分型识别

This commit is contained in:
jackyu66git
2026-03-14 02:03:27 +08:00
parent aeced3c618
commit 1c17cf1f11
2 changed files with 35 additions and 8 deletions
+25
View File
@@ -355,5 +355,30 @@ class Chan_DATA_FIELD:
FIELD_TURNOVER = "turnover" # 成交额
FIELD_TURNRATE = "turnover_rate" # 换手率
class Chan_KLC_STATE:
"""笔当下状态(缠论笔定理)。任意时刻必属其一。"""
FX = auto() # 分型构造中(未确认顶/底)
BI = auto() # 笔延伸中(分型已确认,笔在延伸)
UP = auto() # 顶分型构造中 (1,0):向上笔末端
DOWN = auto() # 底分型构造中 (-1,0):向下笔末端
# 笔定理四状态:(Chan_BI_DIR, Chan_KLC_STATE)。笔方向用 Chan_BI_DIR,阶段用 Chan_KLC_STATE。
# (UP, BI) 向上笔延伸;(DOWN, BI) 向下笔延伸;(UP, UP) 向上笔顶分型构造;(DOWN, DOWN) 向下笔底分型构造
def bi_theorem_state(direction: Chan_BI_DIR, phase: Literal[0, 1]) -> tuple[Chan_BI_DIR, int]:
"""(direction, phase) -> (Chan_BI_DIR, Chan_KLC_STATE)。phase 0=分型构造中,1=笔延伸中。"""
if phase == 1:
return (direction, Chan_KLC_STATE.BI)
return (direction, Chan_KLC_STATE.UP if direction == Chan_BI_DIR.UP else Chan_KLC_STATE.DOWN)
# 笔定理状态转移:当前 (Chan_BI_DIR, Chan_KLC_STATE) 允许的下一状态列表
# (UP,BI) 只能 -> (UP,UP)(DOWN,BI) 只能 -> (DOWN,DOWN)(UP,UP) 可 -> (UP,BI)|(DOWN,BI)(DOWN,DOWN) 可 -> (DOWN,BI)|(UP,BI)
Chan_BI_STATE_TRANSITIONS: dict[tuple[Chan_BI_DIR, int], list[tuple[Chan_BI_DIR, int]]] = {
(Chan_BI_DIR.UP, Chan_KLC_STATE.BI): [(Chan_BI_DIR.UP, Chan_KLC_STATE.UP)],
(Chan_BI_DIR.DOWN, Chan_KLC_STATE.BI): [(Chan_BI_DIR.DOWN, Chan_KLC_STATE.DOWN)],
(Chan_BI_DIR.UP, Chan_KLC_STATE.UP): [(Chan_BI_DIR.UP, Chan_KLC_STATE.BI), (Chan_BI_DIR.DOWN, Chan_KLC_STATE.BI)],
(Chan_BI_DIR.DOWN, Chan_KLC_STATE.DOWN): [(Chan_BI_DIR.DOWN, Chan_KLC_STATE.BI), (Chan_BI_DIR.UP, Chan_KLC_STATE.BI)],
}
Chan_TRADE_INFO_LST = [Chan_DATA_FIELD.FIELD_VOLUME, Chan_DATA_FIELD.FIELD_TURNOVER, Chan_DATA_FIELD.FIELD_TURNRATE]
+10 -8
View File
@@ -919,11 +919,11 @@ class TF_DF():
bi_klc_min = 4
for klc in klc_list:
fx = self.check_fx(klc)
if fx == Chan_FX_TYPE.TOP:
if fx == Chan_FX_TYPE.TOP and False:
if last_bottom:
if self.check_top_fx(last_bottom, klc) == False:
fx = Chan_FX_TYPE.UNKNOWN
if fx == Chan_FX_TYPE.BOTTOM:
if fx == Chan_FX_TYPE.BOTTOM and False:
if last_top:
if self.check_bottom_fx(last_top, klc) == False:
#print(klc.end_time, last_top.end_time, "---")
@@ -986,7 +986,7 @@ class TF_DF():
if last_top.high > klc.high:
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
#klc.set_klc_fx_type(Chan_KLC_FX.TOP3)
klc.set_klc_fx_type(Chan_KLC_FX.TOP3)
#print(klc.end_time, klc.fx, "二类卖点Sell 1")
else:
# A new top found
@@ -1000,11 +1000,12 @@ class TF_DF():
klc.set_bi(bi_list[-1])
# 不满足结合律的分型
else:
klc.set_klc_fx_type(Chan_KLC_FX.TOP0)
#klc.set_klc_fx_type(Chan_KLC_FX.TOP0)
print(klc.end_time, klc.klc_fx_type)
if last_bottom.index + bi_klc_min > klc.index:
if last_top.high > klc.high:
#print(klc.start_time, klc.fx, "二类卖点Sell 1")
#klc.set_fx(Chan_FX_TYPE.PTOP)
klc.set_klc_fx_type(Chan_KLC_FX.TOP8)
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
# New TOP Found前面的UKNOWN可能出现TOP7,但是这里的也可能出现TOP8分型
@@ -1103,7 +1104,7 @@ class TF_DF():
if last_bottom.low < klc.low:
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
#klc.set_klc_fx_type(Chan_KLC_FX.BOTTOM3)
klc.set_klc_fx_type(Chan_KLC_FX.BOTTOM3)
#print(last_bottom.start_time, last_bottom.end_time, "--------------------------------1")
#print(klc.end_time, klc.fx, "二类买点Buy 1")
else:
@@ -1117,12 +1118,14 @@ class TF_DF():
klc.set_bi(bi_list[-1])
# 不满足结合律的分型
else:
klc.set_klc_fx_type(Chan_KLC_FX.TOP0)
#klc.set_klc_fx_type(Chan_KLC_FX.BOTTOM0)
#print(klc.end_time, klc.klc_fx_type)
if last_top.index + bi_klc_min > klc.index:
if last_bottom.low < klc.low:
#print(klc.end_time, klc.fx, "中枢买点Buy 1")
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
klc.set_klc_fx_type(Chan_KLC_FX.BOTTOM8)
# Found new bottom没有意义,上面UNKNOWN的时候已经是笔破坏了
else:
#print(klc.end_time, last_bottom.end_time, "Found a new bottom")
@@ -1155,7 +1158,6 @@ class TF_DF():
if not last_bi.is_sure:
last_bi.set_end_klc(last_top, klc)
bi = ChanBI(last_top, len(bi_list), Chan_BI_DIR.DOWN)
#klc.set_klc_fx_type(Chan_KLC_FX.TOP6)
last_bi.set_next(bi)
bi.set_pre(last_bi)
bi.add_klc(klc)