Skip to main content
Glama

bond_duration

Calculate Macaulay duration for bonds using cash flow timing and yield rates to measure interest rate sensitivity and manage portfolio risk.

Instructions

Calculate Macaulay duration for bond

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cashFlowsYesArray of [time, cashFlow] pairs
yieldRateYes

Implementation Reference

  • Handler function that executes the bond_duration tool by invoking the Python FinancialCalculator.duration method via the PythonBridge.
    handler: async (args: any): Promise<ToolResult> => { try { const result = await pythonBridge.callPythonFunction({ module: 'financial_calculations', function: 'FinancialCalculator.duration', args: [args.cashFlows, args.yieldRate] }); return result; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error) }; } }
  • Input schema defining the parameters for the bond_duration tool: cashFlows as array of time-cashflow pairs and yieldRate.
    inputSchema: { type: "object", properties: { cashFlows: { type: "array", items: { type: "array", items: { type: "number" }, minItems: 2, maxItems: 2 }, description: "Array of [time, cashFlow] pairs" }, yieldRate: { type: "number" } }, required: ["cashFlows", "yieldRate"] },
  • The complete tool registration object for bond_duration within the financialTools array.
    { name: "bond_duration", description: "Calculate Macaulay duration for bond", inputSchema: { type: "object", properties: { cashFlows: { type: "array", items: { type: "array", items: { type: "number" }, minItems: 2, maxItems: 2 }, description: "Array of [time, cashFlow] pairs" }, yieldRate: { type: "number" } }, required: ["cashFlows", "yieldRate"] }, handler: async (args: any): Promise<ToolResult> => { try { const result = await pythonBridge.callPythonFunction({ module: 'financial_calculations', function: 'FinancialCalculator.duration', args: [args.cashFlows, args.yieldRate] }); return result; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error) }; } } },
  • src/index.ts:34-34 (registration)
    Inclusion of financialTools (containing bond_duration) into the main allTools array for MCP server registration.
    ...financialTools,

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/jeremycharlesgillespie/excel-mcp'

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