Skip to content

feat: reusable technical-analysis indicators and signal history models (#109)#113

Merged
C00ldudeNoonan merged 1 commit into
mainfrom
feat/issue-109-technical-analysis
Jul 3, 2026
Merged

feat: reusable technical-analysis indicators and signal history models (#109)#113
C00ldudeNoonan merged 1 commit into
mainfrom
feat/issue-109-technical-analysis

Conversation

@C00ldudeNoonan

Copy link
Copy Markdown
Owner

Summary

Phase 1 of the reusable technical-analysis framework from #109: symbol-level indicator macros, a unified OHLCV universe, a wide daily indicator table, a signal event log with a full state machine, historical signal evaluation with forward returns, and current-setup / reliability surfaces for agents.

Closes #109 phase-1 acceptance criteria (the full ~50-indicator surface is intentionally phased; this PR establishes the framework plus the highest-value indicator subset named in the issue).

What's included

Macros (dbt_project/macros/technical_analysis/)

  • ta_primitives.sql — rolling aggregates (inclusive and prior-bar), lag/lead, z-score, range position, and the project-standard EMA/RMA implementation for BigQuery: a finite-window, weight-normalized exponentially weighted mean over window arrays (documented convergence; resolves the issue's open EMA question without a UDF).
  • ta_price_transforms.sql — typical/median/weighted price, true range, daily/log returns.
  • All macros take partition_by / order_by parameters; nothing hardcodes symbol/date.

Models

  • markets/technical/technical_price_universe — unified adjusted OHLCV at source_universe, symbol, exchange, date grain across sp500 stocks (split-adjusted), sector / fixed-income / currency ETFs, major indices, and global markets. Clamps vendor OHLC inconsistencies so low <= close <= high always holds.
  • markets/technical/technical_indicator_daily — SMA(20/50/200), EMA(12/26), RSI-14 (Wilder), MACD(12/26/9), Bollinger(20,2σ) + bandwidth percentile, ATR/NATR-14, ADX/+DI/-DI-14, Stochastic %K/%D, ROC-20, Williams %R, CCI-20, OBV, MFI-14, Donchian(20, prior-bar), relative volume, rolling z-score, 52-week distance. All indicators NULL until warmup completes.
  • signals/technical_signal_events — long-format event log driven by a jinja signal registry (14 signals: golden/death cross, SMA200 crosses, RSI recovery/reversal, MACD crosses, stochastic crosses, Bollinger squeeze breakouts, Donchian breakouts) with setup / triggered / active / completed / expired states.
  • analysis/technical_signal_instances — per-trigger forward returns at 1/5/10/21/63/126 bars, SPY benchmark + relative returns, MFE/MAE over 21 bars, and benchmark-relative worked_* labels. Future data exists only in this model.
  • signals/technical_current_setups — latest-bar setups/triggered/active per symbol (14-day staleness cutoff).
  • agents_preprocess/agent_technical_signal_setups / agent_technical_signal_history — agent-friendly current-state and reliability summaries.
  • signals/technical_signals — marked deprecated (SPY-only; VIX mean-reversion columns not yet migrated, noted in the model header).

Design decisions (issue open questions)

  • EMA standard: finite-window normalized EWM over window arrays (no recursive UDF). Arrays hold single-field STRUCTs because analytic ARRAY_AGG doesn't support IGNORE NULLS.
  • Worked definition: benchmark-relative vs SPY (absolute returns also provided so consumers can re-label).
  • Signal registry: jinja list inside technical_signal_events — thresholds editable without touching the SQL skeleton; a YAML seed registry can follow in phase 2.
  • Repeat triggers inside an active window are kept as events (standard event-study convention).

Validation

  • dbt build -s technical_price_universe+ in dev: 7 models + 56 tests, all passing (uniqueness at every grain, accepted values for states/sides/universes, bounds for RSI/stochastic/Williams %R/MFI/ADX/ATR/bandwidth, non-negativity checks).
  • Sanity-checked reliability aggregates: ~775k evaluable sp500 instances, hit rates clustered around 50% vs SPY as expected for raw signals; all 14 signals present with correct sides.
  • Rebuilt tables in dev: events 11.5M rows, instances 869k rows, indicator table 1.8M rows (45s build).

Out of scope (per issue)

  • No new ingestion; broader ETF universes need a separate Dagster issue.
  • Remaining indicator families (Ichimoku, SAR, Supertrend, KAMA, vortex, etc.) are phase 2+.

🤖 Generated with Claude Code

#109)

Phase 1 of the technical-analysis framework:

- macros/technical_analysis: window primitives, price transforms, and a
  finite-window exponentially weighted mean (project-standard EMA/RMA
  for BigQuery, documented convergence)
- technical_price_universe: unified adjusted OHLCV spine across sp500
  stocks (split-adjusted), sector/fixed-income/currency ETFs, major
  indices, and global markets, with OHLC consistency clamping
- technical_indicator_daily: SMA/EMA, RSI(Wilder), MACD, Bollinger,
  ATR/NATR, ADX/+DI/-DI, stochastic, ROC, Williams %R, CCI, OBV, MFI,
  Donchian, relative volume, z-score, 52w distance; warmup-gated NULLs
- technical_signal_events: jinja signal registry (14 signals) with
  setup/triggered/active/completed/expired state machine
- technical_signal_instances: forward returns at 1/5/10/21/63/126 bars,
  SPY-relative returns, MFE/MAE, worked labels (no lookahead outside
  this evaluation model)
- technical_current_setups + agent_technical_signal_setups/history:
  operational current-state and reliability surfaces
- deprecates SPY-only technical_signals (VIX columns not yet migrated)

Validated with dbt build in dev: 7 models + 56 tests, all passing.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@C00ldudeNoonan
C00ldudeNoonan merged commit 25ce43c into main Jul 3, 2026
2 checks passed
@C00ldudeNoonan
C00ldudeNoonan deleted the feat/issue-109-technical-analysis branch July 3, 2026 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add reusable technical-analysis indicators and signal history models

1 participant