forked from chiki2bum2/SniperGold_ML
56 lines
2.3 KiB
Python
56 lines
2.3 KiB
Python
# -*- coding: utf-8 -*-
| |||
"""Verifikasi akhir features_XAUUSD.npz: shape, NaN, variasi fitur, densitas label."""
| |||
import os
| |||
import json
| |||
import numpy as np
| |||
import datetime as dt
| |||
| |||
BASE = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),
| |||
"..", "..", "..", "Files", "AlgoForge", "Data"))
| |||
z = np.load(os.path.join(BASE, "features_XAUUSD.npz"))
| |||
F, F2, label, ATR, close, t = (z["F"], z["F2"], z["label"], z["ATR"],
| |||
z["close"], z["time"])
| |||
split_bar, split_pos = int(z["split_bar"]), int(z["split_pos"])
| |||
meta = json.loads(str(z["meta"]))
| |||
print(f"F={F.shape} F2={F2.shape} label={label.shape} ATR={ATR.shape} "
| |||
f"close={close.shape} time={t.shape}")
| |||
print(f"split_bar={split_bar} split_pos={split_pos}")
| |||
| |||
for nm, X in (("F", F), ("F2", F2)):
| |||
n_nan = int(np.isnan(X).sum()) + int(np.isinf(X).sum())
| |||
stds = X.std(0)
| |||
n_const = int((stds < 1e-12).sum())
| |||
print(f"{nm}: NaN/Inf={n_nan} | kolom konstan={n_const} | "
| |||
f"std min={stds.min():.3e} max={stds.max():.3e}")
| |||
| |||
# fitur F2 terakhir (regime) rentang
| |||
print("F2 kolom terakhir (p_lowvol/p_highvol): min=%.3f max=%.3f"
| |||
% (F2[:, 4].min(), F2[:, 5].max()))
| |||
| |||
# label & window
| |||
win = t >= dt.datetime(2018, 1, 1).timestamp()
| |||
mask = (label != 0) & win
| |||
midx = np.where(mask)[0]
| |||
n_bull = int((label[midx] == 1).sum())
| |||
n_bear = int((label[midx] == -1).sum())
| |||
tr, te = midx[:split_pos], midx[split_pos:]
| |||
print(f"\nberlabel={len(midx)} bull={n_bull} bear={n_bear} "
| |||
f"ratio={n_bull/n_bear:.3f}")
| |||
print(f"train={len(tr)} (bull={(label[tr]==1).mean():.3f}) | "
| |||
f"test={len(te)} (bull={(label[te]==1).mean():.3f})")
| |||
| |||
# densitas label: 24-bar forward = berapa jam sesi?
| |||
dts = t[midx + 24] - t[midx]
| |||
hours = dts / 3600.0
| |||
print(f"\n24-bar forward: median={np.median(hours):.2f} jam | "
| |||
f"p10={np.percentile(hours, 10):.2f} p90={np.percentile(hours, 90):.2f} "
| |||
f"| >8 jam: {(hours > 8).mean()*100:.1f}%")
| |||
| |||
# cek feature F untuk beberapa bar acak (sanity numerik)
| |||
i = midx[100000]
| |||
print(f"\ncontoh bar t={dt.datetime.fromtimestamp(int(t[i]), dt.timezone.utc)}: "
| |||
f"label={label[i]} ATR={ATR[i]:.4f} close={close[i]:.2f}")
| |||
print("F[:5] =", np.round(F[i, :5], 3))
| |||
print("F[15:19] =", np.round(F[i, 15:], 3))
| |||
print("F2 =", np.round(F2[i], 3))
| |||
print("\nOK.")
|