Skip to main content

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

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
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
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
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
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:
EntityDescriptionKey Fields
UsersAuthentication and profileemail, brokerage_account, google_id
HoldingsCurrent portfolio positionssymbol, shares, cost_basis, current_price
TransactionsHistorical trading activitysymbol, action, shares, price, date

Hybrid Matching Algorithm

The trading analysis uses a sophisticated matching system:
  1. Broker Realized Gains/Losses - Pre-calculated lot matches from broker statements provide definitive P/L for closed positions
  2. Transaction History - Complete buy/sell transaction records for verification and detail
  3. Hybrid Approach - Combines both sources to achieve broker-level accuracy while maintaining transaction-level detail
See Hybrid Matching for technical details.

API Architecture

The application exposes a RESTful API with the following endpoint categories:

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

class Holding:
    id: int
    user_id: int
    symbol: str
    shares: float
    average_cost: float
    type: str  # stock, etf, mutual_fund
    current_price: float
    last_updated: datetime

Trading Transactions

class Transaction:
    id: int
    user_id: int
    symbol: str
    action: str  # buy, sell
    shares: int
    price: float
    date: datetime
    account_number: str

Realized Gains

class RealizedGain:
    id: int
    user_id: int
    symbol: str
    date_acquired: datetime
    date_sold: datetime
    proceeds: float
    cost_basis: float
    gain_loss: float

Configuration

The application is configured via environment variables:
VariablePurpose
FINNHUB_API_KEYAPI key for price data
GOOGLE_CLIENT_IDOAuth client ID
GOOGLE_CLIENT_SECRETOAuth client secret
AUTHORIZED_USERSComma-separated email list
FLASK_SECRET_KEYSession encryption key
DATABASE_URLPostgreSQL connection string

Features Deep Dive