Update Portfolio Stock
update_portfolio_stockUpdate an existing stock's total quantity and average buy price in your portfolio. Handles additional buys, quantity changes, and partial sells with weighted average calculations.
Instructions
Update the quantity and/or average price of an existing stock in the user's portfolio.
Use cases: • User says "I bought 10 more RELIANCE at ₹1,400" → you must calculate the new total qty and weighted avg price, then call this tool • User says "Change my TCS quantity to 50" → direct update • User says "I sold 5 shares of INFY" → reduce quantity (calculate new qty = old - 5)
IMPORTANT workflow for additional purchases:
First call get_user_portfolio to get current quantity and avg_price
Calculate: new_qty = old_qty + additional_qty
Calculate: new_avg = (old_qty × old_avg + additional_qty × purchase_price) / new_qty
Call this tool with the NEW total quantity and NEW weighted average price
For partial sells:
new_qty = old_qty - sold_qty (avg_price stays the same)
If new_qty = 0, use remove_portfolio_stocks instead
Both quantity and avg_price are required — always provide the final values.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Stock symbol to update (e.g. RELIANCE) | |
| quantity | Yes | New TOTAL quantity (not the additional amount) | |
| avg_price | Yes | New average buy price per share in ₹ |