Skip to main content
Glama
dun999

FinSight

analyze_diversification

Analyze portfolio concentration using the Herfindahl-Hirschman Index to assess diversification across asset classes, regions, and sectors, providing concentration grades and risk warnings.

Instructions

Portfolio diversification analysis using Herfindahl-Hirschman Index (HHI). Returns concentration grade (excellent/good/moderate/poor/critical), effective number of assets, breakdown by asset class / region / sector, and concentration warnings. Payment: $0.01 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 main handler function that calculates the diversification metrics for a given portfolio, including HHI, effective assets, breakdowns, and risk warnings.
    export function analyzeDiversification(portfolio: Portfolio): DiversificationResult {
      const sumWeightsSq = portfolio.holdings.reduce((acc, h) => acc + h.weight ** 2, 0)
      const hhi = Math.round(sumWeightsSq * 10000)
      const effectiveAssets = Number((1 / sumWeightsSq).toFixed(2))
      const grade = hhiGrade(hhi)
    
      const stableRatio = portfolio.holdings
        .filter((h) => h.isStable || h.assetClass === 'cash')
        .reduce((acc, h) => acc + h.weight, 0)
    
      const topHolding = portfolio.holdings.reduce((max, h) => (h.weight > max.weight ? h : max))
    
      const acBreakdown = assetClassBreakdown(portfolio)
      const regBreakdown = regionBreakdown(portfolio)
      const secBreakdown = sectorBreakdown(portfolio)
    
      // Count distinct asset classes (excluding cash)
      const nonCashClasses = new Set(
        portfolio.holdings.filter((h) => h.assetClass !== 'cash').map((h) => h.assetClass),
      )
    
      const warnings: string[] = []
    
      if (topHolding.weight > 0.5)
        warnings.push(
          `Over 50% concentrated in single asset (${topHolding.asset} at ${Math.round(topHolding.weight * 100)}%)`,
        )
    
      if (stableRatio < 0.05 && portfolio.profile !== 'aggressive')
        warnings.push('Less than 5% in stable / cash assets — no liquidity buffer')
    
      if (effectiveAssets < 2)
        warnings.push('Effective number of holdings below 2 — portfolio is barely diversified')
    
      if (hhi > 4000)
        warnings.push(`HHI = ${hhi} (>4000) — high concentration risk`)
    
      if (nonCashClasses.size === 1)
        warnings.push(`Single asset class (${[...nonCashClasses][0]}) — no cross-asset diversification`)
    
      const cryptoWeight = acBreakdown.find((a) => a.assetClass === 'crypto')?.weight ?? 0
      if (cryptoWeight > 0.7)
        warnings.push(`${Math.round(cryptoWeight * 100)}% in crypto — extreme volatility exposure`)
    
      const emWeight = regBreakdown.find((r) => r.region === 'EM')?.weight ?? 0
      if (emWeight > 0.5 && portfolio.profile !== 'aggressive')
        warnings.push(`${Math.round(emWeight * 100)}% in emerging markets — elevated geopolitical / currency risk`)
    
      return {
        hhi,
        effectiveAssets,
        grade,
        stableRatio: Number(stableRatio.toFixed(4)),
        topHolding: { asset: topHolding.asset, weight: topHolding.weight },
        assetClassBreakdown: acBreakdown,
        regionBreakdown: regBreakdown,
        sectorBreakdown: secBreakdown,
        warnings,
      }
    }
Behavior4/5

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

Strong disclosure of critical execution constraint: $0.01 USDC payment on Tempo chain. Also details return structure (concentration grades, breakdowns, warnings) which compensates for missing output schema. Being a computational analysis tool, it implies read-only behavior, though could note it's non-destructive.

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?

Three sentences with zero waste: methodology clause, outputs clause, payment clause. Front-loaded with the HHI methodology. Payment information—critical for agent cost-awareness—is included without verbosity.

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

Completeness4/5

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

Comprehensive given constraints: compensates for missing output schema by enumerating return values (grades, effective assets, breakdowns). Mentions payment requirement. Could benefit from noting the auto-fetch capability for known tickers, but schema covers this adequately.

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?

With 83% schema coverage, the structured documentation carries the heavy lifting. The description implies the 'holdings' parameter structure by mentioning portfolio analysis but doesn't add syntax guidance, validation rules, or examples beyond the schema definitions. Baseline 3 appropriate for high-coverage schemas.

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

Purpose5/5

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

Excellent specificity: states exact methodology (HHI), resource (portfolio), and distinct outputs (concentration grades, effective number of assets). Clearly distinguishes from siblings like analyze_risk or analyze_var by focusing specifically on concentration/diversification metrics.

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

Usage Guidelines3/5

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

Provides implied usage context (diversification analysis) but lacks explicit guidance on when to prefer this over siblings like analyze_correlation or analyze_risk. No mention of prerequisites like wallet connection for the USDC payment.

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