Skip to main content
Glama
dun999

FinSight

analyze_correlation

Calculate correlation matrices and diversification ratios for multi-asset portfolios to identify concentration risks and optimize allocation.

Instructions

Cross-asset correlation matrix and diversification ratio. Returns the full N×N correlation matrix, average pairwise correlation, diversification ratio (DR>1 = benefit), and asset-class pair correlations. Payment: $0.02 USDC on Tempo chain.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
holdingsYes
profileNoRisk profile — affects rebalance targets and scoring. Default: balanced.
benchmarkReturnNoAnnual benchmark return for Sharpe calculation, e.g. 0.08 = 8%. Default: 0.08.
riskFreeRateNoAnnual risk-free rate for Sortino and VaR excess return, e.g. 0.05 = 5%. Default: 0.05.
rebalanceMethodNoPortfolio construction method for rebalance recommendations. Default: profile.
marketIndicatorsNoOptional macro indicators — improves market regime detection confidence to HIGH when 3+ provided.

Implementation Reference

  • The `analyzeCorrelation` function computes the correlation matrix and diversification metrics for a given portfolio, optionally utilizing historical price series data.
    export function analyzeCorrelation(
      portfolio: Portfolio,
      returnSeries?: Record<string, number[]>,
    ): CorrelationResult {
      const holdings = portfolio.holdings
    
      // Track whether we used any real price data
      const hasRealData = returnSeries
        ? holdings.some((h) => returnSeries[h.asset.toUpperCase()]?.length >= MIN_SERIES_LENGTH)
        : false
    
      // Build full N×N correlation matrix
      const matrix: CorrelationEntry[] = holdings.map((hi) => {
        const correlations: Record<string, number> = {}
        for (const hj of holdings) {
          const corr = resolvePairCorrelation(
            hi.asset, hj.asset,
            hi.assetClass, hj.assetClass,
            hi.sector, hj.sector,
            returnSeries,
          )
          correlations[hj.asset] = Number(corr.toFixed(4))
        }
        return { asset: hi.asset, assetClass: hi.assetClass, correlations }
      })
    
      // Weighted average pairwise correlation (off-diagonal only)
      let weightedCorrSum = 0
      let totalPairWeight = 0
      for (let i = 0; i < holdings.length; i++) {
        for (let j = i + 1; j < holdings.length; j++) {
          const corr = resolvePairCorrelation(
            holdings[i].asset, holdings[j].asset,
            holdings[i].assetClass, holdings[j].assetClass,
            holdings[i].sector, holdings[j].sector,
            returnSeries,
          )
          const pairWeight = holdings[i].weight * holdings[j].weight
          weightedCorrSum += corr * pairWeight
          totalPairWeight += pairWeight
        }
      }
      const avgPairwiseCorrelation =
        totalPairWeight > 0 ? Number((weightedCorrSum / totalPairWeight).toFixed(4)) : 1
    
      const pVol = portfolioVol(portfolio, returnSeries)
      const diversificationRatio = computeDiversificationRatio(portfolio, pVol)
      const assetClassCorrelations = assetClassCorrelationSummary(portfolio, returnSeries)
    
      return {
        matrix,
        avgPairwiseCorrelation,
        diversificationRatio,
        assetClassCorrelations,
        interpretation: buildInterpretation(avgPairwiseCorrelation, diversificationRatio, hasRealData),
      }
    }
Behavior3/5

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

With no annotations provided, the description must carry full behavioral burden. It discloses return values (correlation matrix format, diversification ratio semantics) and payment cost/chain (Tempo), but omits safety profile (read-only vs destructive), rate limits, authentication requirements, or error handling behavior expected for a mutation-costing operation.

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

Conciseness5/5

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

Two efficient sentences with zero redundancy. First sentence front-loads purpose and outputs; second discloses payment cost. Every word earns its place with no fluff or repetition of schema content.

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

Completeness3/5

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

Given no output schema exists, the description appropriately documents return structure (N×N matrix, DR>1 semantics). However, given 9 sibling analysis tools and complex nested inputs, the description lacks sufficient usage context and behavioral safety details to be considered fully complete.

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?

Schema description coverage is 83% (high), with detailed property descriptions for the complex 'holdings' object and enums. The description adds no parameter-specific guidance, but with high schema coverage, the baseline 3 is appropriate as the schema adequately documents inputs.

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?

Description clearly states the tool computes a 'Cross-asset correlation matrix and diversification ratio' with specific outputs (N×N matrix, average pairwise correlation, DR>1 interpretation). However, it does not explicitly differentiate from sibling 'analyze_diversification' despite mentioning diversification metrics, leaving some ambiguity on selection criteria.

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 specifies what the tool returns and notes the payment requirement ($0.02 USDC), but provides no guidance on when to select this over siblings like analyze_diversifications, analyze_risk, or analyze_compare, nor does it mention prerequisites or exclusions for use.

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/dun999/finsight-mpp'

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