Savings goal
How much do I need to save each month to hit $X in N years? Pin down the required contribution with a clever PV-discount trick: discount the target back to today, then call loan-payment with the discounted target as principal - the 'payment' the tool returns IS your required monthly savings. Same PMT formula a mortgage uses; different decision.
4 tools run server-side in one request. You pay once, settle once, and get a single response - no orchestration, no per-step payments, and a partial-success envelope if any step fails. USDC over x402 on any supported chain.
When to use this pack
You have a concrete goal - save $1,000,000 for retirement in 30 years, $500k for a child's college in 18 years, $80k for a down payment in 5 years, $20k for a wedding in 2 years - and want the deterministic answer to: how much per month? What's the gap if I keep saving at my current rate? What return would I need on a fixed contribution? This pack walks the agent through projecting current savings, computing the gap, and back-solving the required PMT - all with the finance-math kit, all free over PoW.
Tools in this pack
All 4 run inside the single $0.050 call above. Each is also callable on its own if you only need one part.
- Compound interest POST /api/compound-interest Compute future value of a principal under compound interest. Returns future value, total interest earned, and the effective annual rate (APY) given the compounding frequency. Matches Excel's FV(rate, nper, 0, -principal) and the classic (1+r/n)^(nt) textbook formula.
- Loan payment POST /api/loan-payment Compute the monthly (or per-period) payment on a fully-amortizing loan: mortgage, auto, student loan, business loan. Returns the periodic payment, total paid over the term, and total interest. Matches Excel's PMT(rate, nper, -principal). Use this when you just need the payment number, not the full per-period schedule (see amortization).
- Net present value (NPV) POST /api/npv Compute the net present value of a stream of cashflows at a given discount rate. Index 0 is treated as t=0 (today, not discounted); indices 1..n are discounted by (1+rate)^t. Matches Excel's NPV but with the conventional t=0 treatment most finance textbooks use (Excel itself starts discounting at t=1 - see notes). Use for capital-budgeting decisions: positive NPV = creates value at the discount rate; negative = destroys value.
- Internal rate of return (IRR) POST /api/irr Compute the internal rate of return (IRR) of a cashflow stream - the discount rate at which NPV = 0. Index 0 is treated as t=0 (typically the negative initial investment); indices 1..n are inflows in subsequent periods. Solved via Newton-Raphson with bisection fallback. Requires at least one positive and one negative cashflow (otherwise IRR is undefined). Multiple sign changes in the cashflows can produce multiple IRR roots - we return the first one found.
Workflow
- Project the current balance forward with compound-interest. Pass principal=current_savings, annualRate=expected_return, years=time_horizon, compoundingPerYear=12. This is the 'no further contributions' future value - what's already covered. Subtract from the target → the gap that new contributions need to fill.
- Solve for the required monthly contribution with the PV-discount trick. The PMT formula loan-payment implements is PMT = PV · r / (1 - (1+r)^-n). The same formula in reverse computes: 'what regular contribution accumulates to a given FV?' To use loan-payment directly, first discount the gap back to present value: PV_of_gap = gap / (1 + r)^n (or use npv with cashflows=[0, ..., gap] to do this). Then call loan-payment(principal=PV_of_gap, annualRate=r, termYears=n, paymentsPerYear=12) - the 'payment' the tool returns IS your required monthly contribution. Same PMT formula, different decision: you're not borrowing, you're paying yourself.
- Sanity-check the target in today's dollars with npv. A $1M target in 30 years isn't $1M in spending power - at 3% inflation it's worth ~$412k today. Build a single-cashflow stream [0, ..., target] over the horizon and call npv at discountRate = inflation rate (3% historical, 2.5% recent Fed target). The (positive) NPV is the target in today's-dollars terms. Surface both nominal and real targets to the user - many people set savings targets without realizing they're undershooting because they thought in nominal dollars.
- If the user has a fixed contribution and wants to know 'what return do I need?', back-solve with irr. Build the cashflow stream [-current_savings, -annual_contribution, -annual_contribution, ..., +target] over the horizon and call irr. The returned rate is the required annual return to hit the target - compare to historical asset class returns (cash ~2%, bonds ~4%, balanced ~6%, stocks ~7-10%) to ground-truth whether the plan is plausible. If irr > 10% on a long horizon, the plan is aggressive; if irr > 15%, the user should expect to either save more, extend the horizon, or accept higher risk.
Call it directly
Any x402 client pays the 402 and gets the whole workflow back in one response:
npx agent402-client call savings-goal {"goal":"save $1,000,000 for retirement in 30 years","expectedReturn":"0.07"}
Run it in Claude
claude mcp add agent402 -s user -- npx -y agent402-mcp@latest
Then paste this prompt into Claude:
I want to save $1,000,000 for retirement in 30 years. I currently have $50,000 saved. Use Agent402 to compute how much I need to contribute monthly at a 7% expected return, and pressure-test the plan. (1) Project current $50k forward 30 years: compound-interest(principal=50000, annualRate=0.07, years=30, compoundingPerYear=12) - expect ~$406k. Gap = $1,000,000 - $406k = $594k FV still needed. (2) Discount the gap to PV: PV_of_gap = 594000 / (1+0.07/12)^360 ≈ $73,200. Now call loan-payment(principal=73200, annualRate=0.07, termYears=30, paymentsPerYear=12) → the 'payment' is your required monthly contribution. Expect ~$487/mo. (3) Sanity-check the target in today's dollars: build cashflows=[0, 0, ..., 1000000] (index 30 = $1M), call npv at discountRate=0.03 → ~$412k in today's-dollars terms. Surface both. (4) Optional back-solve: if the user can only afford $300/mo, build cashflow=[-50000, -3600, -3600, ..., +1000000] (30 years of $3600/yr contributions) and call irr → required return. If the irr > 10%, the plan is aggressive - recommend lowering the target, extending the horizon, or increasing the contribution. (5) Return: {requiredMonthlyContribution, targetInTodaysDollars, gapAfterCurrentSavings, plausibilityFlag: "realistic"|"aggressive"|"unrealistic", oneLineConclusion}. All four tools are free over PoW.