You are building the discounting calculator at the core of a fixed-income tool. It is handed a future cashflow amount, an annual interest rate expressed as a decimal (so 0.05 means five percent per year), and a horizon in years until the cashflow arrives (which may be fractional). It returns, as a single number, what that future amount is worth today. If the horizon is zero or the rate is zero, there is nothing to discount and the result is the future amount itself.
Implement a function presentValue(futureAmount, annualRate, years). Dividing the future amount by a discount factor is straightforward; the entire result hinges on a single modeling choice you must make and pin down precisely: how often the rate compounds within the discount factor.
Specify exactly the compounding frequency of the discount. Discounting with the rate applied once per year, as the future amount divided by one-plus-rate raised to the number of years, is the obvious choice, but it is not the convention this family of instruments is conventionally discounted under. There is a standard convention in which the rate compounds more than once a year, which makes the discount factor larger and the present value smaller. Decide which convention governs, state the per-period rate and the number of periods it uses exactly, and write it as something a deterministic test could check. A calculator that compounds annually will quietly disagree with the convention for every period that actually discounts.
Example
With a futureAmount of 1,000,000 and annualRate 0.06 over 1 year, discounting once per year gives about 943,396. The convention this instrument is discounted under gives a smaller number, because the rate compounds more often than annually. The two answers diverge for any nonzero rate and horizon.