Claude/continue previous work vvwws6 - #346
Open
harrisonm23-byte wants to merge 67 commits into
Open
Conversation
Adds examples/analyze_market.py with three modes: - forecast: probabilistic forecast with sample-path quantile bands, plot + CSV - backtest: walk-forward model evaluation (directional accuracy, MAE/RMSE/MAPE) plus a forecast-driven long/flat strategy vs buy-and-hold - signal: decision-support JSON report (trend, support/resistance, implied return, dispersion-based confidence) Supports local model/tokenizer dirs for offline use and configurable CSV column mapping. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Snkpa9NxHpLnBphcE5Luy8
…_market Pulls daily OHLCV for US tickers/ETFs into the CSV schema analyze_market.py expects, sourcing stockanalysis.com with a Nasdaq API fallback. Enables running Kronos forecast/signal/backtest on live-fetched symbols like SPY and QQQ.
analyze_market backtest now reports grouped stats: directional (terminal + per-step accuracy, up/down precision, return correlation), accuracy (terminal MAPE mean/median/p90/worst, path MAPE, MAE/RMSE), bias (signed error, predicted vs actual return), strategy (win rate, profit factor, Sharpe, max drawdown), and naive baselines (buy-and-hold, majority-class direction). fetch_market_data gains an --interval flag for intraday bars (1m/5m/15m/30m/1h) via Alpha Vantage (--av-key / ALPHAVANTAGE_API_KEY), with --months for historical intraday. Daily remains keyless via stockanalysis/nasdaq.
Alpha Vantage moved intraday behind premium. Alpaca's free IEX feed provides 1m/5m/15m/30m/1h bars with generous rate limits via paper-trading keys. The fetcher now paginates via next_page_token for full history depth.
…ng symbols Adds fetch_alpaca_crypto() using the v1beta3 crypto endpoint, with auto-detection of crypto symbols and proper pagination. Output filenames now sanitize / characters so BTC/USD writes to BTCUSD_1h.csv instead of creating subdirectories.
New 'aggregate' mode forecasts N low-timeframe bars then rolls them up into candles at multiple aggregation levels (e.g. 5m -> 15m -> 30m -> 1h -> 2h), scoring each level on candle color (direction), close accuracy, high/low range error, and price-zone overlap (IoU). Tests whether the model reconstructs the coarser-timeframe candle's shape even when individual bars are noisy -- the 'does the paragraph match even if the words differ' framing.
- research/FINDINGS.md: frozen baseline grid, keeper specs, context grade, validated principles, debunked list, goal spec, loop state - engine.py: daily-bar backtest engine (next-open fills, stop/regime/hold support) - 26 study scripts: strategy suite, forensics, intraday scans, options sim, band-walk/trend-break studies, context dictionary, anomaly tests Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
…dies Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
…t debunk Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
…alidation Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
…nal, not directional
…(downside travels)
…track 2 untested)
…tries lose even in native habitat
…interaction Section 10 in FINDINGS.md. Key findings: - Down-down days recover 57% O→C, but first 30 min determines camp (70% bounce vs 33% flush) - Gap-fill probability scales linearly with magnitude (ladder quantified) - Adding down-down context to IBS doesn't improve it (decayed in 2021-26 half) - Not deployable as trades, but valuable as descriptive market laws Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
Entry 75.22 (7/14), exit est 71.23 (7/22 open - 2bp slip). Worst mark -10.2% on 7/20. Two consecutive A-sleeve losses. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
TQQQ gapped down from 71.37 close to 69.77 open on exit day. Actual fill 69.77 - 2bp = 69.63, ret = -7.43%. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
…%/side n=99 trades over 1yr. Raw edge +0.163 R/trade at zero slippage decays to -0.105 at 0.5%/side. Lottery-shaped: WR 32%, median R -0.62, max +9.13, top-5 winners carry the sum. Both halves negative at realistic costs. Mechanized topping-tail and material-red exits perform (+0.8R avg). Logged as FINDINGS section 9; forward paper log continues as the clean sample with float pillar applied. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
Measures pure price movement after each backtest entry with no exit mechanics: MFE/MAE within the morning window and full day, 10:00 and close checkpoints, and touch-based race between k*R targets and the pullback low. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
…momentum scan daily_bars omitted start, so Alpaca returned only the current day's bar and every pillar check saw insufficient history. Now fetches a 200-day window sorted desc and returns chronological bars. First forward scan 2026-08-11: 8 candidates, 3 trades logged (QMCO -0.33R heavy_red, STIM +0.16R heavy_red, GRI -1.14R stop). Floats pending FMP availability. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
QMCO 39.0M and STIM 28.3M exceed the 20M float pillar (flagged float_fail); GRI 90K, PLAG 11.6M, WXM 10.0M, AIFA 3.2M, MSGY 341K pass; NIQ 56.2M exceeds. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
BOXL closed below VWAP in pullback; QNTU and XHLD retraced >50%. A-sleeve: QQQ IBS 0.180 signal, grade 1 YELLOW (SMA20<SMA50), no entry. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
v2 keeps v1 entries and replaces the exit: no stop at the pullback low, take-profit limit ratcheting down as the post-entry dip deepens (20/15/12/8/4 at 0/2/5/10/20% dip), flat 10:00 ET. Schedule was designed on the 2025-08..2026-08 recovery matrix, so that window is in-sample; pass/fail criteria for the 2024-08..2025-08 out-of-sample window are declared in the spec before looking at it. Backtest harness now takes MOMO_START/MOMO_END/MOMO_TAG so the OOS year runs through the identical pipeline. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
v3 keeps v1/v2 entries and sells 25% at each of +5/+10/+20/+35%, moving the stop up to the previously crossed basecamp after each fill. Three pre-registered variants: no initial stop (primary), pullback-low stop, and a dip-conditioned ladder. Same pass/fail battery as v2. Harden backtest networking: retry on timeouts/5xx and checkpoint each scan chunk so a mid-scan failure doesn't discard completed work. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
IS 2025-08..2026-08 (n=98) vs OOS 2024-08..2025-08 (n=71), identical entries, exits varied. - v1 indicator exits replicate exactly OOS: -0.105 R/trade both windows. - v2 (no stop, take-profit ratcheting down with the post-entry dip) is the only scheme meeting all five pre-registered OOS criteria: +3.61%/trade, WR 75%, +2.99% at 1%/side, +2.41% ex-top5, both halves positive. - v3 laddered scale-out fails both windows; the pullback-low variant is the worst scheme tested, a third confirmation that stop placement is the damaging choice here. - Fragility: perturbations keeping dip-conditioning stay positive; removing it collapses to zero. The untuned flat control passed IS and failed OOS. - Survivorship measured by rescanning 1,322 delisted non-OTC symbols over the OOS window: 2 valid entries, both winners under v2. Adds MOMO_UNIVERSE override to the backtest for delisted-universe scans. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Rebuild follows the source notes rather than my tighter rules: every pullback evaluated, intraday qualification, no per-day cap. Candidate pool 1,213 -> 4,792; frequency now 2.3-3.6 trades/week as expected. Full faithful set with v2 exits is ~breakeven (+0.99% OOS, +0.44% IS at 0.5%/side) and negative at 1%/side. First-pullback entries lead in both windows (+5.70%/+1.25%) but robustness disagrees: OOS holds ex-top5 and at 1% costs, IS does not. Percentiles show p75/p90 identical across all buckets (targets cap winners); the entire edge is left-tail avoidance. Runner tranche rejected: selling 75% at target and riding 25% is worse at every trail width tested (20/30/40/50%, flat-10:00, hold-to-close), monotonically worse as the trail widens. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Followed the clue that monsters barely pull back after the target fills. Earlier runner test only went down to a 20% trail and wrongly concluded the runner was dead; tight trails reverse it. Hold to the dip-conditioned level then trail 100% instead of selling: pooled +3.68%/trade at a 2% trail vs +0.65% selling out, with OOS and IS agreeing to within 0.25pt at every width (n=309). Max trade rises from +19.4% to +244%, so this is the mechanism that captures the big movers. Runner fraction is monotone - sell none at the target. Binding constraint is fill quality, not the rule: at 5% slip-through the edge vanishes entirely. A 2-3% trail sits inside the spread on many of these names, which the backtest cannot resolve. Matches the source, which says do not cap winners and exit on the first weakness indicator. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…lter) Grid search over initial stop x activation x trail width x selectivity, scored on IS with OOS held out. System: pullback width >=8% and price <$8.30; no initial stop; arm at +4%; trail 0.75x ATR(14,1min); flat 10:00 ET. IS n=20 WR 70% +5.00%/trade OOS n=21 WR 71% +10.78%/trade POOL n=41 WR 71% +7.96%/trade, avg win +14.1%, avg loss -6.9% Key results: every fixed initial stop (6-20%) hurts monotonically, so downside control comes from arm-then-trail plus the time exit, which is what keeps the upside uncapped (p10 -1.5%, max +103.8%). Volatility-scaled trailing beats fixed-percentage. Selectivity dominates the exit choice. Double-digit mean per trade is reached pooled at 0% slip-through (+10.10%) and at k=0.5 (+10.44%) but not in both windows independently; recorded as partially achieved rather than claimed. Adds momentum_live.py, verified to reproduce the backtest exactly. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Arming the trailing stop at +2% instead of +4% is the breakthrough. v4's worst trades (-36.3%, -27.8%) were entries that dipped hard, never reached the +4% arm, and rode unprotected to the time exit. Arming at +2% means nearly every entry arms before it can collapse. System: pullback width >=8% and price <$8.30; no initial stop; arm at +2%; trail 0.25x ATR(14,1min); flat 10:00 ET. IS n=20 WR 90% +11.03%/trade OOS n=21 WR 90% +16.75%/trade POOL n=41 WR 90% +13.96%/trade 4 losers of 41, avg loss -1.8%, worst -2.7%; winners avg +15.7%, max +125.6% Upside uncapped, downside limited to scratches, double digits in both windows. Fill sensitivity is the caveat: holds while slip-through stays under ~3%. k=0.25 is deployed rather than the grid optimum (k=0.10) because 0.10 implies a 0.73% stop distance, inside the spread on these names. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
CURI stopped at 3.79 (-4.5%). XHG/FGI/DFSC retraced >50%; ARX no trigger. AHT preferred shares reached the candidate list - live scanner now skips preferreds/warrants/units like the backtest universe does. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
FGI (risk 4.6%) -0.92%, DFSC (4.5%) +6.69%, CURI (3.4%) -0.46% via ATR trail; all below the 8% pullback-width gate, logged as skips. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
Book state, momentum program timeline (v1 backtest through v5 deployment), forward-log status, established vs pending, nightly procedure. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
Drops book/legacy-research sections; now covers the deployed v5 system, two-window evidence, exit forensics, forward logs, and open questions. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
Rebuilds the per-trade table from faithful-engine results (both windows), applying the v5 selection filter and exit; writes momentum_v5_trades.md. Roster regeneration is running; the md follows when it completes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
…ster table The v5 filter (price <$8.30, width >=8%) is an optimization subset added after the Cameron entry, keeping 41/309 = 13% of base entries. Framing that presented subset frequency (~20/yr) or subset returns (+14%/trade) as the strategy's was a category error, now corrected in FINDINGS 9g. Master table: all 309 base entries with descriptive columns and boolean filter flags - filters are columns, never row-removal. Key result the table surfaces: the 268 skipped trades earn +4.48%/trade (72% WR) under the same exit. The base strategy at natural ~3/week frequency with the v5 exit is +5.74%/trade overall, positive in both windows (+6.45 OOS / +5.29 IS), and captures ~3x the aggregate return of trading the subset alone. The filter is a conviction tier, not the strategy. Also logs an open audit item: faithful scanner accepts 1-candle pullbacks where spec v1 required >=2. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Pullback now requires >=2 candles; crossing candle breaks the prior candle's high per the source (old code required a leg-high break, an accidental confirmation filter). No optimization filters, frozen exit. OOS: 109 entries (21 first-pullback), IS: 182 (32 first-pullback). Frozen exit on first-pullback: OOS +1.97%, IS +2.72%, pooled +2.42% (n=53, WR 58%). Later pullbacks +0.11%/+1.41%. All positive but well below pre-correction numbers: the definitional fixes reduced measured performance, meaning earlier results partly reflected the unintended confirmation in the entry trigger. Logged without retuning. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Full trade-by-trade table with entry/exit times, prices, pullback widths, exit reasons, and returns. Pooled: n=40, WR 90%, mean +14.25%, worst -2.72%, best +125.58%. One trade fewer than the original n=41 run (minor data drift on regeneration); summary stats within 1.5pp. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
Descriptive transition study on all 291 corrected entries. P(new high) after a >=5% pullback is ~78% and flat across pullback order 1/2/3/4+, stable across both windows and at an 8% threshold; PB1 depth does not alter PB2 odds. Expansion legs 2+ are +18-19% median from trough, formed in minutes; the 22% failure branch ends the day -37% off the peak. The corrected entry lands at the top of the initiating thrust (leg 1 +2.9% median, 0 minutes). Nothing optimized; measurement conventions declared. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
… ~15% Zero-threshold episode decomposition (2,201 episodes / 291 ticker-days) replaces the fixed 5% pullback definition. P(new high | retracement >=X) decays smoothly from 85% at 2% depth to 40% at 20%, crossing 50/50 near 15%; no plateau or cliff. Day-weighted probabilities run 18-20pts below event-weighted (each day carries at most one terminal failure), cluster bootstrap CIs included. Terminal state is scale-invariant: ~-31% close vs peak whatever depth observes it. Next-leg advance grows with depth while odds fall - the tradeoff curve is the real object. Withdraws the "memoryless 78%" framing from the prior section. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
v5 (source-true entry): WETO entered 07:46 @ 11.40, risk 5.2% below the 8% width gate, logged as skip; its exit would have been +8.39% (trail). v1: AEYE stopped -2.43% (-1.25R). A-sleeve: no signals, QQQ IBS 0.453. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
…veat Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Adds funnel/frequency, raw movement, threshold-free recovery curve, escalation ladder, next-leg advance percentiles, dip-buy downside, exhaustive fixed-level grid (all negative), exit comparison, and caveats including the superseded n=41 figure. Upstream README content untouched. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…uction A-sleeve: 8/17 QQQ IBS 0.113 grade 1 YELLOW (missed run, would have skipped); 8/18 QQQ+SPY 5DayLow grade -1 RED (3 red closes, vol 1.24x), skip. No book changes. Momentum 8/18: v5 entries XOS (risk 2.5%) and SLE (6.9%) below width gate, skips; v1 XOS stopped -1.12R. 8/17 reconstructed from daily bars: 1 entry IPST (risk 3.7%) skip, -0.13% under trail. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
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.
No description provided.