Inspiration
We were inspired by the National Bank Bias Detector Challenge at QHacks 2026. Behavioral finance research shows that cognitive biases cost retail traders significant returns, yet most traders are unaware of their own patterns. We wanted to build a tool that doesn’t just flag bad trades, but explains why they happened using machine learning explainability, and gives traders a concrete path to improve through AI coaching.
What it does
BiasLens analyzes a trader’s CSV trade log to detect three cognitive biases:
- Overtrading
- Loss Aversion
- Revenge Trading
Features:
Bias Score Cards A 0–100 score for each bias, with severity ratings and a clear rationale.
SHAP Explainability Expandable per-bias charts showing exactly which of the 18 behavioral features drove the ML model’s prediction.
Interactive Insights Time-bucketed trade frequency, cumulative PnL, and per-period PnL charts with configurable granularity (from 1 minute to 1 day).
Flagged Trade Table Sortable and filterable table highlighting specific trades that triggered bias detectors, including tags and explanations.
What-If Simulator Counterfactual analysis that replays trades under behavioral rules (cooldown after loss, daily trade caps, position size limits) and shows potential PnL improvement.
AI Coaching A Gemini-powered personalized coaching report with a 7-day correction plan tailored to the trader’s bias profile.
News Context Market headlines for each trading day, with Gemini interpretations of how events may have triggered biased behavior.
AI Chat A stateful AI coach with full context of the user’s analysis results for follow-up questions and guidance.
How we built it
Backend (Python / FastAPI) We implemented three rule-based heuristic detectors, each targeting a specific bias with domain-specific scoring formulas.
- Overtrading uses rolling 10-minute burst windows and daily frequency analysis.
- Loss aversion compares hold-time ratios between winning and losing trades.
- Revenge trading detects rapid re-entries with increased position sizes after losses, including streak-based loss detection.
Machine Learning Pipeline We generated 40,000 synthetic trades across four behavioral profiles: calm, overtrading, loss-averse, and revenge trading. From this data, we engineered 18 behavioral features covering trade frequency, performance statistics, position sizing behavior, and bias-specific indicators. Features are extracted from 50-trade sliding windows with a stride of 25. We trained an XGBoost multi-class classifier achieving ~83.5% cross-validation accuracy across all four classes.
Hybrid Scoring The analysis engine blends heuristic and ML scores using a configurable ratio (default 60% heuristic / 40% ML), with three modes: Rules Only, ML Only, and Mixed. This balances transparency with pattern-detection power.
SHAP Explainability We integrated SHAP TreeExplainer to compute per-feature contributions for each bias class, rendered as diverging stacked bar charts on the frontend. Traders can see exactly which behaviors pushed predictions toward specific biases.
Frontend (Next.js / TypeScript) A responsive single-page dashboard built with Next.js 14, Recharts, TanStack Table, Radix UI, and Tailwind CSS. The CSV upload flow auto-detects column mappings from 40+ common aliases, supporting trade logs from most platforms out of the box.
LLM Integration Google Gemini 1.5 Flash powers coaching reports, news interpretation, per-trade insights, and the stateful AI chat, with rate limiting and graceful fallback when API keys aren’t configured.
Challenges we ran into
Capturing complex temporal behavioral patterns
What we learned
- How to engineer behavioral features from raw trade data that capture temporal dynamics like burst trading, loss streaks, and hold-time asymmetry
- The strength of hybrid systems: rule-based methods provide transparency and control, while ML captures subtle, non-obvious patterns—combining both outperforms either alone
What’s next for BiasLens
- Direct brokerage integrations (Interactive Brokers, Alpaca, Binance) for live monitoring
- Real-time alerts to detect bias as it forms, before the next bad trade
Built With
- docker
- fastapi
- github-actions
- google-gemini-api
- next.js
- numpy
- pandas
- pydantic
- python
- radix-ui
- react
- recharts
- scikit-learn
- shap
- tailwind-css
- tanstack-table
- typescript
- xgboost
Log in or sign up for Devpost to join the conversation.