A Trading Psychology Engine with Persistent Memory — detects FOMO, revenge trading, and overconfidence patterns, delivering real-time explainable coaching before trades execute.
Market analysis tools are abundant. What's scarce is a system that addresses the actual source of most retail trading losses: behaviour under emotional pressure. FOMO entries after a breakout you missed, revenge trades after a stop-out, and overconfident sizing after a winning streak — these patterns destroy accounts that have perfectly good strategies.
No existing tool detects these patterns in real time and intervenes before the trade executes with an explainable reason. Without explainability, traders reject the feedback. Without real-time interception, the insight arrives too late. Both properties were non-negotiable design constraints from day one.
Every incoming trade triggers a behavioral feature extraction step — pulling time-of-day, position sizing relative to baseline, win/loss streak, inter-trade interval, and price-action context from a rolling 24-hour session window stored in SQLite. These features feed a TensorFlow classifier, and every prediction is explained with SHAP before being translated into a coaching message.
The Rule Engine + SHAP layer converts raw feature importances into plain-English explanations: "You're sizing 2.4× above your session average immediately after two consecutive losses — this matches the revenge trading pattern." Actionable, specific, and impossible to dismiss as a black box.
My first naive thresholds (e.g. "2× average size = FOMO") produced too many false positives. Consulting actual traders revealed that context — market volatility and position type — changes thresholds significantly.
Early coaching messages were factual but clinical. User testing showed that empathetic, conversational phrasing dramatically increased the likelihood of the trader actually pausing before executing.
Raw SHAP computation added ~80ms of latency. Pre-computing SHAP values for the classifier's fixed feature set during startup and caching them at runtime brought this to under 2ms.
Trade data is deeply sensitive. I retrofitted local-first storage after launch — a painful refactor. Building local-first from day one would have been the correct default for any financial application.
The full source code is on GitHub. If you're building trading tools or fintech products, let's talk about explainable AI architectures.