Skip to main content
Glama

get_sector_correlation_analysis

Analyze sector performance correlations and market trends in the Spanish stock exchange to identify relationships and patterns.

Instructions

Analyze sector performance correlations and market trends

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
daysNoNumber of days to analyze

Implementation Reference

  • Core implementation of get_sector_correlation_analysis tool. Groups IBEX 35 companies by sector, calculates aggregate performance metrics (market cap, PE ratio), sorts sectors by size, and includes market concentration analysis.
    async getSectorCorrelationAnalysis(days: number = 30): Promise<any> {
      const companies = await this.db.getAllCompanies();
      
      // Group companies by sector
      const sectorMap = new Map();
      companies.forEach(company => {
        if (!company.sector) return;
        
        if (!sectorMap.has(company.sector)) {
          sectorMap.set(company.sector, []);
        }
        sectorMap.get(company.sector).push(company);
      });
    
      // Calculate sector performance metrics
      const sectorPerformance = [];
      for (const [sector, sectorCompanies] of sectorMap.entries()) {
        let totalMarketCap = 0;
        let companiesWithData = 0;
        let avgPE = 0;
        let peCount = 0;
    
        sectorCompanies.forEach(company => {
          if (company.market_cap) {
            totalMarketCap += company.market_cap;
            companiesWithData++;
          }
          
          const pe = company.price_to_earnings || company.pe_ratio;
          if (pe) {
            avgPE += pe;
            peCount++;
          }
        });
    
        sectorPerformance.push({
          sector: sector,
          company_count: sectorCompanies.length,
          total_market_cap: totalMarketCap,
          avg_market_cap: companiesWithData > 0 ? totalMarketCap / companiesWithData : 0,
          avg_pe_ratio: peCount > 0 ? avgPE / peCount : null,
          companies: sectorCompanies.slice(0, 5).map(c => ({
            symbol: c.symbol,
            name: c.name,
            market_cap: c.market_cap
          }))
        });
      }
    
      // Sort by total market cap
      sectorPerformance.sort((a, b) => b.total_market_cap - a.total_market_cap);
    
      return {
        period_days: days,
        sector_performance: sectorPerformance,
        total_sectors: sectorPerformance.length,
        largest_sector: sectorPerformance[0]?.sector || 'Unknown',
        market_concentration: this.calculateMarketConcentration(sectorPerformance)
      };
    }
  • src/index.ts:346-358 (registration)
    Tool registration in MCP listTools handler, including name, description, and input schema for optional 'days' parameter.
      name: 'get_sector_correlation_analysis',
      description: 'Analyze sector performance correlations and market trends',
      inputSchema: {
        type: 'object',
        properties: {
          days: {
            type: 'number',
            description: 'Number of days to analyze',
            default: 30,
          },
        },
      },
    },
  • src/index.ts:653-655 (registration)
    Dispatch handler in MCP callToolRequest that invokes the analytics method with parsed arguments.
    case 'get_sector_correlation_analysis':
      result = await this.analytics.getSectorCorrelationAnalysis((args as any)?.days || 30);
      break;
  • Supporting function called by the handler to compute market concentration using Herfindahl-Hirschman Index (HHI) and top sector shares.
    private calculateMarketConcentration(sectorPerformance: any[]): any {
      const totalMarketCap = sectorPerformance.reduce((sum, sector) => sum + sector.total_market_cap, 0);
      
      if (totalMarketCap === 0) return { hhi_index: 0, concentration_level: 'unknown' };
    
      // Calculate Herfindahl-Hirschman Index
      const hhi = sectorPerformance.reduce((sum, sector) => {
        const share = sector.total_market_cap / totalMarketCap;
        return sum + (share * share * 10000); // HHI scale
      }, 0);
    
      let concentrationLevel;
      if (hhi > 2500) concentrationLevel = 'highly_concentrated';
      else if (hhi > 1500) concentrationLevel = 'moderately_concentrated';
      else concentrationLevel = 'competitive';
    
      return {
        hhi_index: Math.round(hhi),
        concentration_level: concentrationLevel,
        top_3_market_share: sectorPerformance.slice(0, 3).reduce((sum, sector) => 
          sum + (sector.total_market_cap / totalMarketCap), 0) * 100
      };
    }
  • TypeScript declaration for the analytics method signature.
    getSectorCorrelationAnalysis(days?: number): Promise<any>;
Behavior2/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. It mentions analysis but doesn't specify whether this is a read-only operation, if it requires authentication, rate limits, or what the output entails (e.g., data format, potential side effects). The description is too vague to inform the agent about key behavioral traits beyond the basic action implied by 'analyze'.

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 concise with a single sentence 'Analyze sector performance correlations and market trends', which is front-loaded and wastes no words. However, it could be more structured by including key details like output format or usage context, but as-is, it's efficiently phrased without redundancy.

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 complexity implied by 'analysis' and lack of annotations or output schema, the description is incomplete. It doesn't explain what the analysis returns (e.g., correlation coefficients, trends data), how results are formatted, or any behavioral aspects. For a tool with no structured data to supplement it, the description should provide more context to be fully actionable for an agent.

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 for its single parameter 'days', with a clear description and default value. The tool description adds no additional parameter semantics beyond what the schema provides, such as explaining how 'days' affects the analysis or any constraints. With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but also doesn't detract.

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

Purpose3/5

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

The description 'Analyze sector performance correlations and market trends' states a general purpose but lacks specificity. It mentions 'sector performance correlations' and 'market trends' but doesn't clarify what analysis is performed (e.g., statistical correlation metrics, visualizations, or summary insights). It doesn't distinguish from siblings like 'analyze_trends' or 'get_network_analysis', which could overlap in analyzing trends or relationships.

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?

No guidance is provided on when to use this tool versus alternatives. With siblings such as 'analyze_trends' and 'get_network_analysis', the description doesn't indicate specific contexts, prerequisites, or exclusions for selecting this tool over others. Usage is implied only by the tool name and vague description, leaving the agent to guess based on incomplete information.

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