npv
Calculate Net Present Value of cash flows using a specified discount rate to evaluate 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:238-252 (registration)Registration of the 'npv' tool using ai.defineTool, including schema and inline handler.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); } );
- index.js:248-251 (handler)Handler function computes Net Present Value by reducing cash flows discounted by the given rate using the time index as the period.async ({ cashFlows, rate }) => { return cashFlows.reduce((npv, cf, t) => npv + cf / Math.pow(1 + rate, t), 0); }
- index.js:239-247 (schema)Schema definition for 'npv' tool: input requires array of cashFlows and discount rate; output is a 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(), },