Skip to content

Instantly share code, notes, and snippets.

@andyjbas
Created February 3, 2013 03:56
Show Gist options
  • Save andyjbas/4700490 to your computer and use it in GitHub Desktop.
Save andyjbas/4700490 to your computer and use it in GitHub Desktop.
class FutureValue
def initialze
end
def annual(rate, years, annual_contribution=0, initial_investment)
pv = self.pv(rate, annual_contribution, years, initial_investment)
pv * (1 + rate)**years
end
# where R is the periodic yield, A is the periodic payment,
# N is the number of payments and i is the initial investment
def pv(r, a, n, i)
((a / r) - a / (r * (1 + r)**n)) + i
end
end
@fv = FutureValue.new
@fv.annual(0.03, 5, 1200, 10000) # => 17963.70
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment