rolling_stats
Calculate rolling mean and volatility for financial symbols to analyze price trends and market fluctuations over specified time windows.
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 core handler function for the 'rolling_stats' tool. Downloads 1y price data via yfinance, computes rolling mean and standard deviation (volatility) over the specified window on closing prices, and returns the last 10 values 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 (along with related feature engineering tools) to the MCP server using the register_tools helper, which applies @mcp.tool() decorator.register_tools( [compute_indicators, rolling_stats, get_technical_summary], "Feature Engineering" )
- app.py:291-291 (registration)Inclusion of rolling_stats in the tools_map dictionary under 'Technical Analysis' category for the Gradio UI toolbox interface."Technical Analysis": [compute_indicators, rolling_stats, get_technical_summary],