Skip to content

Instantly share code, notes, and snippets.

@prdpspkt
Last active November 16, 2018 02:49
Show Gist options
  • Save prdpspkt/ff4a8e2b077494f530741800be592f8f to your computer and use it in GitHub Desktop.
Save prdpspkt/ff4a8e2b077494f530741800be592f8f to your computer and use it in GitHub Desktop.
Calculate how much you save after some years for monthly saving...
@year = 40 #total years you want to save monthly
@months = @year*12
@saving = 200 #amount of money you want to save monthly
@yearly_interest_rate = 6 #yearly interest rate for monthly saving
@interest_calculation_duration_in_month = 3 #interest is calculated each 3 months
@monthly_interest_rate = (@yearly_interest_rate/100.0)/12.0
@amount = 0
(1..@year).each do |y|
(1..12).each do |m|
@amount = @amount + @saving
if(m % @interest_calculation_duration_in_month == 0)
@interest = 0
(1..@interest_calculation_duration_in_month).each do |im|
@interest = @interest + @saving*im*@monthly_interest_rate
end
@interest = @interest + ((@amount-(3*@saving))*3*@monthly_interest_rate)
@interest = @interest - (@interest*5.00/100.0) #5% income tax
@amount = @amount + @interest
end
end
end
print @amount
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment