Skip to main content
Glama

compute_indicators

Calculate technical indicators like RSI, MACD, and BBANDS for financial symbols to support trading strategy analysis and portfolio management.

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 primary handler function implementing the compute_indicators tool. Downloads 1 year of historical data for the given symbol using yfinance, computes the specified technical indicators (RSI, MACD, Bollinger Bands) using pandas_ta, handles data structure issues, and returns the last 10 rows of results as JSON string.
    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)
    Registration of the compute_indicators tool (along with related functions) as part of the 'Feature Engineering' category in the MCP 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"
    )
  • The register_tools helper function that dynamically registers imported tools like compute_indicators by applying the MCP @mcp.tool() decorator in a loop with logging.
    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
  • app.py:291-291 (registration)
    compute_indicators is included in the 'Technical Analysis' tool category for the Gradio UI toolbox (non-MCP usage).
    "Technical Analysis": [compute_indicators, rolling_stats, get_technical_summary],

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