Skip to main content
Glama

optimize_portfolio

Read-onlyIdempotent

Optimize a portfolio of stocks by calculating optimal weights that maximize Sharpe ratio using Markowitz theory, providing expected annual return, volatility, and Sharpe ratio.

Instructions

投資組合最佳化 — Markowitz 最大夏普比率法。輸入多檔股票,根據歷史日報酬率計算最優權重配置,輸出各股建議比例、預期年報酬、年化波動度、夏普比率。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codesYes股票代號(逗號分隔,2-10 檔),例如 2330,2454,2303,2382
marketNo市場 TW 或 US,預設 TW
riskFreeRateNo無風險利率(年化小數),預設 0.02(2%)
Behavior4/5

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

Annotations already declare readOnlyHint=true and idempotentHint=true, so safety is clear. The description adds behavioral context: it uses historical daily returns, calculates optimal weights, and outputs specific metrics. This goes beyond the annotations.

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 a single, information-dense sentence covering method, input, and output. It is efficient and front-loaded, though slightly more structure (separating input/output) could improve readability.

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?

Given the rich schema and annotations, the description adds necessary method and output details. It lists the four key output fields, compensating for the lack of output schema. Complete for a calculation tool.

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 coverage is 100%, with all parameters described (codes, market, riskFreeRate). The description does not add significant meaning beyond the schema but does not need to due to high coverage.

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?

The description clearly states the tool performs portfolio optimization using the Markowitz maximum Sharpe ratio method. It specifies the input (multiple stocks) and output (recommended weights, expected return, volatility, Sharpe ratio), distinguishing it from sibling tools like get_portfolio or calculate_portfolio_var.

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 implies usage for optimization but does not explicitly state when to use this tool versus alternatives. With many portfolio-related siblings, explicit guidance on when to choose optimization would improve clarity.

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/kevinlin49361128-stack/stock-analyzer-mcp'

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