Class: TimeValue
- Inherits:
-
Object
- Object
- TimeValue
- Defined in:
- lib/timevalue.rb
Instance Attribute Summary collapse
-
#fv ⇒ Object
Returns the value of attribute fv.
-
#i ⇒ Object
Returns the value of attribute i.
-
#n ⇒ Object
Returns the value of attribute n.
-
#pmt ⇒ Object
Returns the value of attribute pmt.
-
#pv ⇒ Object
Returns the value of attribute pv.
Instance Method Summary collapse
- #calc_fv ⇒ Object
- #calc_n ⇒ Object
- #calc_pmt ⇒ Object
-
#calc_pv ⇒ Object
Base formula, ordinary annuity: -PV = [FV/((1+i)^n)] + (PMT/i)*.
-
#initialize(n = 0, i = 0, pv = 0.0, pmt = 0.0, fv = 0.0) ⇒ TimeValue
constructor
A new instance of TimeValue.
Constructor Details
#initialize(n = 0, i = 0, pv = 0.0, pmt = 0.0, fv = 0.0) ⇒ TimeValue
Returns a new instance of TimeValue.
5 6 7 8 9 10 11 |
# File 'lib/timevalue.rb', line 5 def initialize(n = 0, i = 0, pv = 0.0, pmt = 0.0, fv = 0.0) @n = n @i = i.to_f @pv = pv.to_f @pmt = pmt.to_f @fv = fv.to_f end |
Instance Attribute Details
#fv ⇒ Object
Returns the value of attribute fv.
3 4 5 |
# File 'lib/timevalue.rb', line 3 def fv @fv end |
#i ⇒ Object
Returns the value of attribute i.
3 4 5 |
# File 'lib/timevalue.rb', line 3 def i @i end |
#n ⇒ Object
Returns the value of attribute n.
3 4 5 |
# File 'lib/timevalue.rb', line 3 def n @n end |
#pmt ⇒ Object
Returns the value of attribute pmt.
3 4 5 |
# File 'lib/timevalue.rb', line 3 def pmt @pmt end |
#pv ⇒ Object
Returns the value of attribute pv.
3 4 5 |
# File 'lib/timevalue.rb', line 3 def pv @pv end |
Instance Method Details
#calc_fv ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/timevalue.rb', line 25 def calc_fv() i = @i / 100.0 #Growth of initial contribution fvp = @pv * ((1 + i) ** @n) #Growth of payments fva = @pmt * (((1 + i) ** @n)-1) / i @fv = (fvp + fva) * (-1) #Round @fv = (@fv*100).round / 100.0 end |
#calc_n ⇒ Object
36 37 38 39 |
# File 'lib/timevalue.rb', line 36 def calc_n() i = @i / 100.0 @n = (Math.log((@pmt - (i * @fv))/(@pmt + (i * @pv)))/Math.log(1 + i)).round(0) end |
#calc_pmt ⇒ Object
41 42 43 44 45 |
# File 'lib/timevalue.rb', line 41 def calc_pmt() i = @i / 100.0 @pmt = (-i*(@fv+(@pv*((1+i)**n))))/(((1+i)**n)-1) @pmt = (@pmt*100).round / 100.0 end |
#calc_pv ⇒ Object
Base formula, ordinary annuity: -PV = [FV/((1+i)^n)] + (PMT/i)*
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/timevalue.rb', line 14 def calc_pv() i = @i / 100.0 #Initial contribution pvf = @fv / ((1 + i) ** @n) #Present value of annuity pva = (@pmt/i) * (1-(1/((1+i)**@n))) @pv = (pvf + pva) * (-1) #Round @pv = (@pv*100).round / 100.0 end |