You are building the growth calculator at the core of a yield product. It is handed a principal amount, an annual interest rate expressed as a decimal (so 0.05 means five percent per year), and a horizon measured in years (which may be fractional). It returns, as a single number, the value the principal grows to over that horizon. If the horizon is zero or the rate is zero, nothing compounds and the result is the original principal.
Implement a function futureValue(principal, annualRate, years). The multiplication of principal by a growth factor is straightforward; the entire result hinges on a single modeling choice you must make and pin down precisely: how the annual rate is applied across the horizon.
Specify exactly how the rate compounds. Applying the rate once per year, as principal times one-plus-rate raised to the number of years, is the obvious choice, but it is not the only one and it is not the convention this kind of growth is conventionally quoted under. There is a standard limiting convention in which the rate compounds at the finest possible frequency rather than once a year, and it produces a strictly larger growth factor for any positive rate and horizon. Decide which convention governs, state the exact growth factor it uses (including the precise function of the rate and the horizon), and write it as something a deterministic test could check. A calculator that compounds once per year will quietly disagree with the convention for every period that actually earns a return.
Example
With principal 1,000,000 and annualRate 0.06 over 1 year, compounding once per year gives 1,060,000. The convention this growth is quoted under gives a larger number, because the rate compounds at the finest frequency rather than annually. The two answers diverge for any nonzero rate and horizon.