Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 42 additions & 18 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ Prediction Analyzer is a modular Python application for analyzing prediction mar
│ - Source filtering │ │ - API settings │
│ - Fuzzy matching │ │ - Chart styling │
│ - Deduplication │ │ - Constants │
├──────────────────────┴──────────────────────┴───────────────────────────┤
│ metrics.py │ positions.py │ drawdown.py │
│ - Sharpe/Sortino │ - Open positions │ - Drawdown periods │
│ - Profit factor │ - Concentration │ - Recovery analysis │
│ - Win/loss streaks │ risk (HHI) │ - Duration tracking │
│ - Trade frequency │ - Unrealized PnL │ │
├──────────────────────┴──────────────────────┴───────────────────────────┤
│ tax.py │ comparison.py │ exceptions.py │
│ - Capital gains │ - Period comparison │ - Custom exceptions │
│ - FIFO/LIFO/Avg │ - Sharpe/win rate │ │
│ - Wash sale detect │ change tracking │ │
└─────────────────────────────────────────────────────────────────────────┘
┌──────────────────┼──────────────────┐
Expand Down Expand Up @@ -73,7 +84,13 @@ prediction_analyzer/
├── trade_filter.py # Market filtering, source filtering, deduplication
├── filters.py # Advanced filters (date, type, PnL)
├── pnl.py # PnL calculation and analysis (per-source breakdown)
├── metrics.py # Advanced trading metrics (Sharpe, Sortino, drawdown, streaks)
├── positions.py # Open positions, unrealized PnL, concentration risk (HHI)
├── drawdown.py # Drawdown analysis with recovery tracking
├── tax.py # Tax reporting (FIFO/LIFO/average cost basis, wash sales)
├── comparison.py # Period-over-period performance comparison
├── inference.py # Market outcome inference
├── exceptions.py # Custom exception classes
├── providers/ # Multi-market provider abstraction layer
│ ├── __init__.py # Auto-registers all 4 providers
Expand All @@ -94,7 +111,7 @@ prediction_analyzer/
├── reporting/ # Report generation
│ ├── __init__.py
│ ├── report_text.py # Text/console reports
│ └── report_data.py # CSV/Excel exports
│ └── report_data.py # CSV/Excel/JSON exports
├── utils/ # Utility functions
│ ├── __init__.py
Expand Down Expand Up @@ -183,6 +200,7 @@ class Trade:
tx_hash: str # Transaction hash (optional)
source: str # Provider: "limitless", "polymarket", "kalshi", "manifold"
currency: str # "USD", "USDC", or "MANA"
fee: float # Transaction fee (default: 0.0)
```

### Provider Configuration
Expand Down Expand Up @@ -250,7 +268,8 @@ Manifold API ──── ManifoldProvider.fetch_trades() ────┘
List[Trade]
├──► filter_by_date() ──┐
├──► filter_by_trade_type() ├──► Filtered List[Trade]
├──► filter_by_trade_type() │
├──► filter_by_side() ├──► Filtered List[Trade]
├──► filter_by_pnl() │
├──► filter_trades_by_market() │
└──► filter_trades_by_source() ──┘
Expand Down Expand Up @@ -282,7 +301,8 @@ Filtered Trades + Stats
│ └──► generate_text_report() ──► Text report
└──► Exports ──────┬──► export_to_csv() ──► CSV file
└──► export_to_excel() ──► XLSX file
├──► export_to_excel() ──► XLSX file
└──► export_to_json() ──► JSON file
```

## Component Details
Expand Down Expand Up @@ -410,7 +430,7 @@ Four chart types with different use cases:
### Reporting Module (`reporting/`)

- **report_text.py**: Console/text output formatting
- **report_data.py**: CSV and Excel export functionality
- **report_data.py**: CSV, Excel, and JSON export functionality

### MCP Server (`prediction_mcp/`)

