calculate_bond_price
Calculate bond price using face value, coupon rate, yield rate, and maturity period to determine current market value for investment analysis.
Instructions
Calculate bond price given yield and terms
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| couponRate | Yes | Annual coupon rate as decimal | |
| faceValue | Yes | ||
| frequency | No | Coupon payments per year | |
| years | Yes | ||
| yieldRate | Yes | Required yield as decimal |
Implementation Reference
- src/tools/financial-tools.ts:140-154 (handler)The tool handler function that invokes the Python implementation via PythonBridge.handler: async (args: any): Promise<ToolResult> => { try { const result = await pythonBridge.callPythonFunction({ module: 'financial_calculations', function: 'FinancialCalculator.bond_price', args: [args.faceValue, args.couponRate, args.yieldRate, args.years, args.frequency || 2] }); return result; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error) }; } }
- src/tools/financial-tools.ts:129-139 (schema)Input schema defining parameters for the calculate_bond_price tool.inputSchema: { type: "object", properties: { faceValue: { type: "number" }, couponRate: { type: "number", description: "Annual coupon rate as decimal" }, yieldRate: { type: "number", description: "Required yield as decimal" }, years: { type: "number" }, frequency: { type: "number", default: 2, description: "Coupon payments per year" } }, required: ["faceValue", "couponRate", "yieldRate", "years"] },
- src/tools/financial-tools.ts:126-155 (registration)Registration of the calculate_bond_price tool in the financialTools array, which is imported and used in the MCP server.{ name: "calculate_bond_price", description: "Calculate bond price given yield and terms", inputSchema: { type: "object", properties: { faceValue: { type: "number" }, couponRate: { type: "number", description: "Annual coupon rate as decimal" }, yieldRate: { type: "number", description: "Required yield as decimal" }, years: { type: "number" }, frequency: { type: "number", default: 2, description: "Coupon payments per year" } }, required: ["faceValue", "couponRate", "yieldRate", "years"] }, handler: async (args: any): Promise<ToolResult> => { try { const result = await pythonBridge.callPythonFunction({ module: 'financial_calculations', function: 'FinancialCalculator.bond_price', args: [args.faceValue, args.couponRate, args.yieldRate, args.years, args.frequency || 2] }); return result; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error) }; } } },
- Core implementation of bond price calculation: present value of coupon payments plus face value.@staticmethod def bond_price(face_value: float, coupon_rate: float, yield_rate: float, years: int, frequency: int = 2) -> float: """Calculate bond price""" periods = years * frequency coupon_payment = (face_value * coupon_rate) / frequency period_yield = yield_rate / frequency pv_coupons = sum(coupon_payment / ((1 + period_yield) ** i) for i in range(1, periods + 1)) pv_face = face_value / ((1 + period_yield) ** periods) return pv_coupons + pv_face