Ilse keeps her savings at the Harlow Savings Bank. Each year t the bank pays a nominal interest rate i_t on her balance, and prices rise by the inflation rate \pi_t over the same year. Both are fractions: 4 % is 0.04, and a negative inflation rate means prices fell.
What she cares about is the real rate r_t: how much more she can buy at the end of the year than at the start. One crown grows to 1 + i_t crowns, while a basket that cost one crown now costs 1 + \pi_t, so
1 + r_t = \frac{1 + i_t}{1 + \pi_t}
This is the Fisher relation. For small rates it is often approximated by r_t \approx i_t - \pi_t.
Write real_returns(rates, inflation) that returns a tuple (exact, approx, total):
exact: the list of exact real rates r_t, one per year, in order;approx: the list of approximate real rates i_t - \pi_t, one per year;total: the exact real return over all the years together: by how much (as a fraction) the buying power of her balance grew from the start of the first year to the end of the last. With no years,totalis0.
Examples
Input: rates = [0.05, 0.04, 0.03], inflation = [0.02, 0.05, 0.03]
Output: ([0.0294118, -0.0095238, 0.0], [0.03, -0.01, 0.0], 0.0196078) (rounded here)
Explanation: in the first year 1.05 / 1.02 = 1.0294118. In the second, inflation beat
the interest rate and buying power fell. Over three years buying power grew by
(1.05 / 1.02) * (1.04 / 1.05) * (1.03 / 1.03) - 1 = 0.0196078.
Input: rates = [0.4], inflation = [0.3]
Output: ([0.0769231], [0.1], 0.0769231) (rounded here)
Explanation: at high inflation the approximation is far off: 1.4 / 1.3 = 1.0769231.
Constraints
- answers are compared with a tolerance of
1e-6; do not round
Goals
- Turn a nominal interest rate and inflation into the exact real rate
- Compare the exact real rate with the approximation $i - \pi$ and see when they differ
- Compound real returns over several years