Expand Down Expand Up @@ -495,25 +515,29 @@ Tkinter-based desktop application:
│ API Key / Wallet: [________________] │
│ Quick Actions: [Load File] [Load API] [Summary] [Dashboard] │
├─────────────────────────────────────────────────────────────────┤
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ Tabs: [Global Summary] [Market Analysis] [Filters] [Charts]│ │
│ ├─────────────────────────────────────────────────────────────┤ │
│ │ │ │
│ │ Tab Content Area │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│ ┌──────────────────────────────────────────────────────────────────────────────────────┐ │
│ │ Tabs: [Summary] [Market] [Trade Browser] [Filters] [Charts] [Portfolio] [Tax Report]│ │
│ ├──────────────────────────────────────────────────────────────────────────────────────┤ │
│ │ │ │
│ │ Tab Content Area │ │
│ │ │ │
│ └──────────────────────────────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────────────────
```

Features:
- Provider selection dropdown (auto/limitless/polymarket/kalshi/manifold)
- File loading with dialog (auto-detects provider format)
- API authentication with provider-appropriate credentials
- Tabbed interface for different views
- Market listbox with selection preservation
- Filter controls with validation
- Chart generation buttons
- Export functionality
- 7-tab interface: Global Summary, Market Analysis, Trade Browser, Filters, Charts, Portfolio, Tax Report
- Trade Browser with sortable treeview columns and market search
- Filter controls with date, type, side (YES/NO), and PnL validation
- Portfolio analysis: open positions, concentration risk (HHI), drawdown tracking
- Tax reporting: capital gains with FIFO/LIFO/average cost basis, wash sale detection
- Period-over-period performance comparison dialog
- Chart generation buttons (Simple, Pro, Enhanced, Dashboard)
- CSV, Excel, and JSON export functionality
- Keyboard shortcuts (Ctrl+O open, Ctrl+S save, Ctrl+F find, Ctrl+Q quit)

### MCP Server (`prediction_mcp/server.py`)

Expand Down Expand Up @@ -627,7 +651,7 @@ tests/
├── test_api_contracts.py # API contract validation
├── test_config_integrity.py # Configuration tests
├── test_data_integrity.py # Data handling tests
├── test_dataclass_contracts.py # Dataclass validation (13 fields)
├── test_dataclass_contracts.py # Dataclass validation (14 fields)
├── test_edge_cases.py # Edge case handling
├── test_filter_contracts.py # Filter function tests
├── test_imports.py # Import validation
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.0] - 2026-03-12

### Added
- GUI: Trade Browser tab with sortable treeview columns and market search
- GUI: Portfolio tab with open positions, concentration risk (HHI), and drawdown analysis
- GUI: Tax Report tab with FIFO/LIFO/average cost basis and wash sale detection
- GUI: Side filter (YES/NO) in Filters tab
- GUI: Period comparison dialog for comparing two date ranges
- GUI: JSON export support alongside CSV and Excel
- GUI: Keyboard shortcuts (Ctrl+O, Ctrl+S, Ctrl+F, Ctrl+Q)
- GUI: Currency and provider breakdowns in Global Summary

### Fixed
- GUI: Fixed compare_periods() dict key mismatches (total_trades→trades, total_pnl→pnl, sharpe_ratio→sharpe)
- GUI: Fixed concentration risk pct_of_total key (was exposure_pct)
- GUI: Fixed drawdown period date keys (start_date/end_date→start/end)
- GUI: Fixed HHI thresholds from 0-1 scale to correct 0-10000 scale
- GUI: Fixed empty date validation in period comparison dialog
- GUI: Replaced redundant manual provider calculation with API's by_source data

## [1.0.0] - 2026-03-10

### Added
Expand Down
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ python run_api.py

These invariants MUST be preserved. Breaking them causes cascading failures:

1. **Trade dataclass has exactly 13 fields** (in `trade_loader.py`):
`market, market_slug, timestamp, price, shares, cost, type, side, pnl, pnl_is_set, tx_hash, source, currency`
1. **Trade dataclass has exactly 14 fields** (in `trade_loader.py`):
`market, market_slug, timestamp, price, shares, cost, type, side, pnl, pnl_is_set, tx_hash, source, currency, fee`

2. **`pnl_is_set` semantics**: `True` means provider explicitly set PnL (including legitimate zero/breakeven). `False` means unset — FIFO calculator may update it. Never overwrite `pnl_is_set=True` trades.

Expand Down
33 changes: 23 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ A complete modular analysis tool for prediction market traders. Analyze past tra
- **Multi-platform support** - Load and analyze trades from 4 prediction market platforms
- Load trade history from JSON, CSV, or Excel (auto-detects provider format)
- Calculate global and market-specific PnL
- Filter trades by date, type, PnL thresholds, and source provider
- Export reports in multiple formats (CSV, Excel, TXT)
- Filter trades by date, type, side (YES/NO), PnL thresholds, and source provider
- Export reports in multiple formats (CSV, Excel, JSON)
- Interactive CLI menu for easy navigation

### For Novice Traders
Expand All @@ -32,6 +32,10 @@ A complete modular analysis tool for prediction market traders. Analyze past tra
- Advanced interactive charts with Plotly
- Multi-market dashboards
- Cross-provider portfolio analysis
- Portfolio position tracking with unrealized PnL and concentration risk (HHI)
- Drawdown analysis with recovery tracking
- Tax reporting with FIFO/LIFO/average cost basis methods and wash sale detection
- Period-over-period performance comparison
- Currency-separated PnL aggregation (real-money USD/USDC vs play-money MANA)
- FIFO PnL computation for providers without native PnL
- MCP server integration for Claude Code / Claude Desktop
Expand Down Expand Up @@ -85,13 +89,16 @@ The easiest way to use Prediction Analyzer is through the graphical interface:
python run_gui.py
```

