Skip to main content
Glama

analyze_trends

Analyze stock price trends, market performance, or sector movements over time to identify patterns and make data-driven investment decisions.

Instructions

Analyze trends in stock prices, market performance, or sector movements over time

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
analysis_typeYesType of trend analysis to perform
targetYesCompany symbol, sector name, or "market" for overall analysis
periodNoNumber of days to analyze
include_forecastNoWhether to include simple trend forecast

Implementation Reference

  • The primary handler function for the 'analyze_trends' tool. It processes different analysis types ('company_trend', 'sector_trend', 'market_trend', 'correlation_analysis') by fetching relevant data from the database, performing calculations, and optionally generating forecasts.
    async analyzeTrends(analysisType: string, target: string, period: number = 30, includeForecast: boolean = false): Promise<any> {
      try {
        const analysis = {
          analysis_type: analysisType,
          target: target,
          period_days: period,
          timestamp: new Date().toISOString(),
          trend_data: null,
          forecast: null,
          insights: []
        };
    
        switch (analysisType) {
          case 'company_trend':
            const company = await this.db.getCompanyBySymbol(target);
            if (!company) throw new Error(`Company ${target} not found`);
            
            const historical = await this.db.getHistoricalPrices(company.id, period);
            analysis.trend_data = this.analyzePriceTrend(historical);
            analysis.insights = this.generateTrendInsights(analysis.trend_data, company);
            
            if (includeForecast) {
              analysis.forecast = this.generateSimpleForecast(historical);
            }
            break;
    
          case 'sector_trend':
            const sectorCompanies = await this.db.getCompaniesBySector(target);
            const sectorPerformance = await this.analyzeCompanyPerformances(sectorCompanies, period);
            analysis.trend_data = {
              sector: target,
              companies_analyzed: sectorCompanies.length,
              average_performance: sectorPerformance.reduce((sum, p) => sum + (p.period_change || 0), 0) / sectorPerformance.length,
              best_performer: sectorPerformance[0],
              worst_performer: sectorPerformance[sectorPerformance.length - 1],
              volatility_measure: this.calculateSectorVolatility(sectorPerformance)
            };
            break;
    
          case 'market_trend':
            const allCompanies = await this.db.getAllCompanies();
            const marketPerformance = await this.analyzeCompanyPerformances(allCompanies.slice(0, 20), period); // Limit for performance
            analysis.trend_data = {
              market: 'IBEX 35',
              companies_analyzed: marketPerformance.length,
              market_direction: this.determineMarketDirection(marketPerformance),
              sector_performance: await this.getSectorCorrelationAnalysis(period),
              volatility_index: this.calculateMarketVolatility(marketPerformance)
            };
            break;
    
          case 'correlation_analysis':
            const correlationData = await this.getSectorCorrelationAnalysis(period);
            analysis.trend_data = {
              ...correlationData,
              correlation_insights: this.generateCorrelationInsights(correlationData)
            };
            break;
        }
    
        return analysis;
      } catch (error) {
        throw new Error(`Trend analysis failed: ${error}`);
      }
    }
  • src/index.ts:406-433 (registration)
    Registration of the 'analyze_trends' tool in the MCP server's tool list, including its name, description, and input schema.
      name: 'analyze_trends',
      description: 'Analyze trends in stock prices, market performance, or sector movements over time',
      inputSchema: {
        type: 'object',
        properties: {
          analysis_type: {
            type: 'string',
            enum: ['company_trend', 'sector_trend', 'market_trend', 'correlation_analysis'],
            description: 'Type of trend analysis to perform',
          },
          target: {
            type: 'string',
            description: 'Company symbol, sector name, or "market" for overall analysis',
          },
          period: {
            type: 'number',
            description: 'Number of days to analyze',
            default: 30,
          },
          include_forecast: {
            type: 'boolean',
            description: 'Whether to include simple trend forecast',
            default: false,
          },
        },
        required: ['analysis_type', 'target'],
      },
    },
  • Dispatch handler in the main server that routes 'analyze_trends' tool calls to the AnalyticsManager's analyzeTrends method.
    case 'analyze_trends':
      result = await this.analytics.analyzeTrends(
        (args as any)?.analysis_type,
        (args as any)?.target,
        (args as any)?.period || 30,
        (args as any)?.include_forecast || false
      );
      break;
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions analyzing trends 'over time' and hints at forecasting with 'include_forecast,' but doesn't specify computational methods, data sources, rate limits, authentication needs, or output format. For a tool with 4 parameters and no output schema, this leaves significant gaps in understanding how the tool behaves and what results to expect.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose without unnecessary details. It avoids redundancy and wastes no words, though it could be slightly more structured by explicitly listing key features like parameter-driven analysis. Overall, it's appropriately concise for the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (4 parameters, no annotations, no output schema), the description is incomplete. It lacks details on behavioral aspects like data processing, error handling, or result interpretation, and doesn't compensate for the missing output schema. For a trend analysis tool with multiple analysis types, more context is needed to guide effective use, especially compared to siblings with overlapping functionalities.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, providing clear details for all parameters, including enums for 'analysis_type' and defaults. The description adds minimal value beyond the schema, as it only implies the scope ('stock prices, market performance, or sector movements') without explaining parameter interactions or constraints. With high schema coverage, the baseline score of 3 is appropriate, as the description doesn't significantly enhance parameter understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: analyzing trends in stock prices, market performance, or sector movements over time. It specifies the verb 'analyze' and resources 'stock prices, market performance, or sector movements,' making it distinct from siblings like 'get_historical_prices' (data retrieval) or 'assess_investment_risk' (risk evaluation). However, it doesn't explicitly differentiate from 'get_sector_correlation_analysis' or 'screen_opportunities,' which might involve similar analytical tasks.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, such as needing historical data from 'get_historical_prices,' or compare it to siblings like 'get_sector_correlation_analysis' for correlation-specific tasks or 'generate_analyst_report' for formatted outputs. Usage is implied by the purpose but lacks explicit context or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/anbrme/ibex35-mcp-server'

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