Module: Valuation

Defined in:
lib/valuation.rb,
lib/valuation/cash_flows.rb,
lib/valuation/interest_rate.rb

Defined Under Namespace

Classes: CashFlows, InterestRate

Instance Method Summary collapse

Instance Method Details

#annuity(c, i, n, options = {}) ⇒ Object

Returns the present value of an annuity

c = Cash flow at time 1 i = Interest rate n = The number of time periods options hash

:g = Growth Rate Defauls to 0
:pv = Defaults to true


25
26
27
28
29
30
31
32
33
34
# File 'lib/valuation.rb', line 25

def annuity(c, i, n, options = {})
  options = {:g => 0, :pv => true}.merge(options)
  g = options[:g]
  pv = c * (1/(i-g).to_f) * (1 - ((1+g)/(1+i).to_f) ** n)
  if options[:pv] == true
    pv
  else
    pv * (1+i) ** n
  end
end

#npv(c, r) ⇒ Object

Returns the present value of a stream of cash flows that have an interest rate r

c = Array of cash flows r = intrest rate as a decimal



41
42
43
44
45
46
47
# File 'lib/valuation.rb', line 41

def npv(c, r)
  npv=0
  c.each_with_index do |c_t,t|
    npv += c_t.to_f / (1.0+r)**t.to_f
  end
  npv
end

#perpetuity(c, i, g = 0) ⇒ Object

Returns the present value of a perpetuity

c = Cash flow at time 1 i = Interest rate Optional g = Growth rate



13
14
15
# File 'lib/valuation.rb', line 13

def perpetuity(c, i, g=0)
  c / (i-g).to_f
end