Skip to content

Instantly share code, notes, and snippets.

@morganp
Created July 11, 2013 11:44
Show Gist options
  • Save morganp/5974746 to your computer and use it in GitHub Desktop.
Save morganp/5974746 to your computer and use it in GitHub Desktop.
Pension Planner, Compound interest with annual payments, annual payments can increase linearly overtime (%). Initial statement, how much you currently have in your plan. Years to calculate over. The lower we can get this and still get the final value you require for retirement the sooner we can retire. **Retiring sooner will mean more money is r…
#!/usr/bin/env ruby
# encoding: UTF-8
require 'pp'
statement = [1000.0] ## Pounds starting balance
years = 20 ## How many statement calculations
interest_rate = 0.04 ## Decimal ie 10% is 0.10
annual_payment = 1000 ## Pounds
payment_increase = 0.02 ## increase payments by %2 (0.02) a year.
(1..years).each do |year|
current_annual_payment = annual_payment * (1 + ( year * payment_increase ))
statement[year] = (statement[year - 1] + current_annual_payment )*(1+interest_rate)
end
#pp statement
puts "Initial #{statement[0]}, #{years} years at #{interest_rate} interest. "
puts "first annual deposit #{annual_payment}, deposits increasing /year by #{payment_increase}"
puts "£#{statement[years].to_i}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment