flex_analyze_pnl
Aggregate realized profit and loss from Interactive Brokers Flex XML trade reports. Group by symbol, month, year, asset category, or buy/sell, and filter by date or asset type to get a sorted breakdown.
Instructions
Aggregate realized P&L from trade records in a Flex XML report.
Only closing trades (open_close contains 'C') contribute to realized P&L.
Args: xml_content: Raw Flex XML string. group_by: Dimension to aggregate by — "symbol", "month", "year", "asset_category", or "buy_sell" (default "symbol"). asset_category: Filter by asset category e.g. STK, OPT, FUT (optional). from_date: Earliest trade date, YYYY-MM-DD (optional). to_date: Latest trade date, YYYY-MM-DD (optional).
Returns JSON with totals and a breakdown list sorted by realized_pnl descending.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| to_date | No | ||
| group_by | No | symbol | |
| from_date | No | ||
| xml_content | Yes | ||
| asset_category | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |