Skip to main content
Glama

var

Calculate Value at Risk (VaR) to quantify potential portfolio losses at a specified confidence level for risk management.

Instructions

Calculates Value at Risk (VaR).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
confidenceNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'var' tool, which computes the Value at Risk (VaR) for the current portfolio using historical returns and percentile method.
    def var(confidence: float = 0.95) -> str:
        """Calculates Value at Risk (VaR)."""
        data, weights = _get_portfolio_data()
        if data is None:
            return "Portfolio is empty."
        
        returns = data.pct_change().dropna()
        # Portfolio historical returns
        port_returns = returns.dot(weights)
        
        # Parametric VaR
        mean = np.mean(port_returns)
        std = np.std(port_returns)
        var_val = np.percentile(port_returns, (1 - confidence) * 100)
        
        return f"Daily VaR ({confidence:.0%}): {var_val:.2%}"
  • server.py:380-383 (registration)
    Registration of the 'var' tool (imported from tools.risk_engine) as an MCP tool using the register_tools helper function, which applies @mcp.tool() decorator.
    register_tools(
        [portfolio_risk, var, max_drawdown, monte_carlo_simulation],
        "Risk Engine"
    )
  • Helper function _get_portfolio_data used by var (and other risk tools) to fetch portfolio positions, historical price data, and compute value weights.
    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
Behavior1/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. The description reveals nothing about how the tool behaves - whether it's read-only or mutative, what data sources it uses, what permissions are required, whether it has rate limits, what format the output takes, or any error conditions. This is completely inadequate for a tool with no annotation coverage.

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 extremely concise - just three words. While this is efficient, it's arguably too brief given the complexity of VaR calculations and the complete lack of other documentation. However, it does front-load the core purpose without unnecessary words.

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 that this is a financial risk calculation tool with no annotations, 0% schema description coverage, and multiple similar sibling tools, the description is woefully incomplete. While an output schema exists (which might help with return values), the description doesn't explain what data the tool operates on, what methodology it uses, or how it differs from other risk tools. This leaves too many unanswered questions for effective use.

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

Parameters2/5

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

The schema description coverage is 0%, meaning the single parameter 'confidence' has no documentation in the schema. The description provides no information about parameters at all - it doesn't mention that confidence is a parameter, what it represents, what range is valid, or how it affects the calculation. For a tool with one undocumented parameter, this represents a significant gap.

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

Purpose2/5

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

The description 'Calculates Value at Risk (VaR)' is a tautology that essentially restates the tool name 'var' (which is an abbreviation for VaR). It doesn't specify what resources or data it operates on (e.g., portfolio data, market data), nor does it distinguish this tool from sibling tools like 'portfolio_risk' or 'monte_carlo_simulation' that might also perform risk calculations.

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

Usage Guidelines1/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 are multiple sibling tools that appear related to risk analysis (portfolio_risk, monte_carlo_simulation, max_drawdown), but the description doesn't explain when this specific VaR calculation is appropriate versus those other tools.

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