A QHacks 2026 Project
AI-Powered Trading Psychology Platform
Identify, understand, and overcome psychological trading biases with machine learning
CogniTrade is a comprehensive trading psychology platform that combines paper trading simulation with AI-powered behavioral analysis. It uses machine learning models to detect common psychological biases in your trading patterns, helping you become a more disciplined and profitable trader.
Most traders don't fail because of bad strategiesβthey fail because of psychological biases. CogniTrade helps you:
- π Track your trades with a realistic paper trading simulation
- π§ Detect psychological biases using ML models trained on trading behavior
- π¬ Get AI-powered insights from an expert trading coach
- π Improve your discipline with educational content and quizzes
Full-featured paper trading with real market data powered by the Alpaca Markets API:
- Market & Limit Orders β Execute buy/sell orders with market or limit pricing
- Stop-Loss & Take-Profit β Set automatic exit levels for risk management
- Watchlist Management β Track your favorite stocks with live price updates
- Position Tracking β Monitor P&L, average cost basis, and portfolio allocation
- Order History β Complete log of all trades with timestamps and notes
- Voice Memos β Record voice notes for trades using speech-to-text (Gradium API)
- Interactive Charts β Real-time candlestick charts with multiple timeframes
- Persistent Data β All data saved to localStorage for consistency across sessions
Upload your trade logs (or use your in-app trades) for comprehensive psychological analysis:
| Model | Detection Target | Algorithm |
|---|---|---|
| Overtrading Detector | Excessive trading frequency | XGBoost Classifier |
| Revenge Trading Detector | Post-loss aggressive trading | Custom ML Pipeline |
| Loss Aversion Detector | Holding losers / cutting winners | Pattern Analysis |
| Journal Bias Detector | NLP analysis of trade journals | RoBERTa Multi-Label |
- FOMO β Chasing trades out of fear of missing out
- Loss Aversion β Cutting winners early, holding losers too long
- Revenge Trading β Trading emotionally after losses to "win it back"
- Overtrading β Taking excessive low-quality trades
- Gambler's Fallacy β Believing in false patterns and "due" wins
An intelligent assistant powered by LangGraph + Backboard AI that:
- Analyzes your complete trading history with SQL queries
- Provides personalized feedback on your trading patterns
- Answers follow-up questions about specific trades
- Offers actionable advice for improving discipline
- Streams responses with real-time progress updates
- Behavior Summary β Quick-reference guide to the five trading biases
- Pre-Trade Checklist β Questions to ask before every trade
- Interactive Quiz β Test your bias recognition with real training examples
- Daily Intentions β Mindset prompts for disciplined trading
CogniTrade/
βββ src/ # React Frontend (Vite + TypeScript)
β βββ pages/ # Route pages
β β βββ Index.tsx # Dashboard with portfolio overview
β β βββ TradePage.tsx # Trading interface with charts
β β βββ SearchPage.tsx # Stock search and watchlist
β β βββ AnalysisPage.tsx # ML bias analysis + AI chat
β β βββ SummaryPage.tsx # Educational content + quiz
β β βββ SettingsPage.tsx # Account settings
β β βββ LogsPage.tsx # Trade history logs
β βββ components/ # Reusable UI components
β β βββ AlpacaMarketChart.tsx # Interactive stock charts
β β βββ TradePanel.tsx # Buy/sell order form
β β βββ AgentChat.tsx # AI expert chat interface
β β βββ LogUpload.tsx # Trade log upload + analysis
β β βββ BehaviorAnalysis.tsx # Bias score cards
β β βββ ui/ # Radix UI primitives
β βββ lib/
β βββ tradingStore.ts # Zustand state management
β
βββ backend/ # Python Flask Backend
β βββ app.py # Flask API routes
β βββ agent.py # LangGraph AI agent with DuckDB
β βββ models/ # ML model inference
β β βββ overtrading_model/
β β βββ revenge_trading_model/
β β βββ loss_aversion_trading_model/
β βββ journal_model_training_script/
β β βββ train_bias_detector.py # RoBERTa training
β βββ requirements.txt
β
βββ public/
βββ cognitrade_logo2.png
- Node.js 18+ and npm
- Python 3.10+
- API Keys (see below)
git clone https://github.com/yourusername/CogniTrade.git
cd CogniTradeCopy the example environment file and add your API keys:
cp .env.example .envEdit .env with your credentials:
# Alpaca Markets (for real-time stock data)
VITE_ALPACA_API_KEY=your_alpaca_key
VITE_ALPACA_SECRET_KEY=your_alpaca_secret
VITE_ALPACA_BASE_URL=https://paper-api.alpaca.markets
# Backend API URL (default for local dev)
VITE_API_URL=http://localhost:5001
# Gradium (for voice transcription)
GRADIUM_API_KEY=your_gradium_key
GRADIUM_REGION=us
# Backboard AI (for the AI trading expert)
BACKBOARD_API_KEY=your_backboard_key
# OpenAI (backup for AI features)
OPENAI_API_KEY=your_openai_keynpm installcd backend
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
cd ..Terminal 1 β Frontend:
npm run devTerminal 2 β Backend:
cd backend
source venv/bin/activate
python app.pyThe app will be available at http://localhost:5173 or http://localhost:8080
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Health check |
/health |
GET | Service status |
/transcribe |
POST | Single-shot audio transcription |
/transcribe/stream |
WebSocket | Real-time streaming transcription |
/analyze_journal |
POST | Analyze journal text for biases (RoBERTa) |
/analyze_trades |
POST | Analyze trade CSV for all three biases |
/agent/analyze |
POST | Full AI analysis with ML + expert report (SSE) |
/agent/chat |
POST | Follow-up chat with the AI expert (SSE) |
For the /analyze_trades and /agent/analyze endpoints, upload a CSV with these columns:
| Column | Type | Description |
|---|---|---|
timestamp |
datetime | Trade execution time |
asset |
string | Stock symbol (e.g., AAPL) |
side |
string | "buy" or "sell" |
quantity |
number | Number of shares |
entry_price |
number | Entry price per share |
exit_price |
number | Exit price per share |
profit_loss |
number | P&L for the trade |
balance |
number | Account balance after trade |
| Technology | Purpose |
|---|---|
| React 19 | UI framework |
| TypeScript | Type safety |
| Vite | Build tool & dev server |
| TailwindCSS | Utility-first styling |
| Radix UI | Accessible component primitives |
| Zustand | State management |
| Motion | Animations |
| Recharts | Data visualization |
| Lightweight Charts | Stock candlestick charts |
| React Query | Server state management |
| Technology | Purpose |
|---|---|
| Flask | Web framework |
| Flask-CORS | Cross-origin requests |
| Flask-Sock | WebSocket support |
| Pandas | Data manipulation |
| scikit-learn | ML utilities |
| XGBoost | Overtrading model |
| PyTorch | Deep learning runtime |
| Transformers | RoBERTa bias detector |
| LangGraph | AI agent orchestration |
| Backboard SDK | AI thread management |
| DuckDB | In-memory SQL for trade analysis |
The overtrading detector uses XGBoost trained on windowed trading features:
- Trade frequency per window
- Average position size deviation
- Time between trades
- Win/loss streaks
The RoBERTa-based NLP model is trained on labeled trading journal entries:
cd backend/journal_model_training_script
python train_bias_detector.pyTraining data is in backend/rational_training/train.json.
| Dashboard | Trading | Analysis |
|---|---|---|
| Portfolio overview with P&L | Real-time charts + order form | ML bias scores + AI chat |
This project is licensed under the MIT License β see the LICENSE file for details.
- Alpaca Markets for real-time market data
- Backboard AI for AI agent infrastructure
- Gradium for speech-to-text
- Radix UI for accessible components
- TradingView Lightweight Charts for stock charts
Made with β€οΈ for disciplined traders everywhere.