Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
346 views
ubuntu2204
Kernel: Python 3 (system-wide)

Inflation Rate Calculator

How long, until your money is only worth half for a given inflation rate.

# import necessary libraries import numpy as np import matplotlib.pyplot as plt # set initial parameters money = 100 # initial amount of money r = 0.07 # inflation rate years = 30 # number of years to observe t = np.arange(years) # create array for years
# calculate the value of money for each year money_over_time = money * (1 - r)**t # plot the result plt.plot(t, money_over_time) plt.xlabel('Years') plt.ylabel('Value of Money') plt.title(f'Value of Money Over Time with Inflation Rate of {r*100:.0f}%') plt.grid(True) plt.ylim(0) plt.xlim(0) plt.show()
Image in a Jupyter notebook
years = 0 # initialize year counter money = 100 half = money / 2 while money >= half: money = money * (1 - r) # calculate new value of money years += 1 # increment year counter print(f"Your money will be worth {money:.2f} in {years} years.")
Your money will be worth 48.40 in 10 years.

Precise formula

ln(12)=yearsln(1r)\ln\left({\frac{1}{2}}\right) = \text{years} * \ln(1 - r)
from sympy import Symbol from sympy.solvers import solve y = Symbol('y') solve(1/2 - 1 * (1-r)**y, y)
[9.55133750944734]
np.log(1/2) / np.log(1-r)
9.551337509447336

Quick and dirty: rule of 72

https://www.investopedia.com/ask/answers/what-is-the-rule-72/

72inflation in percent\frac{72}{\text{inflation in percent}}
72 / (100*r)
10.285714285714285