feat: reusable technical-analysis indicators and signal history models (#109)#113
Merged
Merged
Conversation
#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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.partition_by/order_byparameters; nothing hardcodes symbol/date.Models
markets/technical/technical_price_universe— unified adjusted OHLCV atsource_universe, symbol, exchange, dategrain across sp500 stocks (split-adjusted), sector / fixed-income / currency ETFs, major indices, and global markets. Clamps vendor OHLC inconsistencies solow <= close <= highalways 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) withsetup / triggered / active / completed / expiredstates.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-relativeworked_*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)
ARRAY_AGGdoesn't supportIGNORE NULLS.technical_signal_events— thresholds editable without touching the SQL skeleton; a YAML seed registry can follow in phase 2.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).Out of scope (per issue)
🤖 Generated with Claude Code