QTrade/check_precision.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

54 lines
1.4 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.

"""验证159915.SZ的数据精度"""
import pymysql
conn = pymysql.connect(
host="localhost", user="root", password="1234", database="qtrade_backtest"
)
cursor = conn.cursor()
# 查看159915.SZ的1m数据样例
print("159915.SZ的1m数据样例(最近10条):")
cursor.execute("""
SELECT timestamp, open, high, low, close
FROM klines_1m
WHERE symbol='159915.SZ'
ORDER BY timestamp DESC
LIMIT 10
""")
rows = cursor.fetchall()
for row in rows:
print(f"时间: {row[0]}, 开: {row[1]}, 高: {row[2]}, 低: {row[3]}, 收: {row[4]}")
# 查看159915.SZ的1d数据样例
print("\n159915.SZ的1d数据样例(最近10条):")
cursor.execute("""
SELECT timestamp, open, high, low, close
FROM klines_1d
WHERE symbol='159915.SZ'
ORDER BY timestamp DESC
LIMIT 10
""")
rows = cursor.fetchall()
for row in rows:
print(f"时间: {row[0]}, 开: {row[1]}, 高: {row[2]}, 低: {row[3]}, 收: {row[4]}")
# 检查是否有3位小数的价格
print("\n检查是否有3位小数的价格(例如 x.xx5, x.xx1 等):")
cursor.execute("""
SELECT timestamp, close
FROM klines_1m
WHERE symbol='159915.SZ'
AND (close * 1000) % 10 != 0
LIMIT 5
""")
rows = cursor.fetchall()
if rows:
print("找到3位小数的价格:")
for row in rows:
print(f" 时间: {row[0]}, 收盘: {row[1]}")
else:
print("未找到3位小数的价格,可能数据被截断了")
conn.close()