get_stock_price_by_date
Retrieve historical stock prices for specific symbols and dates to analyze market trends and track investment performance.
Instructions
Get the stock price for a given stock symbol on a specific date.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Stock symbol in Yahoo Finance format. | |
| date | Yes | The date in YYYY-MM-DD format. |
Implementation Reference
- src/mcp_yahoo_finance/server.py:210-218 (handler)MCP tool handler for 'get_stock_price_by_date'. Decorated with @mcp_instance.tool(), defines input schema via annotations and docstring, and delegates execution to the YahooFinance instance method.@mcp_instance.tool() def get_stock_price_by_date(symbol: str, date: str) -> str: """Get the stock price for a given stock symbol on a specific date. Args: symbol (str): Stock symbol in Yahoo Finance format. date (str): The date in YYYY-MM-DD format. """ return yf_instance.get_stock_price_by_date(symbol, date)
- YahooFinance class helper method that implements the core logic: fetches historical stock data for a specific date using yfinance Ticker.history() and returns the closing price.def get_stock_price_by_date(self, symbol: str, date: str) -> str: """Get the stock price for a given stock symbol on a specific date. Args: symbol (str): Stock symbol in Yahoo Finance format. date (str): The date in YYYY-MM-DD format. """ stock = Ticker(ticker=symbol, session=self.session) price = stock.history(start=date, period="1d") return f"{price.iloc[0]['Close']:.4f}"