A Python-based tool for calculating investment returns across multiple brokerage accounts (IBKR, Exante, and Poems). The system processes broker-specific reports and generates standardized returns metrics including Time-Weighted Returns (TWR) and Internal Rate of Return (IRR).
pandas>=2.2.3
numpy>=2.0.2
numpy_financial>=1.0.0
openpyxl>=3.1.5
python-dateutil>=2.9.0
pytz>=2024.2
Install dependencies:
pip install -r requirements.txt
Create the following directory structure:
ReturnsCalculator/
├── Input/ # Input directory for raw broker files
│ ├── IBKR/ # IBKR input files
│ └── Exante/ # Exante input files
├── logs/ # Processing logs
└── results/ # Generated results
├── Combined/ # Asset-weighted composite results
├── IBKR_{client_name}/
└── Exante_{client_name}/
-
Export broker reports:
- IBKR: Export performance report as CSV from Client Portal/TWS
- Exante: Export account statement as CSV (tab-delimited)
-
Place the exported files in their respective directories:
Input/IBKR/{client_name}.csv Input/Exante/{client_name}.csv
-
Calculate returns:
python TWR_Calculator.py -i Input
This will:
- Automatically scan for and process all broker files
- Generate processed data files in client-specific subdirectories
- Calculate individual and composite returns
- Create timestamped result files in the results directory
The system processes broker files in three main steps:
-
Account Discovery
- Scans Input directory for CSV files
- Identifies client names from filenames
- Creates processing directories
-
Broker-specific Processing
- IBKR reports are split into component files:
- Allocation by Asset Class (NAV data)
- Deposits and Withdrawals
- Dividends, Fees, Interest details
- Exante reports are converted to:
- NAV.xlsx (daily portfolio values)
- Trades.xlsx (transactions and flows)
- IBKR reports are split into component files:
-
Returns Calculation
- Calculates sub-period returns between cash flows
- Computes monthly TWR through geometric linking
- Generates rolling 6-month returns
- Calculates IRR using cash flows and NAVs
- Creates asset-weighted composite returns
- Eliminates impact of cash flow timing
- Calculated between each cash flow
- Geometrically linked for longer periods
- Used for performance comparison
- Considers timing and size of cash flows
- Uses actual day count for annualization
- Represents investor's actual experience
- Calculated using numpy_financial.irr
- Asset-weighted using start-of-month NAVs
- Only includes active accounts
- Provides period-specific account lists
- Composite IRR from aggregated flows
Results are saved with timestamps (YYYYMMDD_HHMMSS):
-
Monthly Returns
- Monthly TWR values
- Start-of-month NAVs
- Used for composite calculations
-
Six-Month Returns
- Rolling 6-month periods
- Geometrically linked returns
- Performance trending analysis
-
Return Summary
- Total and annualized TWR
- Internal Rate of Return
- Period returns (2022, 2023, 2024 YTD)
- Active account listings
For detailed file formats and structures, see docs/files.md.
- All monetary values are converted to EUR
- Returns are calculated net of fees
- Reporting periods align with Feb-Jan cycle
- Logs are generated in the logs directory
- Results use YYYYMMDD_HHMMSS timestamps
- Validates input file formats
- Handles missing or corrupted data
- Logs processing errors and warnings
- Skips invalid return calculations
- Provides detailed error messages
The system requires Python 3.8+ and the following key packages:
- pandas: Data processing and analysis
- numpy: Numerical computations
- numpy_financial: IRR calculations
- openpyxl: Excel file handling
See requirements.txt for complete dependency list.