What is the Trading Analysis Dashboard?
The Trading Analysis Dashboard is a Flask-based web application designed to track and analyze stock trading performance. It provides real-time portfolio management, historical trade analysis, and comprehensive reporting to help understand trading patterns and portfolio performance.Core Components
Portfolio Manager
Portfolio Manager
Tracks current holdings including stocks, ETFs, and mutual funds with real-time price updates from Finnhub API. Displays allocation charts, performance metrics, and gain/loss analysis.Key capabilities:
- Add/edit/delete holdings
- Real-time price refresh
- Allocation visualization
- Performance tracking
Trading Analysis Engine
Trading Analysis Engine
Analyzes historical trading performance using a hybrid matching algorithm that combines broker-provided realized gains/losses with transaction history for broker-level accuracy.Key capabilities:
- Monthly P&L breakdown
- Trade-by-trade details
- Win/loss ratios
- Dividend tracking
Timeframe Analysis
Timeframe Analysis
Allows custom date range analysis to compare trading performance across different periods and identify trends.Key capabilities:
- Custom date ranges
- Period comparison
- Trend identification
- Performance reports
Trading Calendar
Trading Calendar
Visual calendar view showing daily trading activity with heat maps to quickly identify profitable and losing periods.Key capabilities:
- Monthly calendar view
- P&L heat mapping
- Pattern recognition
- Activity tracking
CSV Import System
CSV Import System
Supports bulk data import via CSV files for both portfolio holdings and transaction history with drag-and-drop interface.Key capabilities:
- Drag-and-drop upload
- Real-time processing feedback
- Upload history tracking
- Format validation
Application Flow
User Authentication
The application uses Google OAuth 2.0 for secure authentication. Users must be authorized (configured in environment variables) to access the system. Each user’s data is completely isolated.Data Structure
The application maintains three primary data entities:| Entity | Description | Key Fields |
|---|---|---|
| Users | Authentication and profile | email, brokerage_account, google_id |
| Holdings | Current portfolio positions | symbol, shares, cost_basis, current_price |
| Transactions | Historical trading activity | symbol, action, shares, price, date |
Hybrid Matching Algorithm
The trading analysis uses a sophisticated matching system:- Broker Realized Gains/Losses - Pre-calculated lot matches from broker statements provide definitive P/L for closed positions
- Transaction History - Complete buy/sell transaction records for verification and detail
- Hybrid Approach - Combines both sources to achieve broker-level accuracy while maintaining transaction-level detail
API Architecture
The application exposes a RESTful API with the following endpoint categories:Trading Data
Access monthly trading data, individual trades, and P/L information
Portfolio
Manage holdings and trigger price refresh operations
Authentication
OAuth endpoints and session management
Timeframe Analysis
Query performance across custom date ranges
Technology Stack
Backend
- Flask - Python web framework handling routing, templating, and business logic
- SQLAlchemy - ORM for database operations
- PostgreSQL - Relational database for data persistence
- Flask-Dance - OAuth integration for Google authentication
Frontend
- Bootstrap 5 - Responsive UI framework
- Chart.js - Interactive charts and visualizations
- jQuery - DOM manipulation and AJAX requests
- DataTables - Enhanced table functionality
External Services
- Finnhub API - Real-time stock price data
- Google OAuth 2.0 - User authentication
Data Models
Portfolio Holdings
Trading Transactions
Realized Gains
Configuration
The application is configured via environment variables:| Variable | Purpose |
|---|---|
FINNHUB_API_KEY | API key for price data |
GOOGLE_CLIENT_ID | OAuth client ID |
GOOGLE_CLIENT_SECRET | OAuth client secret |
AUTHORIZED_USERS | Comma-separated email list |
FLASK_SECRET_KEY | Session encryption key |
DATABASE_URL | PostgreSQL connection string |