import pandas as pd import numpy as np import sys import os from core.biz.metrics_calculation import MetricsCalculation def test_k_shape(): # 创建测试数据 test_data = pd.DataFrame({ 'open': [9.3030000000], 'high': [9.3030000000], 'low': [9.3020000000], 'close': [9.3020000000] }) print("测试数据:") print(test_data) print() # 计算基本特征 test_data['high_low_diff'] = test_data['high'] - test_data['low'] test_data['open_close_diff'] = abs(test_data['close'] - test_data['open']) test_data['open_close_fill'] = test_data['open_close_diff'] / test_data['high_low_diff'] test_data['price_range_ratio'] = test_data['high_low_diff'] / test_data['close'] * 100 print("计算的特征:") print(f"high_low_diff: {test_data['high_low_diff'].iloc[0]}") print(f"open_close_diff: {test_data['open_close_diff'].iloc[0]}") print(f"open_close_fill: {test_data['open_close_fill'].iloc[0]}") print(f"price_range_ratio: {test_data['price_range_ratio'].iloc[0]}%") print() # 检查"一字"条件 price_range_ratio = test_data['price_range_ratio'].iloc[0] open_close_fill = test_data['open_close_fill'].iloc[0] print("条件检查:") print(f"price_range_ratio < 0.01: {price_range_ratio < 0.01}") print(f"open_close_fill > 0.9: {open_close_fill > 0.9}") print() # 使用MetricsCalculation类 mc = MetricsCalculation() # 为了测试,我们需要创建一个有足够数据的DataFrame # 复制测试数据多次以创建滚动窗口 extended_data = pd.concat([test_data] * 25, ignore_index=True) # 运行set_k_shape函数 result = mc.set_k_shape(extended_data.copy()) print("分类结果:") print(f"k_shape: {result['k_shape'].iloc[0]}") print() # 详细分析为什么没有被分类为"一字" print("详细分析:") print(f"价格范围比例: {price_range_ratio:.6f}%") print(f"实体占比: {open_close_fill:.6f}") print() if price_range_ratio < 0.01: print("✓ 满足价格范围比例 < 0.01% 的条件") else: print(f"✗ 不满足价格范围比例 < 0.01% 的条件 (实际: {price_range_ratio:.6f}%)") if open_close_fill > 0.9: print("✓ 满足实体占比 > 0.9 的条件") else: print(f"✗ 不满足实体占比 > 0.9 的条件 (实际: {open_close_fill:.6f})") if __name__ == "__main__": test_k_shape()