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;

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