The GUI provides:
- Provider selection dropdown (Limitless, Polymarket, Kalshi, Manifold)
- Point-and-click file loading with auto-format detection
- Visual trade statistics and summaries
- Easy market selection and analysis
- Interactive filters with form controls
- One-click chart generation and export
The GUI provides a 7-tab interface:
- **Global Summary** — Aggregate PnL with currency and provider breakdowns
- **Market Analysis** — Per-market PnL, charts, and outcome inference
- **Trade Browser** — Sortable, searchable trade list with market search
- **Filters** — Date, type, side (YES/NO), and PnL filters
- **Charts** — Simple, Pro, Enhanced, and Dashboard chart generation
- **Portfolio** — Open positions, concentration risk (HHI), drawdown analysis
- **Tax Report** — Capital gains with FIFO/LIFO/average cost basis, wash sale detection

Plus: provider selection dropdown, CSV/Excel/JSON export, keyboard shortcuts (Ctrl+O, Ctrl+S, Ctrl+F, Ctrl+Q), and period comparison dialog

### Interactive CLI Mode (Terminal-Friendly)
```bash
Expand Down Expand Up @@ -260,7 +267,13 @@ prediction_analyzer/
├── trade_filter.py # Trade filtering (market, source, dedup)
├── filters.py # Advanced filters (date, type, PnL)
├── pnl.py # PnL calculations (with per-source breakdown)
├── metrics.py # Advanced trading metrics (Sharpe, Sortino, drawdown, streaks)
├── positions.py # Open positions, unrealized PnL, concentration risk
├── drawdown.py # Drawdown analysis with recovery tracking
├── tax.py # Tax reporting (FIFO/LIFO/average cost basis, wash sales)
├── comparison.py # Period-over-period performance comparison
├── inference.py # Market outcome inference
├── exceptions.py # Custom exception classes
├── providers/ # Multi-market provider abstraction
│ ├── base.py # MarketProvider ABC + ProviderRegistry
│ ├── limitless.py # Limitless Exchange provider
Expand All @@ -275,7 +288,7 @@ prediction_analyzer/
│ └── global_chart.py # Multi-market dashboard
├── reporting/ # Report generation
│ ├── report_text.py # Text reports
│ └── report_data.py # Data exports (CSV/Excel)
│ └── report_data.py # Data exports (CSV/Excel/JSON)
├── utils/ # Utility functions
│ ├── auth.py # Multi-provider API authentication
│ ├── data.py # Limitless API data fetching
Expand Down
Loading
Loading