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
| Name | Required | Description | Default |
|---|---|---|---|
| cashFlows | Yes | Array of [time, cashFlow] pairs | |
| yieldRate | Yes |
Implementation Reference
- src/tools/financial-tools.ts:420-434 (handler)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) }; } }
- src/tools/financial-tools.ts:403-419 (schema)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"] },
- src/tools/financial-tools.ts:400-435 (registration)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,