修改了bsp state,继续测试

This commit is contained in:
jackyu66git
2026-05-20 00:49:53 +08:00
parent 91148a648a
commit 9b876c45ed
7 changed files with 430 additions and 161 deletions
+10 -18
View File
@@ -1,8 +1,7 @@
"""
engine.py - 缠论管线封装:DataFrame → KLC → BI → ZS → BSP。
engine.py - 缠论管线封装:DataFrame → KLU → KLC → BI → SEG → ZS → BSP。
复用 ~/Project/Chan/ 下的 TF_DF 模块。
注意:TF_DF.__init__ 有 bugget_zs_list 不存在),这里手动调用各步骤。
复用 ~/Project/Chan/ 下的 TF_DF 模块,管线步骤对齐 TF_DF.get_bsp_state()
"""
import sys
import os
@@ -13,21 +12,19 @@ if _PARENT not in sys.path:
sys.path.insert(0, _PARENT)
import pandas as pd
import talib.abstract as ta
from ChanEnum import (
Chan_BSP_DIR, Chan_BSP_TYPE, Chan_KLC_FX, Chan_BI_DIR,
Chan_FX_TYPE, Chan_KLINE_DIR, Chan_SEG_DIR, Chan_ZS_DIR,
Chan_ZS_DIR,
)
from ChanBSP import ChanBSP
from ChanBI import ChanBI
from ChanZS import ChanZS
# 仅导入类,不触发 TF_DF.__init__
from TF_DF import TF_DF as _TF_DF_Class
class ChanEngine:
"""手动执行缠论管线,绕过 TF_DF.__init__ 的 bug"""
"""缠论管线,对齐 TF_DF.get_bsp_state() 的调用顺序"""
def __init__(self, df: pd.DataFrame):
if df.empty or len(df) < 50:
@@ -39,18 +36,13 @@ class ChanEngine:
self.df = df
self._tf = _TF_DF_Class.__new__(_TF_DF_Class) # 不调用 __init__
# Step 0: 添加 TA 指标
# Step 0: 添加 TA 指标 (MACD/EMA/BB/RSI)
self._df_with_indicators = self._tf.add_indicators(df.copy())
# Step 1: KLU (K-line unit)
self.klu_list = self._tf.cal_kl_data(self._df_with_indicators)
# Step 1: KLU — get_klu_list → get_kl_data → cal_kl_data
self.klu_list = self._tf.get_klu_list(self._df_with_indicators)
# Step 1.5: MACD state
from ChanMACD import ChanMACD
chanmacd = ChanMACD(self.klu_list)
self.klu_list = chanmacd.cal_macd_state()
# Step 2: KLC (combined K-line)
# Step 2: KLC — 内部已含 ChanMACD.cal_macd_state() + cal_trend()
self.klc_list = self._tf.get_klc_list(self.klu_list)
# Step 3: BI (stroke)
@@ -59,8 +51,8 @@ class ChanEngine:
# Step 4: SEG (segment)
self.seg_list = self._tf.get_seg_list(self.bi_list)
# Step 5: ZS (bi-level center) — 供 find_all_bsp 使用
self.bi_zs_list: List = self._tf.cal_bi_zs_list(self.bi_list)
# Step 5: ZS — cal_bi_zs(seg_list) 对齐 get_bsp_state(从线段计算笔中枢)
self.bi_zs_list: List = self._tf.cal_bi_zs(self.seg_list)
# Step 6: BSP (buy/sell points)
self.bsp_list: List[ChanBSP] = self._tf.find_all_bsp(