portfolio
Calculate current stock holdings by analyzing trade history to show net shares for each symbol with positive balances.
Instructions
Show current portfolio holdings.
This tool calculates the net number of shares held for each stock symbol by summing all buy and sell trades in the trade history CSV.
Returns: A dictionary mapping stock symbols to their current number of held shares. Only symbols with a positive balance are included.
Example: portfolio() -> {"AAPL": 120, "GOOG": 60}
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- trader_tools.py:47-67 (handler)The 'portfolio' tool implementation. It uses the @mcp.tool() decorator for registration and calculates holdings from a global DataFrame 'df'.
@mcp.tool() def portfolio() -> dict[str, int]: """Show current portfolio holdings. This tool calculates the net number of shares held for each stock symbol by summing all buy and sell trades in the trade history CSV. Returns: A dictionary mapping stock symbols to their current number of held shares. Only symbols with a positive balance are included. Example: portfolio() -> {"AAPL": 120, "GOOG": 60} """ holdings = defaultdict(int) for _, row in df.iterrows(): if row['type'] == 'Buy': holdings[row['symbol']] += row['shares'] else: holdings[row['symbol']] -= row['shares'] return {k: v for k, v in holdings.items() if v > 0}