01-projects/investing

markov equities pipeline spec

2026-05-27·project·status: spec-pending-founder
markov-chainequitiespaper-tradingalpacamonte-carlokellyregime-modelingcapability-build

Markov-Chain Equities Pipeline — build spec (v0, pending founder)

Origin: founder shared a Polymarket Markov framework 2026-05-27 ([[2026-05-27-polymarket-markov-quant-framework]]), then: "No prediction markets, just stocks. Markov chains have always fascinated me but I've never put one into production. Curious about getting this pipeline built out." This is a capability + learning build with honestly-measured, modest edge expectations — not a money-printer. Paper-traded on the existing Alpaca scaffold; live trading off the table without explicit founder authorization.

⭐ UPDATE 2026-05-27 (founder direction) — capital-cycle state machine, NOT generic regimes

Founder redirected the formulation (and it's better than my v0 options): model the chip-fab / semiconductor capital cycle as the explicit state machine. "We are not day traders. Our most-developed theory is chip-fab capital cycles. We're in Phase 2 (capacity announcements), not yet Phase 3 (capacity online). That's a clear state machine — which phase are we in, what's the probability of moving to the next." Plus: discretized price buckets at multiple horizons as a complementary lens.

This is the anchored version — and it plugs into infra RDCO already has:

Two-layer architecture (supersedes the v0 "design decision" below):

  1. Capital-cycle phase tracker (macro, strategic — sets direction + conviction). States = cycle phases: P1 tight-supply/rising-ASP → P2 capacity-announcements (←here) → P3 capacity-online/glut → P4 capex-cuts/rationalization → back to P1. Honest wrinkle: only ~4-6 semi cycles in 40 yrs = too few to fit a transition matrix. So this layer = explicit phase definition + observable leading indicators (capex announcements, fab groundbreaks, fab-utilization, lead times, book-to-bill, inventory days, ASP trend) + informed transition priors, fed by /investing:label-historical-phases. It answers "what inning are we in + is the next-phase signal firing."
  2. Price-bucket multi-horizon Markov (tactical, data-rich — times entries). The actual transition-matrix + Monte-Carlo math from the source framework, run on chip-exposed tickers at weekly/monthly horizons (NOT daily — not day-traders). Times entries inside whichever phase Layer 1 says we're in.

Net: Layer 1 sets the bet (long the cycle through P1-P2, de-risk before the P2→P3 turn where the cycle kills people); Layer 2 sizes + times within it. Both paper-first, walk-forward. The two-layer design below (states/MC/calibrate/Kelly/limit-execution) still applies — it's Layer 2's machinery + the sizing/execution for both.


The core translation problem (why Polymarket→stocks isn't 1:1)

On Polymarket, price = probability (0-100¢ = P(YES)) with a fixed binary resolution, so a Markov chain over price-states maps directly to "P(YES at expiry)." Stocks have no bounded price, no binary outcome, no fixed expiry. So three things must be redefined:

Element Polymarket Equities adaptation
State contract price bucket (0-10¢…) NOT raw price. Either (a) forward-RETURN buckets, or (b) market REGIME (trend/range × vol-state)
Prediction target P(YES at resolution) forward-return distribution over horizon N (e.g. P(up >X% in N days), or expected N-day return)
Calibration vs binary resolution rates vs historical forward-return base rates for that state
Sizing / execution quarter-Kelly / maker limit same — both carry over directly

The design decision (recommend: regime-state, not price/return-level)

Pipeline (5 stages, equities-adapted)

  1. State definition — map each historical bar to a regime state via transparent rules (MA slope + realized-vol bucket). Keep it interpretable.
  2. Transition matrix — count regime→regime transitions over a long, multi-regime history; enforce ≥30 observations per state (the discipline the source article preached then violated). Per-ticker AND/OR pooled across a universe for robustness.
  3. Monte Carlo — from current regime, simulate forward paths → distribution of N-day forward returns. (Map regime-sequence → return draws via each regime's empirical return distribution.)
  4. Calibrate — compare model's predicted forward-return probabilities against realized historical base rates for that regime. If the model says "60% up" it must actually happen ~60% of the time. This is the load-bearing honesty check.
  5. Size + execute — quarter-Kelly position sizing on the calibrated edge; limit/DAY orders on Alpaca paper (maker discipline + the known [[feedback_alpaca_paper_opg_unreliable]] lesson: fractional DAY notional, not market-on-open).

Validation (non-negotiable, = our existing doctrine)

Per [[investing-backtest-thesis]]: walk-forward (re-estimate the transition matrix using only data available at each point — zero lookahead), survivorship-free universe (construct from point-in-time membership), out-of-sample test windows, leave-one-out reporting, honest confidence intervals (no 2-decimal Sharpe on tiny trade counts). A model that's brilliant with lookahead bias bleeds out live.

Phasing

First increment (reversible prep, buildable now on greenlight)

Phase 1 engine on historical data only — pure research/backtest, no Alpaca connection, no execution. Build as a todo-file + dynamic /loop sequenced build (per [[feedback_todo_file_loop_vs_notion_queue]]) with a running implementation-notes file (per [[feedback_implementation_notes_sub_agent_pattern]] — financial-execution-adjacent → decisions/deviations/open-questions logged). PR-only on the repo ([[feedback_pr_only_workflow]]).

Gates / guardrails

Open design questions for founder

Answered by founder 2026-05-27:

Still open:

  1. Layer-1 phase definitions: adopt the phases as already framed in [[2026-05-18-memory-cycle-v1.1]] verbatim, or re-derive a crisp 4-phase definition + the indicator thresholds that trigger each transition? (I'd reconcile the two and bring you one canonical phase ladder.)
  2. Universe: the chip-exposed names — pure-play memory (MU + the SK Hynix / Samsung ADRs), or broader semi-cap-equipment + foundry (AMAT/LRCX/KLAC/TSM)? Different names sit at different points in the same cycle (equipment leads, foundry lags).
  3. Repo: new markov-cycle repo, or fold into the existing Alpaca/autoinv scaffold?

(Phase-1 engine build doesn't block on these — they shape Layer-1 + Phase-2 paper-trading.)

Related