get_stock_price_date_range
Retrieve historical stock prices for a specific symbol within a defined date range using Yahoo Finance data.
Instructions
Get the stock prices for a given date range for a given stock symbol.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Stock symbol in Yahoo Finance format. | |
| start_date | Yes | The start date in YYYY-MM-DD format. | |
| end_date | Yes | The end date in YYYY-MM-DD format. |
Implementation Reference
- src/mcp_yahoo_finance/server.py:220-229 (handler)MCP tool handler for get_stock_price_date_range, decorated with @mcp_instance.tool() for registration. Delegates to YahooFinance instance 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)
- Core implementation in YahooFinance class: fetches historical stock prices using yfinance.Ticker.history() and returns Close prices as 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')}"