Skip to main content
Glama

portfolio_risk

Calculate annualized portfolio volatility to assess investment risk using Monte Carlo simulations for quantitative finance analysis.

Instructions

Returns annualized volatility of the portfolio.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'portfolio_risk' tool. Computes portfolio returns from current positions, calculates covariance matrix, and derives annualized volatility.
    def portfolio_risk() -> str:
        """Returns annualized volatility of the portfolio."""
        data, weights = _get_portfolio_data()
        if data is None:
            return "Portfolio is empty."
        
        returns = data.pct_change().dropna()
        cov_matrix = returns.cov() * 252
        port_variance = np.dot(weights.T, np.dot(cov_matrix, weights))
        port_volatility = np.sqrt(port_variance)
        
        return f"Annualized Portfolio Volatility: {port_volatility:.2%}"
  • server.py:380-383 (registration)
    MCP tool registration block where portfolio_risk is registered via the register_tools helper function, which applies @mcp.tool() decorator.
    register_tools(
        [portfolio_risk, var, max_drawdown, monte_carlo_simulation],
        "Risk Engine"
    )
  • Supporting helper function that retrieves portfolio positions, fetches historical price data, and computes value-based weights for risk calculations.
    def _get_portfolio_data(lookback: str = "1y"):
        portfolio = get_positions()
        positions = portfolio.get("positions", {})
        if not positions:
            return None, None
        
        tickers = list(positions.keys())
        weights = np.array(list(positions.values())) # This is qty, need value weights
        
        # Fetch data
        data = yf.download(tickers, period=lookback, progress=False)['Close']
        if isinstance(data, pd.Series):
            data = data.to_frame(name=tickers[0])
            
        # Calculate current value weights
        current_prices = data.iloc[-1]
        values = current_prices * pd.Series(positions)
        total_value = values.sum()
        weights = values / total_value
        
        return data, weights
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 states the tool returns a value but doesn't explain computational methods, assumptions, data sources, or potential limitations. For a risk calculation tool with zero annotation coverage, this is a significant gap in transparency.

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?

The description is a single, efficient sentence that directly states the tool's function without any wasted words. It's front-loaded and appropriately sized for a simple tool with no parameters.

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 the tool has 0 parameters, 100% schema coverage, and an output schema exists, the description is minimally adequate. However, as a risk calculation tool with no annotations, it lacks details on methodology or context that would help an agent use it correctly, especially compared to siblings like 'var'.

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

Parameters4/5

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

The tool has 0 parameters, and schema description coverage is 100%, so there's no need for parameter details in the description. The baseline for this scenario is 4, as the description appropriately focuses on the tool's purpose without redundant parameter information.

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 with a specific verb ('Returns') and resource ('annualized volatility of the portfolio'), making it immediately understandable. However, it doesn't explicitly differentiate from siblings like 'var' or 'max_drawdown', which are also risk-related tools, so it doesn't reach the highest score.

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. There's no mention of prerequisites, context, or comparisons to sibling tools like 'var' or 'max_drawdown', leaving the agent to infer usage based on the name alone.

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/N-lia/MonteWalk'

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