Skip to content

Instantly share code, notes, and snippets.

@samilkorkmaz
Last active February 6, 2024 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samilkorkmaz/4ccbc4298025e8f02ae45a91c0ec8aac to your computer and use it in GitHub Desktop.
Save samilkorkmaz/4ccbc4298025e8f02ae45a91c0ec8aac to your computer and use it in GitHub Desktop.
Calculate inflation adjusted value
# Calculate inflation adjusted value. Generated with chatGPT4
from datetime import datetime
start_amount = 140000
start_year = 2019
end_year = 2024
# Inflation rates by year, from 2019 to the current year
# Note: These are fictional rates for demonstration purposes.
# In a real-world scenario, you would use actual inflation rates obtained from a reliable financial source.
inflation_rates = {
2019: 1.8, # Example inflation rate for 2019
2020: 1.2, # Example inflation rate for 2020
2021: 2.6, # Example inflation rate for 2021
2022: 7.0, # Example inflation rate for 2022
2023: 3.2, # Example inflation rate for 2023
}
# Function to calculate the equivalent value taking inflation into account
def adjust_for_inflation(amount, rates):
for year in range(start_year, end_year + 1):
inflation_rate = rates.get(year, 0) / 100
amount += amount * inflation_rate
return amount
adjusted_value = adjust_for_inflation(start_amount, inflation_rates)
print("start amount in",start_year," :", f"{start_amount:.0f}")
print("inflation adjusted amount in",end_year,":", f"{adjusted_value:.0f}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment