Skip to content

Instantly share code, notes, and snippets.

@strboul
Created October 23, 2021 14:57
Show Gist options
  • Save strboul/086af08d6835f5fc5f7068fe2fa0da80 to your computer and use it in GitHub Desktop.
Save strboul/086af08d6835f5fc5f7068fe2fa0da80 to your computer and use it in GitHub Desktop.
if a business has $x revenue and $y% fixed growth rate every year, how much revenue will it have in the next $z years?
from pprint import pprint
def calc_growth(revenue, fixed_rate, years):
"""Calculate growth rate
revenue: Initial revenue.
fixed_rate: fixed rate to grow in a year. It's between 0 and 1.
years: number of years.
"""
init_revenue = revenue
output = []
for year in range(1, years + 1):
revenue = revenue + (revenue * fixed_rate)
cum_growth_rate = (revenue - init_revenue) / 100 / 10
year_status = {
"year": year,
"revenue": round(revenue, 3),
"cum_growth_rate": round(cum_growth_rate, 3),
}
output.append(year_status)
return output
# if a business has 1000 revenue and 13% fixed growth rate every year, how
# much revenue will it have in the next 5 years?
out = calc_growth(1000, 0.13, 5)
pprint(out)
# [{'cum_growth_rate': 0.13, 'revenue': 1130.0, 'year': 1},
# {'cum_growth_rate': 0.277, 'revenue': 1276.9, 'year': 2},
# {'cum_growth_rate': 0.443, 'revenue': 1442.897, 'year': 3},
# {'cum_growth_rate': 0.63, 'revenue': 1630.474, 'year': 4},
# {'cum_growth_rate': 0.842, 'revenue': 1842.435, 'year': 5}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment