Created
February 3, 2013 03:56
-
-
Save andyjbas/4700490 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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