calculate_irr
Compute the internal rate of return for investment analysis by inputting cash flows including initial investment to evaluate profitability.
Instructions
Calculate Internal Rate of Return
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cashFlows | Yes | Cash flows including initial investment |
Implementation Reference
- src/tools/financial-tools.ts:46-59 (handler)The MCP tool handler function that delegates the IRR calculation to the Python FinancialCalculator.irr method via the Python bridge.handler: async (args: any): Promise<ToolResult> => { try { const result = await pythonBridge.callPythonFunction({ module: 'financial_calculations', function: 'FinancialCalculator.irr', args: [args.cashFlows] }); return result; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error) }; }
- src/tools/financial-tools.ts:39-45 (schema)Input schema for the calculate_irr tool, requiring an array of cash flows.inputSchema: { type: "object", properties: { cashFlows: { type: "array", items: { type: "number" }, description: "Cash flows including initial investment" } }, required: ["cashFlows"] },
- src/tools/financial-tools.ts:36-61 (registration)Registration of the calculate_irr tool within the financialTools array, which is imported and spread into the main allTools list in src/index.ts.{ name: "calculate_irr", description: "Calculate Internal Rate of Return", inputSchema: { type: "object", properties: { cashFlows: { type: "array", items: { type: "number" }, description: "Cash flows including initial investment" } }, required: ["cashFlows"] }, handler: async (args: any): Promise<ToolResult> => { try { const result = await pythonBridge.callPythonFunction({ module: 'financial_calculations', function: 'FinancialCalculator.irr', args: [args.cashFlows] }); return result; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error) }; } } },
- The core implementation of IRR calculation using numpy_financial.irr library function.@staticmethod def irr(cash_flows: List[float]) -> float: """Calculate Internal Rate of Return""" return float(npf.irr(cash_flows))