Skip to content

What (One-liner)

Gold (GC=F) direction signal: the rule path compares SMA(50) / SMA(200) with the current price three ways for BULLISH/BEARISH/NEUTRAL; an optional XGBoost path silently falls back to the rule on dependency failure.

How to use

Drag gold_price_predictor_v1 onto the Canvas, fill symbol (default GC=F) + optional use_xgboost (default False).

Typical usage:

symbol=GC=F, use_xgboost=False   # rule baseline
→ current_price, sma_50, sma_200, signal ∈ {BULLISH, BEARISH, NEUTRAL}

Core formulas

# Rule-based path:
close = yf.Ticker(symbol).history('1y').Close
sma_50, sma_200 = close.rolling(50, 200)

signal = BULLISH   if close[-1] > sma_50[-1] > sma_200[-1]
       = BEARISH   if close[-1] < sma_50[-1] < sma_200[-1]
       = NEUTRAL   else

volatility = close.pct_change().std() × sqrt(252) × 100   # annualized % (fixed v1.0.1)

# XGBoost path (optional; falls back on import error):
pred = pangura_core.prediction.gold_xgboost.predict_gold_direction(hist)

Assumptions & applicability

Assumptions: yfinance '1y' period + auto_adjust + SMA 50/200 hardcoded + COMEX continuous contract (GC=F).

Fits: medium/long-horizon direction for precious metals; safe-haven scenario input.

Does not fit: non-precious commodities, futures rollover, HFT, short windows.

Input / Output contract

{symbol: str, use_xgboost: bool}{current_price, data_points, sma_50, sma_200, signal, volatility} (rule-based), plus optional model / direction / confidence (XGBoost success).

Known limitations / not implemented

✅ KNOWN-BUG-GOLD-001 RESOLVED (2026-04-20, v1.0.1)

Original issue: the volatility formula was close.pct_change().std() × 100, i.e. daily vol × 100 (~1% magnitude), while the field name implies annualized. Fixed: the new formula × sqrt(252) × 100 correctly returns annualized percent (~16% magnitude for equity-like names).

How it surfaced: the 2026-04-20 post-audit — a user challenge that "Canvas looks fine" — triggered a full target review of the Tier 2 batch 5/6 goldens. The original golden was found to be deliberately locking buggy behaviour (the "KNOWN-BUG pattern"), but a 16× magnitude error in volatility affects user decisions too directly to defer. One-line fix + golden regenerated, v1.0.0 → v1.0.1.

Other known limitations

  1. RSI computed but NOT used in the signal (dead code)
  2. '1y' period + SMA 50/200 windows hardcoded
  3. 3-bucket discrete signal (no continuous confidence)
  4. Silent XGBoost fallback — dependency failures not reported to the caller
  5. NEUTRAL merges 'flat' + 'mixed' without distinction

References

Murphy (1999) Technical Analysis SMA crossovers + Baur-Lucey (2010) gold safe-haven evidence + Chen-Guestrin (2016) XGBoost. Full citations in the frontmatter.

Golden Test

tests/golden/fixtures/tier2/gold_price_predictor/ — a yfinance-Ticker-mock regression (rule-based path only), 1e-10 tolerance, 7 tests:

  • matches_snapshot — full output byte-equal
  • determinism — 5 reruns identical
  • bullish_signal — upward synthetic → BULLISH + strict monotonic check
  • bearish_signal — downward synthetic → BEARISH
  • neutral_signal — engineered (current > SMA200 but < SMA50) → NEUTRAL
  • result_structure — 6 fixed top-level keys (rule path)
  • xgboost_fallback_handles_missing_dep — use_xgboost=True with the dep missing does not raise

The XGBoost success path is NOT covered here — it belongs to the Tier 5 LLM-attestation scope.

Changelog

  • 1.0.1 (2026-04-20) — KNOWN-BUG-GOLD-001 resolved (volatility properly annualized)
  • 1.0.0 (2026-04-20) — First Active (Tier 2 batch 6, rule-based path)

Verifiable intelligence for the decisions that demand scrutiny.