get_stock_price_date_range
Retrieve historical stock prices for a specific symbol within a defined date range using YYYY-MM-DD format for accurate financial analysis.
Instructions
Get the stock prices for a given date range for a given stock symbol.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| end_date | Yes | The end date in YYYY-MM-DD format. | |
| start_date | Yes | The start date in YYYY-MM-DD format. | |
| symbol | Yes | Stock symbol in Yahoo Finance format. |
Implementation Reference
- src/mcp_yahoo_finance/server.py:220-229 (handler)The MCP tool handler for 'get_stock_price_date_range', registered via @mcp_instance.tool() decorator. It delegates execution to the yf_instance helper method.@mcp_instance.tool() def get_stock_price_date_range(symbol: str, start_date: str, end_date: str) -> str: """Get the stock prices for a given date range for a given stock symbol. Args: symbol (str): Stock symbol in Yahoo Finance format. start_date (str): The start date in YYYY-MM-DD format. end_date (str): The end date in YYYY-MM-DD format. """ return yf_instance.get_stock_price_date_range(symbol, start_date, end_date)
- The supporting method in the YahooFinance class that implements the core logic: retrieves historical closing prices for the given symbol and date range using yfinance, formats dates as strings, and returns JSON.def get_stock_price_date_range( self, symbol: str, start_date: str, end_date: str ) -> str: """Get the stock prices for a given date range for a given stock symbol. Args: symbol (str): Stock symbol in Yahoo Finance format. start_date (str): The start date in YYYY-MM-DD format. end_date (str): The end date in YYYY-MM-DD format. """ stock = Ticker(ticker=symbol, session=self.session) prices = stock.history(start=start_date, end=end_date) prices.index = prices.index.astype(str) return f"{prices['Close'].to_json(orient='index')}"