๐ Market Regime Agent (v1)
A deterministic, offline market context agent that classifies the current market regime using transparent signals and persistent memory.
Observe โ Reason โ Act โ Remember
This agent is designed to provide context, not predictions โ and to integrate cleanly with other trading and analysis agents.
๐ง What This Agent Does
MarketRegimeAgent answers one core question:
โWhat type of market environment am I operating in right now?โ
It classifies the market using explicit, rule-based signals:
Trend (moving averages)
Volatility (realized volatility)
Breadth (participation across assets)
Risk-On / Risk-Off (relative asset performance)
Example Output { "regime": "Risk-Off / Low Vol / Downtrend / Healthy Breadth", "confidence": 0.75, "drivers": [ "SPY below long-term trend", "Volatility below stress threshold", "Majority of assets above MA50", "SPY underperforming TLT" ], "implications": [ "Reduce exposure", "Avoid chasing breakouts", "Favor defensive positioning" ] }
โ What This Agent Does NOT Do
This is intentional.
MarketRegimeAgent does not:
Predict prices
Generate trade signals
Optimize returns
Backtest strategies
Fetch live market data
Call OpenAI or any LLM
Make any external API requests
Require API keys
It provides context, not alpha.
๐งฉ Design Philosophy
Market regimes are not a language problem โ they are a signal aggregation problem.
For that reason, this agent is:
โ Deterministic
โ Offline
โ Explainable
โ Testable
โ Reproducible
All logic is explicit. No hidden heuristics. No model hallucination.
LLMs, if used later, are limited to optional narration, never classification.
๐ Agent Loop
This agent implements a full agent lifecycle:
Observe
Ingests price history (CSV)
Validates structure
Reason
Computes signals
Classifies regime
Assigns confidence
Generates drivers & implications
Act
Detects regime changes
Applies alert cooldown logic
Remember
Persists last regime
Stores history
Prevents duplicate alerts
State is stored as JSON โ simple, portable, and GitHub-safe.
๐ Input Requirements (Important)
This agent only accepts price history CSVs in wide format.
โ Valid Input Example date,SPY,QQQ,IWM,TLT,GLD 2024-01-02,470,410,190,93,180 2024-01-03,472,412,191,92.8,181 ...
Required
date column
At least one market index (e.g. SPY)
Recommended
Risk-off proxy (TLT)
Multiple assets for breadth
โ Invalid Inputs
Do not upload:
Trade logs (trades.example.csv)
Execution history
Journals
Order data
Those belong to other agents (e.g. Trade Journal, Execution Discipline).
Uploading non-price CSVs may cause unrelated errors if other agents exist in the same project.
๐ Data Length & NaN Behavior
This agent uses rolling windows:
MA50 / MA200
20-day realized volatility
Breadth across assets
If your dataset has insufficient rows (typically < 200):
Some signals will be NaN
Confidence will be reduced
Regime classification will be conservative
No alerts will be fired
This is expected behavior.
The agent does not fabricate missing data.
๐ฆ Confidence Score
Confidence reflects signal completeness, not correctness.
1.00 โ all signals available
0.75 โ most signals available
0.25 โ insufficient data
Low confidence means:
โUse this as rough context, not a strong regime call.โ
๐ Memory & State
State is stored in:
state/memory.json
It tracks:
Last regime
Last alert date
Regime history
This enables:
Change detection
Alert deduplication
Longitudinal analysis
No databases required.
๐ฅ Running the App Install pip install -r requirements.txt
Run streamlit run app.py
Upload a valid price CSV or load the included sample file.
๐งช Testing Strategy (Recommended)
Run with โฅ 1 year of daily data
Confirm regime stability across days
Introduce a synthetic drawdown to test regime change
Verify alerts fire once per transition
Confirm memory persists across runs
This agent is tested for stability and interpretability, not prediction accuracy.
๐ Integration with Other Agents
MarketRegimeAgent is designed to be upstream context for:
Portfolio risk analysis
Sentiment interpretation
Trade journal diagnostics
Execution discipline enforcement
It improves downstream decisions without modifying them.
๐ฎ Future Extensions (Optional)
Optional LLM explanation layer
Live data adapters (yfinance, FRED, etc.)
Regime persistence (N-day confirmation)
Cross-asset confirmation
Multi-regime labeling
These are enhancements โ not requirements.
๐ฏ Summary
MarketRegimeAgent is a real agent, not a demo.
It is:
Offline
Deterministic
Transparent
Stateful
Integration-ready
If you are looking for predictions or automated trading, this is not the right tool.
If you want clear market context to support human decision-making, this agent is built for exactly that.