Class: Valuation::CashFlows
- Inherits:
-
Object
- Object
- Valuation::CashFlows
- Defined in:
- lib/valuation/cash_flows.rb
Instance Method Summary collapse
- #future_value ⇒ Object
-
#initialize(flows, options = {}) ⇒ CashFlows
constructor
A new instance of CashFlows.
- #irr(significant_digits = 4) ⇒ Object
- #present_value ⇒ Object
Constructor Details
#initialize(flows, options = {}) ⇒ CashFlows
Returns a new instance of CashFlows.
5 6 7 8 |
# File 'lib/valuation/cash_flows.rb', line 5 def initialize(flows, = {}) @flows = flows @i = [:i] || 0 end |
Instance Method Details
#future_value ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/valuation/cash_flows.rb', line 18 def future_value value = 0 @flows.reverse.each_index do |n| value += @flows[n] * ((1+@i)**n).to_f end value end |
#irr(significant_digits = 4) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/valuation/cash_flows.rb', line 26 def irr(significant_digits=4) limit = 10**-(significant_digits) estimate = @flows.sum/(@flows.size-1.0)/75.0 delta = estimate.abs n = npv(@flows,estimate) while n.abs > limit sign = n/n.abs if (delta.abs < limit/1000) delta=estimate.abs #if we aren't getting anywhere, take a big jump return sign/0.0 if (n-@flows[0]).abs < limit end estimate += (delta/=2) * sign n = npv(@flows,estimate) end estimate end |
#present_value ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/valuation/cash_flows.rb', line 10 def present_value value = 0 @flows.each_index do |n| value += @flows[n] / ((1+@i)**n).to_f end value end |