npv
Calculate Net Present Value (NPV) of cash flows by inputting cash flow values and discount rate to assess investment profitability.
Instructions
Calculate Net Present Value of cash flows
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cashFlows | Yes | ||
| rate | Yes |
Implementation Reference
- index.js:248-251 (handler)The inline handler function for the 'npv' tool that computes Net Present Value by reducing over cash flows, discounting each by (1 + rate)^t.async ({ cashFlows, rate }) => { return cashFlows.reduce((npv, cf, t) => npv + cf / Math.pow(1 + rate, t), 0); }
- index.js:239-247 (schema)Tool configuration object defining the name, description, input schema (cashFlows: array of numbers, rate: number), and output schema (number).{ name: 'npv', description: 'Calculate Net Present Value of cash flows', inputSchema: z.object({ cashFlows: z.array(z.number()), rate: z.number() // discount rate as decimal }), outputSchema: z.number(), },
- index.js:238-252 (registration)Full registration of the 'npv' tool via ai.defineTool, including schema and inline handler implementation.ai.defineTool( { name: 'npv', description: 'Calculate Net Present Value of cash flows', inputSchema: z.object({ cashFlows: z.array(z.number()), rate: z.number() // discount rate as decimal }), outputSchema: z.number(), }, async ({ cashFlows, rate }) => { return cashFlows.reduce((npv, cf, t) => npv + cf / Math.pow(1 + rate, t), 0); } );