用 TypeScript 建立經風險調整的 AI 投資回報與回本模型
Risk-adjusted AI ROI and payback modeling in TypeScript
文章示範如何用 TypeScript 建立 AI 投資回報與回本模型,按採用率、現金實現率和交付成本估算三種情境。示例採用税前美元假設,計算 12 個月加權 NPV 為 $42,637.08,並估算在這些假設下年底前回本概率為 75%。文章亦説明如何以試點任務數、賬單、重試、人工審核及具體開支變化,核對模型中的採用率、單位成本和現金節省假設。
A $24,000 automation pilot can release hours and still miss cash payback. For a workflow with 10,000 eligible tasks per month, six minutes saved per automated task and $30 per labor hour imply a $30,000 monthly ceiling. Adoption and the share of time that turns into cash savings determine how much reaches the budget.
Model three mutually exclusive cases. Each case can carry a different adoption rate, rate of cash realization, and delivery cost. Keep the three cash-flow series for review, then weight their outcomes. The assumptions below are illustrative pre-tax USD, with costs and savings booked at month-end.
Build one cash-flow schedule per case
At full ramp, base-case adoption covers 6,500 tasks a month. Those tasks release 650 hours. At 55% cash realization, avoided overtime or contractor spend yields $10,725 of benefit. A $1,400 recurring charge and $0.35 in usage and review cost per adopted task leave $7,050 in net monthly cash flow. Count the remaining hours separately as capacity.
Save these two TypeScript blocks in ai-roi.ts and run node ai-roi.ts with Node.js 24.
type Scenario = {
name: string;
weight: number;
adoption: number;
cashRealization: number;
costPerAdoptedTask: number;
};
const initial = 24_000;
const monthlyFixed = 1_400;
const eligibleTasks = 10_000;
const laborPerTask = (6 / 60) * 30;
const monthlyDiscount = 1.12 ** (1 / 12) - 1;
const ramp = [0.25, 0.50, 0.75, ...Array<number>(9).fill(1)];
function buildCashFlows(scenario: Scenario) {
return ramp.map((rampFactor) => {
const adopted = eligibleTasks * scenario.adoption * rampFactor;
const benefit = adopted * laborPerTask * scenario.cashRealization;
const cost = monthlyFixed + adopted * scenario.costPerAdoptedTask;
return { benefit, cost, net: benefit - cost };
});
}
function paybackMonth(cashFlows: number[]): number | null {
let cumulative = -initial;
for (const [index, net] of cashFlows.entries()) {
cumulative += net;
if (cumulative >= 0) return index + 1;
}
return null;
}
function summarize(scenario: Scenario) {
const rows = buildCashFlows(scenario);
const benefit = rows.reduce((sum, row) => sum + row.benefit, 0);
const cost = rows.reduce((sum, row) => sum + row.cost, initial);
const discount = (amount: number, index: number) =>
amount / (1 + monthlyDiscount) ** (index + 1);
const cashFlows = rows.map((row) => row.net);
const discounted = cashFlows.map(discount);
return {
name: scenario.name,
weight: scenario.weight,
benefit,
cost,
roi: (benefit - cost) / cost,
npv: discounted.reduce((sum, row) => sum + row, -initial),
payback: paybackMonth(cashFlows),
discountedPayback: paybackMonth(discounted),
};
}
Treat the setup as a month-zero outflow. The 12% effective annual discount becomes about 0.949% monthly. NPV sums the discounted end-of-month flows plus the initial outflow. Ordinary payback counts to the first month-end at which cumulative cash reaches zero. Discounted payback applies that same test to present-value cash flows. A case that never crosses zero returns null for the modeled horizon. ACCA investment appraisal · OpenStax NPV method
Weight the outcomes and keep the downside visible
const scenarios: Scenario[] = [
{ name: "Downside", weight: 0.25, adoption: 0.35, cashRealization: 0.30, costPerAdoptedTask: 0.50 },
{ name: "Base", weight: 0.50, adoption: 0.65, cashRealization: 0.55, costPerAdoptedTask: 0.35 },
{ name: "Upside", weight: 0.25, adoption: 0.85, cashRealization: 0.70, costPerAdoptedTask: 0.30 },
];
if (scenarios.some(({ weight }) => !Number.isFinite(weight) || weight < 0)
|| Math.abs(scenarios.reduce((sum, { weight }) => sum + weight, 0) - 1) > 1e-9) {
throw new RangeError("Scenario weights must be nonnegative and sum to 1");
}
const outcomes = scenarios.map(summarize);
const expected = (select: (result: ReturnType<typeof summarize>) => number) =>
outcomes.reduce((sum, outcome) => sum + outcome.weight * select(outcome), 0);
const expectedBenefit = expected((result) => result.benefit);
const expectedCost = expected((result) => result.cost);
const expectedNpv = expected((result) => result.npv);
const roiOnExpectedCash = (expectedBenefit - expectedCost) / expectedCost;
const paybackByYearEnd = expected((result) => Number(result.payback !== null));
const usd = (amount: number) => amount.toFixed(2);
const percent = (rate: number) => `${(100 * rate).toFixed(1)}%`;
console.table(outcomes.map(({ name, npv, roi, payback, discountedPayback }) => ({
name, npv: usd(npv), roi: percent(roi), payback, discountedPayback,
})));
console.log({
expectedNpv: usd(expectedNpv),
roiOnExpectedCash: percent(roiOnExpectedCash),
paybackByYearEnd: percent(paybackByYearEnd),
});
| Case | 12-month NPV | Cash ROI | Payback month | Discounted payback month |
|---|---|---|---|---|
| Downside | −$26,067.26 | −44.1% | — | — |
| Base | $43,127.82 | 74.1% | 6 | 6 |
| Upside | $110,359.92 | 177.4% | 4 | 4 |
The weighted NPV is $42,637.08, with a 75% probability of payback by year-end under these assumptions. ROI on expected cash is 74.0%, calculated after weighting benefits and costs. A probability-weighted mean of the three ROI percentages gives a different number because case costs differ.
A finance review needs evidence for both adoption and realization. Pull adoption from completed pilot tasks divided by eligible tasks for a fixed period. Estimate cost per adopted task from billed attempts, retries and human review. Tie realization to a specific expense that changes, such as overtime hours or a vendor minimum.
For a worksheet version, map the three cases to the payback calculator and use the token worksheet to estimate metered model cost before adding retry and review spend. The maintainers of this article also publish these tools. AI agent payback calculator · AI token cost calculator
AI disclosure. This article was generated with AI.
來源:DEV Community · dev.to