refactor: 缠论引擎包化与 Web 分层(ECR-001)
将根目录引擎迁入 chanlun/ 并保留兼容 shim;拆分 TF_DF 与 web 服务; 前端模块化;strategies 改用 chanlun 导入;补充 ESS 文档与 golden 回归。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,164 @@
|
||||
import sys, os
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
分型强度检测使用示例
|
||||
该文件展示如何使用ChanKLC类中新增的分型强度检测功能
|
||||
"""
|
||||
|
||||
from chanlun.core.ChanKLC import ChanKLC
|
||||
from chanlun.core.ChanEnum import Chan_FX_TYPE
|
||||
import ChanKLU
|
||||
|
||||
|
||||
def demo_fx_strength_detection():
|
||||
"""
|
||||
演示分型强度检测功能
|
||||
"""
|
||||
print("=== 分型强度检测功能演示 ===\n")
|
||||
|
||||
# 假设我们有一个已经确定为分型的KLC对象
|
||||
# 这里仅为演示,实际使用中KLC对象应该通过正常流程创建
|
||||
|
||||
print("1. 分型强度计算方法:")
|
||||
print(" - calculate_fx_strength(): 返回0-100的强度分数")
|
||||
print(" - get_fx_strength_level(): 返回强度等级描述")
|
||||
print(" - is_strong_fx(threshold): 判断是否为强分型")
|
||||
print()
|
||||
|
||||
print("2. 强度评分维度 (总分100分):")
|
||||
print(" - 价格差异强度: 40分 (与相邻K线的价格差异)")
|
||||
print(" - 突破历史点位: 20分 (是否突破重要高低点)")
|
||||
print(" - 成交量确认: 15分 (分型形成时的成交量)")
|
||||
print(" - RSI背离确认: 15分 (价格与RSI的背离)")
|
||||
print(" - MACD背离确认: 10分 (价格与MACD的背离)")
|
||||
print()
|
||||
|
||||
print("3. 强度等级分类:")
|
||||
print(" - 极强: 80-100分")
|
||||
print(" - 强: 60-79分")
|
||||
print(" - 中等: 40-59分")
|
||||
print(" - 弱: 20-39分")
|
||||
print(" - 极弱: 0-19分")
|
||||
print()
|
||||
|
||||
print("4. 在特征数据中的应用:")
|
||||
print(" 分型强度会自动集成到get_feature_data()方法返回的特征中:")
|
||||
print(" - klc_fx_strength: 强度分数")
|
||||
print(" - klc_fx_strength_level: 强度等级")
|
||||
print(" - klc_is_strong_fx: 是否为强分型(布尔值)")
|
||||
print(" - klc_fx_strength_extreme: 是否为极强分型")
|
||||
print(" - klc_fx_strength_strong: 是否为强分型")
|
||||
print(" - klc_fx_strength_medium: 是否为中等分型")
|
||||
print(" - klc_fx_strength_weak: 是否为弱分型")
|
||||
print(" - klc_fx_strength_very_weak: 是否为极弱分型")
|
||||
print()
|
||||
|
||||
|
||||
def analyze_fx_strength(klc):
|
||||
"""
|
||||
分析单个KLC的分型强度
|
||||
|
||||
Args:
|
||||
klc: ChanKLC对象
|
||||
"""
|
||||
if klc.fx == Chan_FX_TYPE.UNKNOWN:
|
||||
print(f"时间: {klc.start_time} - 无分型")
|
||||
return
|
||||
|
||||
fx_type = "顶分型" if klc.fx == Chan_FX_TYPE.TOP else "底分型"
|
||||
strength = klc.calculate_fx_strength()
|
||||
strength_level = klc.get_fx_strength_level()
|
||||
is_strong = klc.is_strong_fx()
|
||||
|
||||
print(f"时间: {klc.start_time}")
|
||||
print(f"分型类型: {fx_type}")
|
||||
print(f"强度分数: {strength}")
|
||||
print(f"强度等级: {strength_level}")
|
||||
print(f"是否强分型: {'是' if is_strong else '否'}")
|
||||
print("-" * 30)
|
||||
|
||||
|
||||
def filter_strong_fractals(klc_list, min_strength=60):
|
||||
"""
|
||||
筛选强分型
|
||||
|
||||
Args:
|
||||
klc_list: KLC对象列表
|
||||
min_strength: 最小强度阈值
|
||||
|
||||
Returns:
|
||||
强分型列表
|
||||
"""
|
||||
strong_fractals = []
|
||||
|
||||
for klc in klc_list:
|
||||
if klc.fx != Chan_FX_TYPE.UNKNOWN and klc.is_strong_fx(min_strength):
|
||||
strong_fractals.append(klc)
|
||||
|
||||
return strong_fractals
|
||||
|
||||
|
||||
def get_fractal_statistics(klc_list):
|
||||
"""
|
||||
获取分型强度统计信息
|
||||
|
||||
Args:
|
||||
klc_list: KLC对象列表
|
||||
|
||||
Returns:
|
||||
统计信息字典
|
||||
"""
|
||||
stats = {
|
||||
'total_fractals': 0,
|
||||
'top_fractals': 0,
|
||||
'bottom_fractals': 0,
|
||||
'extreme_strength': 0, # 极强
|
||||
'strong_strength': 0, # 强
|
||||
'medium_strength': 0, # 中等
|
||||
'weak_strength': 0, # 弱
|
||||
'very_weak_strength': 0,# 极弱
|
||||
'avg_strength': 0
|
||||
}
|
||||
|
||||
strengths = []
|
||||
|
||||
for klc in klc_list:
|
||||
if klc.fx != Chan_FX_TYPE.UNKNOWN:
|
||||
stats['total_fractals'] += 1
|
||||
|
||||
if klc.fx == Chan_FX_TYPE.TOP:
|
||||
stats['top_fractals'] += 1
|
||||
else:
|
||||
stats['bottom_fractals'] += 1
|
||||
|
||||
strength = klc.calculate_fx_strength()
|
||||
strengths.append(strength)
|
||||
|
||||
if strength >= 80:
|
||||
stats['extreme_strength'] += 1
|
||||
elif strength >= 60:
|
||||
stats['strong_strength'] += 1
|
||||
elif strength >= 40:
|
||||
stats['medium_strength'] += 1
|
||||
elif strength >= 20:
|
||||
stats['weak_strength'] += 1
|
||||
else:
|
||||
stats['very_weak_strength'] += 1
|
||||
|
||||
if strengths:
|
||||
stats['avg_strength'] = sum(strengths) / len(strengths)
|
||||
|
||||
return stats
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
demo_fx_strength_detection()
|
||||
|
||||
print("=== 使用建议 ===")
|
||||
print("1. 在交易策略中,可以只关注强度>=60的分型")
|
||||
print("2. 极强分型(>=80分)通常是重要的转折点")
|
||||
print("3. 结合成交量和技术指标背离的分型更可靠")
|
||||
print("4. 可以用分型强度来设置止损和止盈位置")
|
||||
print("5. 分型强度可以作为机器学习模型的重要特征")
|
||||
Reference in New Issue
Block a user