Files
stock-tax-analyzer/README.md
Eden Kirin e9360cbc08 Initial
2025-10-12 00:34:03 +02:00

4.5 KiB

Stock Tax Analyzer - Deployment Guide

A complete stock portfolio analyzer with tax-eligible holdings calculation, real-time prices, and stock split adjustments.

Project Structure

stock-tax-analyzer/
├── main.go              # Go backend server
├── go.mod               # Go module file
├── index.html           # React frontend app
├── Dockerfile           # Multi-stage Docker build
├── docker-compose.yml   # Docker Compose configuration
└── README.md           # This file

Features

  • 📊 Analyze Revolut trading statements
  • 💰 Real-time stock prices in EUR
  • 🏆 Tax-eligible holdings (stocks held >2 years)
  • 📈 Stock split adjustments (NVDA, TSLA, AAPL, GOOGL, AMZN)
  • 💵 Portfolio valuation with gain/loss calculations
  • 🔒 Runs entirely on your server - no data leaves your infrastructure

Quick Start

  1. Create a directory and copy all files:
mkdir stock-tax-analyzer
cd stock-tax-analyzer
# Copy: main.go, go.mod, index.html, Dockerfile, docker-compose.yml
  1. Build and run:
docker-compose up -d
  1. Access the application:
http://localhost:8080

Option 2: Using Docker

  1. Build the image:
docker build -t stock-analyzer .
  1. Run the container:
docker run -d -p 8080:8080 --name stock-analyzer stock-analyzer
  1. Access the application:
http://localhost:8080

Option 3: Manual Build (without Docker)

  1. Install Go 1.21 or higher

  2. Build the Go backend:

go build -o stock-analyzer main.go
  1. Create static directory:
mkdir -p static
cp index.html static/
  1. Run the server:
./stock-analyzer
  1. Access the application:
http://localhost:8080

How to Use

  1. Open the application in your browser
  2. Click "Click to upload CSV file"
  3. Select your Revolut trading statement CSV file
  4. Wait for the analysis to complete
  5. Review your portfolio:
    • Total Holdings: All your stocks
    • Tax-Eligible Holdings: Stocks bought more than 2 years ago

API Endpoint

POST /api/stock-prices

Fetches current stock prices from Yahoo Finance.

Request:

{
  "tickers": ["AAPL", "MSFT", "GOOGL"]
}

Response:

{
  "prices": {
    "AAPL": {
      "ticker": "AAPL",
      "usd": 150.25,
      "eur": 138.23,
      "success": true
    }
  },
  "exchangeRate": 0.92
}

Configuration

Environment Variables

  • PORT: Server port (default: 8080)
  • TZ: Timezone (default: Europe/Zagreb)

Supported Stock Splits

The application includes historical stock split data for:

  • NVDA: 6 splits (including 10:1 in 2024)
  • TSLA: 2 splits (3:1 and 5:1)
  • AAPL: 5 splits (including 4:1 in 2020)
  • GOOGL: 1 split (20:1 in 2022)
  • AMZN: 4 splits (including 20:1 in 2022)

Architecture

Multi-stage Docker Build

  1. Stage 1 (static-builder): Prepares static HTML files
  2. Stage 2 (go-builder): Compiles Go backend
  3. Stage 3 (final): Clean Alpine image with binary and static files

Benefits:

  • Small final image size (~15MB)
  • No build tools in production image
  • Secure and efficient

Backend (Go)

  • HTTP server on port 8080
  • Fetches stock prices from Yahoo Finance
  • Handles CORS and rate limiting
  • Serves static frontend files

Frontend (React)

  • Pure client-side React app
  • No build step required
  • Processes CSV files in browser
  • Calls backend API for stock prices

Troubleshooting

Stock prices showing as N/A

  • Check if Yahoo Finance is accessible from your server
  • Verify network connectivity
  • Check Docker logs: docker-compose logs -f

Port already in use

Change the port in docker-compose.yml:

ports:
  - "9090:8080"  # Use port 9090 instead

File upload not working

  • Ensure the CSV file is a valid Revolut trading statement
  • Check browser console for errors
  • Verify file size is reasonable (<10MB)

Security Notes

  • Application runs entirely on your server
  • CSV files are processed in the browser (never sent to server)
  • Only stock tickers are sent to backend for price fetching
  • No data is stored or logged

Development

Running locally for development

# Terminal 1: Run Go backend
go run main.go

# Terminal 2: Serve static files (or just open index.html)
python3 -m http.server 8000

Then open http://localhost:8080 (backend serves both API and static files)

License

MIT License - Feel free to modify and use as needed.

Support

For issues or questions, check the application logs:

docker-compose logs -f stock-analyzer