Skip to main content
Glama
l4b4r4b4b4
by l4b4r4b4b4

optimize_portfolio

Optimize investment portfolio weights using Efficient Frontier analysis to maximize Sharpe ratio, minimize volatility, or achieve target return/volatility objectives.

Instructions

Optimize portfolio weights using Efficient Frontier.

    Finds optimal portfolio weights based on the specified optimization
    method. Uses numerical optimization (scipy) to find the solution.

    Args:
        name: The portfolio name.
        method: Optimization method:
            - "max_sharpe": Maximize Sharpe ratio (default)
            - "min_volatility": Minimize portfolio volatility
            - "efficient_return": Minimize volatility for target return
            - "efficient_volatility": Maximize return for target volatility
        target_return: Required for "efficient_return" method.
            The target annualized return to achieve.
        target_volatility: Required for "efficient_volatility" method.
            The target annualized volatility.

    Returns:
        Dictionary containing:
        - method: Optimization method used
        - optimal_weights: Dict of optimal weights per symbol
        - expected_return: Expected return of optimal portfolio
        - volatility: Volatility of optimal portfolio
        - sharpe_ratio: Sharpe ratio of optimal portfolio
        - original: Original portfolio metrics for comparison
        - improvement: Improvement over original portfolio

    Example:
        ```
        # Maximize Sharpe ratio
        result = optimize_portfolio(name="tech_stocks", method="max_sharpe")

        # Minimize volatility
        result = optimize_portfolio(name="tech_stocks", method="min_volatility")

        # Target 15% return with minimum volatility
        result = optimize_portfolio(
            name="tech_stocks",
            method="efficient_return",
            target_return=0.15
        )
        ```
    

Caching Behavior:

  • Any input parameter can accept a ref_id from a previous tool call

  • Large results return ref_id + preview; use get_cached_result to paginate

  • All responses include ref_id for future reference

Preview Size: server default. Override per-call with get_cached_result(ref_id, max_size=...).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
methodNomax_sharpe
target_returnNo
target_volatilityNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Behavior4/5

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

With no annotations provided, the description carries full burden and does well by disclosing implementation details ('Uses numerical optimization (scipy)'), caching behavior, preview handling, and return structure. It explains that results can be cached and paginated, which are important behavioral traits not obvious from the schema alone.

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

Conciseness3/5

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

The description is front-loaded with core functionality but includes extensive documentation (Args, Returns, Example, Caching Behavior sections) that makes it quite lengthy. While all content is relevant, it could be more streamlined - the caching behavior section repeats information about get_cached_result that might be better placed elsewhere.

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

Completeness5/5

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

Given the complexity of portfolio optimization, no annotations, and 0% schema coverage, the description provides excellent completeness. It covers purpose, parameters, return values, examples, and caching behavior - everything needed to understand and use the tool effectively. The output schema exists but the description still usefully explains the return structure.

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

Parameters5/5

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

With 0% schema description coverage, the description fully compensates by providing detailed parameter explanations beyond the bare schema. It documents all 4 parameters, explains the method options with their meanings, clarifies which parameters are required for which methods, and provides default values and examples - adding substantial semantic value.

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 'optimizes portfolio weights using Efficient Frontier' and 'finds optimal portfolio weights based on the specified optimization method,' which is a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'apply_optimization' or 'update_portfolio_weights,' which likely have related but distinct purposes.

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?

The description provides implied usage through method descriptions and examples, showing when to use different optimization approaches. However, it lacks explicit guidance on when to choose this tool over alternatives like 'apply_optimization' or 'update_portfolio_weights,' and doesn't mention prerequisites or when-not-to-use scenarios.

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/l4b4r4b4b4/portfolio-mcp'

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