Skip to main content
Glama

compute_indicators

Calculate technical indicators like RSI, MACD, and Bollinger Bands for trading symbols to support quantitative analysis and strategy development.

Instructions

Calculates technical indicators for a symbol. Args: symbol: Ticker symbol. indicators: List of indicators (e.g., ['RSI', 'MACD', 'BBANDS']).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYes
indicatorsNo

Implementation Reference

  • The core handler function that downloads 1 year of stock data using yfinance, computes specified technical indicators (RSI, MACD, Bollinger Bands) using pandas_ta, and returns the last 10 rows as JSON string. Includes error handling for data fetch and computation.
    def compute_indicators(symbol: str, indicators: List[str] = ["RSI", "MACD"]) -> str: """ Calculates technical indicators for a symbol. Args: symbol: Ticker symbol. indicators: List of indicators (e.g., ['RSI', 'MACD', 'BBANDS']). """ df = yf.download(symbol, period="1y", progress=False) if df.empty: return f"No data for {symbol}" # Handle MultiIndex if isinstance(df.columns, pd.MultiIndex): df.columns = df.columns.get_level_values(0) result = df[['Close']].copy() for ind in indicators: try: if ind.upper() == "RSI": result['RSI'] = ta.rsi(df['Close']) elif ind.upper() == "MACD": macd = ta.macd(df['Close']) result = pd.concat([result, macd], axis=1) elif ind.upper() == "BBANDS": bb = ta.bbands(df['Close']) result = pd.concat([result, bb], axis=1) # Add more as needed except Exception as e: return f"Error computing {ind}: {str(e)}" return result.tail(10).to_json(orient="index")
  • server.py:390-393 (registration)
    Registers the compute_indicators tool (along with rolling_stats and get_technical_summary) to the FastMCP server using the register_tools helper function, which applies @mcp.tool() decorator to each.
    register_tools( [compute_indicators, rolling_stats, get_technical_summary], "Feature Engineering" )
  • server.py:16-16 (registration)
    Import statement bringing the compute_indicators function into the MCP server scope for registration.
    from tools.feature_engineering import compute_indicators, rolling_stats, get_technical_summary
  • Type hints defining the input schema: symbol (str), optional indicators list (defaults to RSI, MACD); output str (JSON). Docstring provides additional parameter descriptions.
    def compute_indicators(symbol: str, indicators: List[str] = ["RSI", "MACD"]) -> str: """ Calculates technical indicators for a symbol. Args: symbol: Ticker symbol. indicators: List of indicators (e.g., ['RSI', 'MACD', 'BBANDS']). """
  • Helper function used to register batches of tools, including compute_indicators, by dynamically applying the @mcp.tool() decorator and logging the process.
    def register_tools(tools: List[Callable], category: str): """Helper to register multiple tools with logging.""" for tool in tools: try: mcp.tool()(tool) logger.info(f"Registered {category} tool: {tool.__name__}") except Exception as e: logger.error(f"Failed to register {tool.__name__}: {e}") raise

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/N-lia/MonteWalk'

If you have feedback or need assistance with the MCP directory API, please join our Discord server