rolling_stats
Compute rolling mean and volatility for financial symbols to analyze time-series data trends and market fluctuations.
Instructions
Computes rolling mean and volatility.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | ||
| window | No |
Implementation Reference
- tools/feature_engineering.py:43-55 (handler)The primary handler function implementing the rolling_stats MCP tool. It fetches 1 year of historical closing prices for the given symbol using yfinance, computes rolling mean and standard deviation over the specified window size (default 20), and returns the most recent 10 periods as JSON.def rolling_stats(symbol: str, window: int = 20) -> str: """Computes rolling mean and volatility.""" df = yf.download(symbol, period="1y", progress=False) if df.empty: return "No data" close = df['Close'] if isinstance(close, pd.DataFrame): close = close.iloc[:, 0] stats = pd.DataFrame() stats['Mean'] = close.rolling(window=window).mean() stats['Std'] = close.rolling(window=window).std() return stats.tail(10).to_json(orient="index")
- server.py:390-393 (registration)Registration of the rolling_stats tool within the Feature Engineering category using the register_tools helper, which applies the @mcp.tool() decorator to enable it in the FastMCP server.register_tools( [compute_indicators, rolling_stats, get_technical_summary], "Feature Engineering" )