Skip to main content
Glama
quanttrucker

portfolio-analytics-mcp

by quanttrucker

revalue_positions

Match trades FIFO to compute realized and unrealized P&L, showing open positions and trade history. Pass executions and optional marks to get profit breakdown per symbol.

Instructions

Match buys and sells FIFO and compute realised and unrealised P&L.

Use this to turn a list of fills into a trade history — "what did I actually make on these trades", "which positions are still open", "what is my realised P&L". Fills are matched first-in-first-out per instrument: a sell consumes the oldest open lots first, and any excess opens a position in the opposite direction, so a sell of 150 against a long of 100 closes the 100 and leaves a short of 50. Longs and shorts are handled symmetrically.

Pass the executions in; this tool cannot fetch anyone's trade history. Realised P&L is converted to your reporting currency at the closing fill's FX rate, which is where the gain is crystallised.

Optionally pass marks (symbol to current price) to get unrealised P&L on whatever remains open. Symbols without a mark are reported with a null rather than being treated as flat.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
marksNo
executionsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
open_lotsYes
closed_tradesYes
realised_pnl_baseYesTotal realised P&L in the reporting currency.
unrealised_pnl_by_symbolNoPer-symbol mark-to-market on open lots, in each lot's own currency.
Behavior5/5

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

With no annotations, the description carries the full behavioral burden and excels: it discloses FIFO matching mechanics, symmetric open-position behavior, FX conversion at closing fill's rate, and the null-for-unmarked-symbols behavior. These details go far beyond a generic tool description.

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?

Every sentence earns its place. Main purpose is front-loaded, then use cases, then behavioral details, then parameter explanation. The length is justified by the complexity of FIFO matching and FX conversion, with no filler or redundancy.

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?

Despite having an output schema (which covers return values), the description covers inputs, processing algorithm, edge cases (opposite-direction opens), and limitations (cannot fetch trades). It is fully contextualized for the tool's complexity.

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 schema descriptions are rich, but the tool description adds semantic context beyond them, e.g., that `marks` maps symbol to current price and that missing marks yield null. It explains the effects of executions as a list but doesn't enumerate each field—still adds meaning above schema.

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 opens with a specific verb+resource: 'Match buys and sells FIFO and compute realised and unrealised P&L.' It clearly distinguishes itself from siblings (portfolio_beta, sector_correlation) by focusing on trade history and P&L, not portfolio statistics.

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

Usage Guidelines5/5

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

Provides explicit guidance: 'Use this to turn a list of fills into a trade history' and states a clear limitation: 'this tool cannot fetch anyone's trade history.' It also explains when to pass marks for unrealized P&L, giving actionable usage criteria.

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

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