simulate_sell
Estimate profit or loss by simulating stock sales with FIFO matching. Enter a stock symbol and share quantity to calculate potential returns.
Instructions
Simulate selling a number of shares of a stock and estimate the profit or loss.
Args: symbol: The stock ticker symbol to simulate the sale for (e.g., TSLA) shares: The number of shares to simulate selling.
Returns: The estimated profit/loss from the simulated sale using FIFO matching, in dollars.
Example: simulate_sell("AAPL", 50) -> 123.45
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | ||
| shares | Yes |
Output Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- trader_tools.py:217-263 (handler)The 'simulate_sell' tool is registered using @mcp.tool() and implements logic to calculate the estimated profit/loss of a stock sale using FIFO matching, based on current holdings derived from a CSV and the live market price.
@mcp.tool() def simulate_sell(symbol: str, shares: int) -> float: """Simulate selling a number of shares of a stock and estimate the profit or loss. Args: symbol: The stock ticker symbol to simulate the sale for (e.g., TSLA) shares: The number of shares to simulate selling. Returns: The estimated profit/loss from the simulated sale using FIFO matching, in dollars. Example: simulate_sell("AAPL", 50) -> 123.45 """ # Build current holdings for this symbol holdings = [] for _, row in df.iterrows(): if row['symbol'] != symbol: continue if row['type'] == 'Buy': holdings.append((row['shares'], row['price_per_share'])) else: to_sell = row['shares'] while to_sell > 0 and holdings: qty, price = holdings[0] matched = min(qty, to_sell) if matched == qty: holdings.pop(0) else: holdings[0] = (qty - matched, price) to_sell -= matched proceeds = 0.0 sell_price = get_live_price(symbol) to_sell = shares while to_sell > 0 and holdings: qty, buy_price = holdings[0] matched = min(qty, to_sell) proceeds += matched * (sell_price - buy_price) if matched == qty: holdings.pop(0) else: holdings[0] = (qty - matched, buy_price) to_sell -= matched return round(proceeds, 2)