top of page
Writer's pictureUzair Ansari

Calculate Inflation, CAGR, optimum salary using powershell

Updated: Nov 5, 2021

Ever felt the need to calculate inflation, depreciation or CAGR? Well there are several methods and online tools available to calculate it if you do it manually. However if you want to embed the code in powershell script or some windows based application, you can refer the code below.

There are different scripts mentioned below. One will enable to calculate inflation or depreciation after some number of years, the other will help you calculate the amount with CAGR after specific number of years, and one script will enable you to calculate the CAGR percentage.




Below is an example script to calculate the value of $100000 after 10 years at the average inflation percentage of 6.

You need to enter the value as below.

  1. The amount which you want to calculate in $BB variable.

  2. Inflation percentage in $InflationPercent variable

  3. Number of years in $n variable

This script will list out the inflation amount for $100000 for each year.

#Beginning Balance
$BB = 100000

#Inflation / Depreciation percent
$InflationPercent = 6

#No of years
$n = 10

for ($i=1;$i -le $n; $i++)
{
    Write-Host "$i - $BB"
    $BB = [System.Math]::Round($($BB - ($BB * $InflationPercent /100)),2)
}


Below is an example script to calculate the value of $100000 after 10 years at the average inflation percentage of 6.

You need to enter the value as below.

  1. The amount which you want to calculate in $BB variable.

  2. Inflation percentage in $InflationPercent variable

  3. Number of years in $n variable

This script will list out the final inflation amount for $100000 that will be after 10 years.

#Beginning Balance
$BB = 100000

#Inflation / Depreciation percent
$InflationPercent = 6

#No of years
$n = 10

for ($i=1;$i -lt $n; $i++)
{
    $BB = [System.Math]::Round($($BB - ($BB * $InflationPercent /100)),2)
}
$BB



Below is an example script to calculate the value of $100000 after 10 years at CAGR of 15.

You need to enter the value as below.

  1. The amount which you want to calculate in $BB variable.

  2. CAGR percentage in $CAGR variable

  3. Number of years in $n variable

This script will list out the CAGR amount for $100000 for each year.


#BB
$BB = 100000

#CAGR percent
$CAGR = 15

#No of years
$n = 10

for ($i=1; $i -le $n; $i++)
{
    Write-Host "$i - $BB"
    $BB = [System.Math]::Round($($BB + ($BB * $CAGR /100)),2)
}



Below is an example script to calculate the value of $100000 after 10 years at CAGR of 15.

You need to enter the value as below.

  1. The amount which you want to calculate in $BB variable.

  2. CAGR percentage in $CAGR variable

  3. Number of years in $n variable

This script will list the final CAGR amount for $100000 that will be after 10 years.

#BB
$BB = 100000

#CAGR percent
$CAGR = 15

#No of years
$n = 10

for ($i=1; $i -lt $n; $i++)
{
    $BB = [System.Math]::Round($($BB + ($BB * $CAGR /100)),2)
}
$BB


You could also the above method to calculate your optimum salary after X number of years if you receive Y percent of hike every year. Here is an example:

  1. Your current annual salary package in $CP variable.

  2. Average increment percentage in $inc variable

  3. Number of years in $n variable

This script will list the final amount for $100000 that will be after 10 years.

#CP
$CP = 100000

#Increament percent
$inc = 8

#No of years
$n = 10

for ($i=1; $i -lt $n; $i++)
{
    $CP = [System.Math]::Round($($CP + ($Cp * $inc /100)),2)
}
$CP



Below is an example script to calculate CAGR percentage of $100 over a period of 2 years.

You need to enter the value as below.

  1. The initial invested amount in $BB variable

  2. The final ]amount in $EB variable

  3. Total duration in years for which the amount was invested in $n variable

This script will list the final CAGR percentage

#Beginning Balance
$BB = 100

#Ending Balance
$EB = 125

#No of years
$n = 2

$MB = $EB/$BB
$x = 1/$n
[math]::Round($([math]::Pow($MB,$x) - 1)*100,2)



You could also the above method to calculate your average salary increment after X number of years. Here is an example:

  1. Your initial salary package in $BB variable

  2. The final salary package in $EB variable

  3. Total duration in years when your salary increased from $BB to $EB in variable $n

This will generate an average salary increment percentage

#Beginning Balance
$BB = 500000
 
#Ending Balance
$EB = 850000
 
#No of years
$n = 5
 
$MB = $EB/$BB
$x = 1/$n
[math]::Round($([math]::Pow($MB,$x) - 1)*100,2)

Comments


bottom of page