QTrade/check_indicators.py
cuizhan 43ab91b44d 重构数据系统:ta-lib指标、RSI多周期、数据库精度优化、表结构统一
核心改进:
- 指标计算:全部切换为ta-lib实现(MACD/KDJ/BOLL)
- RSI指标:新增多周期RSI(6/12/24),列名rsi_fast/mid/slow
- 数据精度:数据库DECIMAL(10,3)支持ETF 3位小数,下载器round(x,3)
- 表结构:所有表使用(symbol,timestamp)复合主键,移除id自增
- 表命名:统一为indicators_{period}_{indicator}格式,删除42个旧表
- 自动计算:DataProvider下载后自动计算并保存指标
- 列名规范:macd_dif/dea/histogram, kdj_k/d/j, boll_upper/mid/lower
- KlineReader:保留timestamp和symbol列供指标计算使用

已验证:1m周期2400+条数据,所有指标正常计算保存
2025-12-17 22:58:22 +08:00

45 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""检查指标数据"""
import pymysql
conn = pymysql.connect(
host="localhost", user="root", password="1234", database="qtrade_backtest"
)
cursor = conn.cursor()
# 检查各个指标表的数据
indicators = ["macd", "kdj", "boll", "rsi"]
periods = ["1m", "1d"]
symbol = "159915.SZ"
print(f"检查 {symbol} 的指标数据:\n")
for period in periods:
print(f"=== {period} 周期 ===")
for indicator in indicators:
table_name = f"indicators_{period}_{indicator}"
cursor.execute(f"SELECT COUNT(*) FROM {table_name} WHERE symbol='{symbol}'")
count = cursor.fetchone()[0]
print(f" {indicator}: {count} 条")
print()
# 查看MACD 1m的样例数据
print("MACD 1m 样例数据(最近5条):")
cursor.execute("""
SELECT timestamp, symbol, macd_dif, macd_dea, macd_histogram
FROM indicators_1m_macd
WHERE symbol='159915.SZ'
ORDER BY timestamp DESC
LIMIT 5
""")
rows = cursor.fetchall()
if rows:
for row in rows:
print(
f" {row[0]} | {row[1]} | DIF:{row[2]:.6f} | DEA:{row[3]:.6f} | MACD:{row[4]:.6f}"
)
else:
print(" 无数据")
conn.close()