Created
February 24, 2026 19:48
-
-
Save vishalkg/1996f156c73e2b64e4d5b3f52ac39fd6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import csv | |
| import sys | |
| from datetime import datetime | |
| from collections import defaultdict | |
| today = datetime.now().strftime('%m/%d/%Y') | |
| trades = defaultdict(lambda: {'pnl': 0, 'qty': 0}) | |
| with open(sys.argv[1], encoding='utf-8-sig') as f: | |
| for row in csv.DictReader(f): | |
| symbol = row['Symbol(CUSIP)'] | |
| if not (symbol.startswith('SPXW') or symbol.startswith('SPY')) or row['Date Sold'] != today: | |
| continue | |
| st = row['Short Term Gain/Loss'].replace('$', '').replace(',', '').replace('+', '').strip() | |
| lt = row['Long Term Gain/Loss'].replace('$', '').replace(',', '').replace('+', '').strip() | |
| pnl = (float(st) if st and st != '--' else 0) + (float(lt) if lt and lt != '--' else 0) | |
| key = (row['Date Acquired'], symbol.split('(')[0]) | |
| trades[key]['pnl'] += pnl | |
| trades[key]['qty'] += float(row['Quantity']) | |
| for (acq, sym), data in sorted(trades.items()): | |
| print(f"{acq} -> {sym} (qty: {data['qty']:.0f}): ${data['pnl']:,.2f}") | |
| print(f"\nTotal: ${sum(t['pnl'] for t in trades.values()):,.2f}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment