Dev.to WebDev 🛠 Dev 👁 0 📖 3 min read

APY vs APR: The Compounding Frequency Nobody Quotes

Two savings products both advertise "6%". One pays you 6.00% over the year. The other pays 6.17%. The difference is not a fee or a promotion — it is how often the interest compounds, and it is the single most misquoted n

Two savings products both advertise "6%". One pays you 6.00% over the year. The other pays 6.17%. The difference is not a fee or a promotion — it is how often the interest compounds, and it is the single most misquoted number in consumer finance.

The relationship

The nominal annual rate $r$ and the number of compounding periods per year $n$ give the effective annual yield (APY):

$$\text{APY} = \left(1 + \frac{r}{n}\right)^{n} - 1$$

When $n = 1$ the APY equals the nominal rate. When $n = 12$ it is higher. The limit as $n \to \infty$ is continuous compounding:

$$\text{APY} = e^{r} - 1$$

In code, the direct form is fine for ordinary rates but breaks down for very small $r$, because $(1 + r/n)^n$ suffers catastrophic cancellation:

function apy(r, n) {
  if (r === 0) return 0;
  // expm1 keeps precision when r/n is tiny
  return Math.expm1(n * Math.log1p(r / n));
}

Math.expm1(x) computes $e^x - 1$ accurately for small $x$, and Math.log1p(x) computes $\ln(1+x)$ accurately for small $x$. Together they are the numerically safe way to evaluate this expression.

Worked example

A 6% nominal annual rate:

  • Annual ($n = 1$): $\text{APY} = (1.06)^1 - 1 = 6.000\%$
  • Monthly ($n = 12$): $\text{APY} = (1 + 0.005)^{12} - 1 = 6.168\%$
  • Daily ($n = 365$): $\text{APY} = (1 + 0.06/365)^{365} - 1 = 6.183\%$
  • Continuous: $\text{APY} = e^{0.06} - 1 = 6.184\%$

The gap between annual and monthly is 17 basis points — real money on a large balance. The gap between daily and continuous is 0.1 basis point — nothing. That asymmetry is why banks advertise "daily compounding" as if it mattered: it sounds precise, but it buys almost nothing over monthly.

Edge cases that actually bite

Zero rate. $(1 + 0/n)^n - 1 = 0$, but a naive implementation using Math.pow on a denormalized ratio can return -1 or NaN. Special-case it.

Very high frequency. At $n = 10^6$ and $r = 0.06$, r/n is $6\times10^{-8}$. 1 + 6e-8 is representable, but the $n$-th power loses relative precision. Use the expm1/log1p form above, or just return $e^r - 1$ — the discrete result is already within $10^{-12}$ of the continuous limit.

Negative rates. Some jurisdictions have had negative deposit rates. The formula still works, but Math.log1p(r/n) is fine as long as $1 + r/n > 0$, and Math.pow of a negative base with a fractional exponent is NaN. Guard the sign.

APR vs APY. In the US, APR includes certain fees and is not the same number as the contract rate. Converting APR to APY without knowing which fees are included is guesswork. Always convert from the contract rate, not from a marketing APR.

Quoted "APY" that is actually a nominal rate. Some products label the nominal rate as APY when compounding is annual, which is technically correct but invites comparison against a monthly-compounded rival on unequal footing. Normalize to effective annual before comparing.

Common mistakes

  • Comparing a nominal rate with an APY. Convert both to the same basis first, or the comparison is meaningless.
  • Assuming the stated rate is the yield. It is the yield only when $n = 1$.
  • Using `(1 + r/n)n - 1 in Python 2 style integer arithmetic.** In JS the exponent operator is **; in older code Math.pow`. Neither fixes the precision issue, but at least get the operator right.
  • Hard-coding n = 12. Quarterly, semi-annual, weekly, and daily products all exist. n is an input.
  • Forgetting that "6% APY" and "6% nominal compounded monthly" are different products. The first yields 6.00%, the second 6.168%.
  • Ignoring fees. A product with a higher APY and a monthly maintenance fee can still lose to a lower-APY no-fee product.

Checking your own numbers

If you want to see the conversion for any rate and frequency — including the continuous limit and the basis-point gap between two products — the APY calculator at https://www.miryori.org/tools/apy-calculator runs the formula both ways and shows the effective annual yield.

YMYL note: these figures are illustrative arithmetic, not financial advice. Verify rates, fees, and compounding terms against the product disclosure before making decisions.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.