feat: 添加 cloudflare_pages、mysql_d1_backup_scheduler,更新 start_system、ensemble_models 及配置文件
This commit is contained in:
1 parent
6184c34a3a
commit
62110554d1
20 files changed
+1438
-19
No files matched your search
@@ -99,7 +99,7 @@ def fmt_result(pred, actual):
|
||||
|
||||
def main():
|
||||
print("=" * 110)
|
||||
print("2026年2月 BTC 1h 涨跌预测准确率测试 (DLinear, N-BEATS, TTM-R2) - ONNX Version")
|
||||
print("2026年3月 BTC 1h 涨跌预测准确率测试 (DLinear, N-BEATS, TTM-R2) - ONNX Version")
|
||||
print("输入:预测K线的前一根 | 对比:预测结果 vs 预测K线收盘价 | 时间:北京时间(UTC+8)")
|
||||
print("DLinear预测逻辑:整个df一次性预处理,按索引遍历窗口")
|
||||
print("=" * 110)
|
||||
@@ -168,9 +168,9 @@ def main():
|
||||
ttm_session = None
|
||||
|
||||
# ========== 步骤2: 获取测试数据 ==========
|
||||
print("\n[2/4] 获取2026年2月数据...")
|
||||
print("\n[2/4] 获取2026年3月数据...")
|
||||
fetcher = BinanceDataFetcher()
|
||||
df = fetcher.fetch_ohlcv('BTC', '1h', start_date='2025-10-01', end_date='2026-03-01', use_cache=False)
|
||||
df = fetcher.fetch_ohlcv('BTC', '1h', start_date='2026-01-01', end_date='2026-04-01', use_cache=False)
|
||||
|
||||
print(f"数据范围(UTC): {df['timestamp'].min()} -> {df['timestamp'].max()}")
|
||||
print(f"总行数: {len(df)}")
|
||||
@@ -221,28 +221,38 @@ def main():
|
||||
X_ttm = np.array(X_ttm, dtype=np.float32)
|
||||
idx_ttm_map = {v: k for k, v in enumerate(idx_ttm)}
|
||||
|
||||
# 找出2月(北京时间)的所有预测目标K线索引
|
||||
# 找出3月(北京时间)的所有预测目标K线索引
|
||||
# df 中每一行都是一根已收盘的K线,timestamp 是 UTC
|
||||
jan_targets = []
|
||||
for target_idx in range(1, len(df)):
|
||||
target_time_utc = df.iloc[target_idx]['timestamp']
|
||||
# 同样在筛选样本时也将时间向后移动一个小时
|
||||
target_time_utc = df.iloc[target_idx]['timestamp'] + timedelta(hours=1)
|
||||
target_time_bj = utc_to_beijing(target_time_utc)
|
||||
if target_time_bj.year == 2026 and target_time_bj.month == 2:
|
||||
if target_time_bj.year == 2026 and target_time_bj.month == 3:
|
||||
jan_targets.append(target_idx)
|
||||
|
||||
print(f"2月(北京时间)目标K线数: {len(jan_targets)}")
|
||||
print(f"3月(北京时间)目标K线数: {len(jan_targets)}")
|
||||
|
||||
results = []
|
||||
|
||||
for target_idx in jan_targets:
|
||||
target_time_utc = df.iloc[target_idx]['timestamp']
|
||||
# 原始timestamp表示k线的开始时间,因此预测的结果实际对应下一小时的k线。
|
||||
# 所以展示时需要将时间向后移动1小时。
|
||||
target_time_utc = df.iloc[target_idx]['timestamp'] + timedelta(hours=1)
|
||||
target_time_bj = utc_to_beijing(target_time_utc)
|
||||
|
||||
# 输入K线索引(前一根)
|
||||
input_idx = target_idx - 1
|
||||
current_close = df.iloc[input_idx]['close']
|
||||
target_close = df.iloc[target_idx]['close']
|
||||
actual_label = 1 if target_close > current_close else 0
|
||||
# 现在我们将预测目标设为下一根k线(即target_idx+1),
|
||||
# 输入使用它的前一根(等于原先的target_idx)。
|
||||
predicted_idx = target_idx + 1
|
||||
if predicted_idx >= len(df):
|
||||
# 已经到达数据末尾,无法构建完整样本,跳过
|
||||
continue
|
||||
input_idx = target_idx
|
||||
# 开盘/收盘对应预测k线
|
||||
open_price = df.iloc[predicted_idx]['open']
|
||||
close_price = df.iloc[predicted_idx]['close']
|
||||
# 实际涨跌以预测k线的开盘为基准
|
||||
actual_label = 1 if close_price > open_price else 0
|
||||
|
||||
# --- DLinear 预测 (ONNX) ---
|
||||
dl_pred = None
|
||||
@@ -304,8 +314,8 @@ def main():
|
||||
results.append({
|
||||
'time_utc': target_time_utc,
|
||||
'time_bj': target_time_bj,
|
||||
'current_close': current_close,
|
||||
'target_close': target_close,
|
||||
'open': open_price,
|
||||
'close': close_price,
|
||||
'actual': actual_label,
|
||||
'dlinear': dl_pred,
|
||||
'nbeats': nb_pred,
|
||||
@@ -324,7 +334,7 @@ def main():
|
||||
|
||||
total_samples = len(df_res)
|
||||
|
||||
print(f"\n[4/4] 准确率统计 (2026年2月,北京时间)")
|
||||
print(f"\n[4/4] 准确率统计 (2026年3月,北京时间)")
|
||||
print(f"总样本数: {total_samples}")
|
||||
|
||||
# ========== 每小时详细数据 ==========
|
||||
@@ -332,8 +342,9 @@ def main():
|
||||
print("每小时详细数据")
|
||||
print("=" * 110)
|
||||
|
||||
# 改为显示开盘/收盘
|
||||
hourly_header = (
|
||||
f"{'北京时间':<18} {'前收盘':>10} {'现收盘':>10} {'实际':>4} "
|
||||
f"{'北京时间':<18} {'开盘':>10} {'收盘':>10} {'实际':>4} "
|
||||
f"{'DL':>3} {'':>1} {'NB':>3} {'':>1} {'TTM':>3} {'':>1} {'集成':>4} {'':<1}"
|
||||
)
|
||||
|
||||
@@ -371,7 +382,7 @@ def main():
|
||||
ens_r = fmt_result(row['ensemble'], row['actual'])
|
||||
|
||||
print(
|
||||
f"{time_str:<18} {row['current_close']:>10.2f} {row['target_close']:>10.2f} {actual_str:>4} "
|
||||
f"{time_str:<18} {row['open']:>10.2f} {row['close']:>10.2f} {actual_str:>4} "
|
||||
f"{dl_str:>3} {dl_r:>1} {nb_str:>3} {nb_r:>1} {ttm_str:>3} {ttm_r:>1} {ens_str:>4} {ens_r:<1}"
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user