← All posts
tutorialfinance

How to build a DCF valuation tool with terminal growth and a discount rate slider

Mahesh Naidu·5 min read

Discounted Cash Flow valuation is the standard method analysts use to estimate a company's intrinsic value from its expected future cash flows, rather than its current market price. /dcf implements the full model: projected cash flows, a discount rate, and a terminal value — not just a single-year shortcut.

The five inputs

fetch("https://aplicious.com/api/v1/finance/dcf?cashflow=10000000&growth_rate=12&discount_rate=9&terminal_growth=2.5&years=10", {
  headers: { "X-API-Key": "lapi_live_••••" },
});

cashflow is the base annual free cash flow (required). The other four have sensible defaults if you omit them: growth_rate defaults to 10%, discount_rate (effectively your WACC, weighted average cost of capital) defaults to 10%, terminal_growthdefaults to 2.5% (roughly long-run GDP growth, the standard conservative assumption for a company's cash flows after the explicit projection period), and years defaults to 10, capped at 20.

Why both a projection period and a terminal value

You can't project cash flows accurately forever, so DCF models split valuation into two parts: an explicit projection period (here, up to 20 years) where you forecast each year's cash flow individually and discount it back to present value, plus a terminal value representing everything after that period, calculated with the Gordon Growth Model and discounted back as a single lump sum. Get the terminal growth rate wrong and the whole valuation swings wildly — which is exactly why it's exposed as a parameter rather than hardcoded, so you can show sensitivity across a range of assumptions instead of presenting one number as gospel.

Building a sensitivity table

The real value of exposing every assumption as a parameter is that you can call the endpoint multiple times with different discount rates and show a sensitivity table — exactly what a serious valuation tool should show, instead of a single point estimate that implies more precision than DCF models actually have.

async function sensitivityTable(cashflow: number, discountRates: number[]) {
  const headers = { "X-API-Key": process.env.APLICIOUS_KEY! };
  const results = await Promise.all(
    discountRates.map(rate =>
      fetch(`https://aplicious.com/api/v1/finance/dcf?cashflow=${cashflow}&discount_rate=${rate}`, { headers })
        .then(r => r.json())
    )
  );
  return discountRates.map((rate, i) => ({ discount_rate: rate, value: results[i].data }));
}

This is also why /dcf is pure computation with no upstream data dependency — the inputs are always yours, so the same call always returns the same number, which makes it safe to call repeatedly while a user drags a discount-rate slider in real time.

Try APlicious free
One key. 34 live namespaces. 500 free calls per month — no credit card required.
Get your free API key →
← Back to all posts