Self-healing ML for stock prediction
Detects when market conditions drift beyond training distribution, retrains automatically using walk-forward cross-validation, shadow trades the candidate model, then promotes or rolls back. No human in the loop.
When drift is detected, a LangGraph agent activates and walks through the full remediation cycle autonomously.
PSI and KL divergence computed across feature groups. Drift type classification routes to the correct remediation path.
Every component is swappable. yfinance ships as the free default. Polygon.io, Alpaca, and Anthropic activate when keys are set.
LangGraph with typed Pydantic state. Each node is independently testable. The LLM only touches two nodes — everything else is deterministic Python.
def node_diagnose(state: AgentState) -> AgentState: """LLM-powered drift diagnosis and remediation planning.""" drift_report = state.get("drift_report", {}) diagnosis, plan = llm_diagnose(drift_report, perf, state["ticker"]) state["diagnosis"] = diagnosis state["action_plan"] = plan return log_step(state, "diagnose", "info", f"Plan: {plan}") def node_retrain(state: AgentState) -> AgentState: """Walk-forward retrain. HPO only on concept drift.""" run_hpo = state.get("drift_type") in ("concept", "volatility_regime") result = walk_forward_train( ticker=state["ticker"], run_hpo_flag=run_hpo, ) state["retrain_result"] = result return log_step(state, "retrain", "info", f"sharpe={result['overall_sharpe']:.2f} version={result['version']}") # Graph wiring graph.add_edge("ingest", "detect") graph.add_edge("detect", "diagnose") graph.add_edge("diagnose", "retrain") graph.add_edge("retrain", "backtest") graph.add_edge("backtest", "shadow") graph.add_edge("shadow", "promote")
Clone it, add your API keys, and run make full to train, backtest, and launch the dashboard in one command.