Skip to content

Claude/continue previous work vvwws6 - #346

Open
harrisonm23-byte wants to merge 49 commits into
shiyu-coder:masterfrom
harrisonm23-byte:claude/continue-previous-work-vvwws6
Open

Claude/continue previous work vvwws6#346
harrisonm23-byte wants to merge 49 commits into
shiyu-coder:masterfrom
harrisonm23-byte:claude/continue-previous-work-vvwws6

Conversation

@harrisonm23-byte

Copy link
Copy Markdown

No description provided.

claude added 30 commits June 30, 2026 11:24
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
…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
…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
claude and others added 19 commits July 24, 2026 21:07
QQQ closed at 684.23 (IBS 0.17, 5DayLow also fired). Friday + quiet
volume give grade 2 despite SMA20<SMA50. Entry est 64.13 (7/27 open +2bp).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
Recreated book_state.json (lost in container recycle). Records 2 closed
A-sleeve trades (QQQ -1.04%, TQQQ -7.43%) and 1 open TQQQ position
(entry 66.07, 7/27). QQQ IBS=0.867 at 7/30 close triggers exit rule;
TQQQ sells at 7/31 open.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
QQQ IBS=0.867 at 7/30 close triggered exit. TQQQ sold 7/31 open
65.74 less 2bp = 65.73 vs entry 66.07. Worst mark was -12.6% on 7/29
(TQQQ 57.75) but bounce + gap-up recovered to -0.51%.

Book: 3 closed A-sleeve trades, 0 open. All positions flat.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
Five-pillar selection (rel vol >=5x, price 2-20, gain >=10pct, float <20M,
gap up 2pct), first-pullback entry on crossing candle, stop at pullback
low, 2:1 minimum target, 10am hard cutoff. Candidate for new sleeve
pending gauntlet: mechanized backtest on historical gappers with
realistic small-cap costs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
Pre-registered mechanical spec v1: five-pillar scan (Alpaca screener +
FMP float cache), first-pullback state machine on 1-min bars with
crossing-candle entry, pullback-low stop, and mechanized exits
(topping tail, heavy red, material red, slowdown, 9EMA break, 10am
flat). 0.5%/side slippage, 1%-through-stop fills. Runs after close in
the daily tracker loop; logs R-multiples to momentum_paper_log.json.
Machinery validated on SCKT 8/11 premarket (correct first-pullback DQ).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A6hZxScXSnjZkT7h87gMe8
momentum_paper.py: per-date DST offsets (EDT/EST), injectable bars,
raw exit prices for cost-stress recompute, squeeze-resumption fix
(a <2-candle dip no longer consumes the first pullback).

momentum_backtest.py: 3-stage no-lookahead backtest - full-market
daily scan (open-gap >=10%, open $2-20, morning relvol >=5x by 09:45),
1-min replay via the same frozen state machine, stats with percentile
distributions, exit-reason table, cost stress, initial-condition
quartile cuts, time-half split, concentration check.

Co-Authored-By: Claude Fable 5 <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>
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.

2 participants