Assignment: Lotwise Portfolio Tracker
Objective
Build a simple tool to track portfolio trades using a lot system:
Buy (positive quantity) → creates a new lot.
Sell (negative quantity) → closes existing lots using FIFO and calculates realized P&L.
Show open positions and realized P&L clearly.
Requirements
Backend ([Link] + Postgres)
REST API endpoints:
o POST /trades → add trade (symbol, qty, price, timestamp).
o GET /positions → list open lots + average cost.
o GET /pnl → realized P&L summary.
Every new trade should also be published to Kafka.
Worker ([Link] + Kafka)
Consume trade events from Kafka.
Apply lot logic (create/close lots).
Update database with positions and realized P&L.
Frontend ([Link])
Page 1: Trade input form.
Page 2: Positions (open lots, avg cost).
Page 3: Realized P&L view.
Deliverables
1. Code in a public GitHub repo (well-structured + README).
2. README must explain:
o Data model (tables/relationships).
o How FIFO matching works.
o How to run locally.
o Any assumptions made.
3. Live working site link (deployed on free services is fine — e.g.
o Frontend → Vercel / Netlify
o Backend API + Kafka Worker → Render / Railway / Heroku (or Docker on free VM)
o Database → Supabase / Railway Postgres).
4. A short demo account or seeded trades so we can test the logic directly.
Test Scenario (for yourself)
1. Buy 100 AAPL @ 150
2. Buy 50 AAPL @ 160
3. Sell 80 AAPL @ 170
Expected:
Remaining open lots = 70 AAPL (20 from first, 50 from second).
Realized P&L correctly computed.