Files
Chan/chanlun/analysis/fx_strength_config.py
T
jackyu66gitandCursor 74dec4e50b refactor: 缠论引擎包化与 Web 分层(ECR-001)
将根目录引擎迁入 chanlun/ 并保留兼容 shim;拆分 TF_DF 与 web 服务;
前端模块化;strategies 改用 chanlun 导入;补充 ESS 文档与 golden 回归。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-05 18:48:20 +08:00

153 lines
6.0 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
分型强度检测配置文件
用于调整分型强度计算的各项参数和权重
"""
class FxStrengthConfig:
"""分型强度检测配置类"""
def __init__(self):
# ===== 权重配置 (总分100分) =====
self.price_difference_weight = 40 # 价格差异强度权重
self.breakthrough_weight = 20 # 突破历史点位权重
self.volume_weight = 15 # 成交量确认权重
self.rsi_divergence_weight = 15 # RSI背离权重
self.macd_divergence_weight = 10 # MACD背离权重
# ===== 价格差异参数 =====
self.price_diff_multiplier = 1000 # 价格差异放大倍数
self.max_price_score = 20 # 价格差异最高得分
# ===== 突破检测参数 =====
self.breakthrough_lookback = 10 # 回看K线数量
self.breakthrough_multiplier = 500 # 突破幅度放大倍数
self.max_breakthrough_score = 20 # 突破最高得分
# ===== 成交量参数 =====
self.volume_lookback = 5 # 计算平均成交量的回看期数
self.volume_multiplier = 10 # 成交量放大倍数
self.max_volume_score = 15 # 成交量最高得分
self.min_volume_ratio = 1.0 # 最小成交量比率
# ===== RSI背离参数 =====
self.rsi_divergence_divisor = 2 # RSI背离除数
self.max_rsi_score = 15 # RSI最高得分
# ===== MACD背离参数 =====
self.macd_divergence_multiplier = 100 # MACD背离放大倍数
self.max_macd_score = 10 # MACD最高得分
# ===== 强度等级阈值 =====
self.extreme_threshold = 80 # 极强分型阈值
self.strong_threshold = 60 # 强分型阈值
self.medium_threshold = 40 # 中等分型阈值
self.weak_threshold = 20 # 弱分型阈值
# ===== 其他参数 =====
self.min_strength = 0 # 最小强度分数
self.max_strength = 100 # 最大强度分数
def get_strength_level_name(self, strength):
"""根据强度分数获取等级名称"""
if strength >= self.extreme_threshold:
return "极强"
elif strength >= self.strong_threshold:
return "强"
elif strength >= self.medium_threshold:
return "中等"
elif strength >= self.weak_threshold:
return "弱"
else:
return "极弱"
def is_strong_fractal(self, strength, custom_threshold=None):
"""判断是否为强分型"""
threshold = custom_threshold if custom_threshold is not None else self.strong_threshold
return strength >= threshold
def validate_config(self):
"""验证配置参数的合理性"""
total_weight = (self.price_difference_weight +
self.breakthrough_weight +
self.volume_weight +
self.rsi_divergence_weight +
self.macd_divergence_weight)
if total_weight != 100:
print(f"警告: 权重总和为{total_weight},不等于100")
if not (0 <= self.extreme_threshold <= 100):
print(f"警告: 极强阈值{self.extreme_threshold}不在合理范围内")
if not (self.weak_threshold < self.medium_threshold <
self.strong_threshold < self.extreme_threshold):
print("警告: 强度阈值设置不合理")
return True
def print_config(self):
"""打印当前配置"""
print("=== 分型强度检测配置 ===")
print(f"价格差异权重: {self.price_difference_weight}分")
print(f"突破点位权重: {self.breakthrough_weight}分")
print(f"成交量权重: {self.volume_weight}分")
print(f"RSI背离权重: {self.rsi_divergence_weight}分")
print(f"MACD背离权重: {self.macd_divergence_weight}分")
print()
print("=== 强度等级阈值 ===")
print(f"极强: >={self.extreme_threshold}分")
print(f"强: {self.strong_threshold}-{self.extreme_threshold-1}分")
print(f"中等: {self.medium_threshold}-{self.strong_threshold-1}分")
print(f"弱: {self.weak_threshold}-{self.medium_threshold-1}分")
print(f"极弱: <{self.weak_threshold}分")
# 默认配置实例
DEFAULT_CONFIG = FxStrengthConfig()
# 保守配置 (更严格的分型识别)
CONSERVATIVE_CONFIG = FxStrengthConfig()
CONSERVATIVE_CONFIG.price_difference_weight = 50
CONSERVATIVE_CONFIG.breakthrough_weight = 25
CONSERVATIVE_CONFIG.volume_weight = 15
CONSERVATIVE_CONFIG.rsi_divergence_weight = 10
CONSERVATIVE_CONFIG.macd_divergence_weight = 0
CONSERVATIVE_CONFIG.strong_threshold = 70
CONSERVATIVE_CONFIG.extreme_threshold = 85
# 激进配置 (更宽松的分型识别)
AGGRESSIVE_CONFIG = FxStrengthConfig()
AGGRESSIVE_CONFIG.price_difference_weight = 30
AGGRESSIVE_CONFIG.breakthrough_weight = 15
AGGRESSIVE_CONFIG.volume_weight = 20
AGGRESSIVE_CONFIG.rsi_divergence_weight = 20
AGGRESSIVE_CONFIG.macd_divergence_weight = 15
AGGRESSIVE_CONFIG.strong_threshold = 50
AGGRESSIVE_CONFIG.extreme_threshold = 70
# 技术指标重点配置 (重视技术指标背离)
TECHNICAL_CONFIG = FxStrengthConfig()
TECHNICAL_CONFIG.price_difference_weight = 25
TECHNICAL_CONFIG.breakthrough_weight = 15
TECHNICAL_CONFIG.volume_weight = 10
TECHNICAL_CONFIG.rsi_divergence_weight = 25
TECHNICAL_CONFIG.macd_divergence_weight = 25
if __name__ == "__main__":
print("=== 分型强度配置演示 ===\n")
configs = {
"默认配置": DEFAULT_CONFIG,
"保守配置": CONSERVATIVE_CONFIG,
"激进配置": AGGRESSIVE_CONFIG,
"技术指标配置": TECHNICAL_CONFIG
}
for name, config in configs.items():
print(f"=== {name} ===")
config.print_config()
config.validate_config()
print()