Module: Xirr::Base
- Extended by:
- ActiveSupport::Concern
- Included in:
- Bisection, NewtonMethod
- Defined in:
- lib/xirr/base.rb
Overview
Base module for XIRR calculation Methods
Instance Attribute Summary collapse
-
#cf ⇒ Object
readonly
Returns the value of attribute cf.
Instance Method Summary collapse
-
#initialize(cf) ⇒ Object
Must provide the calling Cashflow in order to calculate.
-
#periods_from_start(date) ⇒ Rational
Calculates days until last transaction.
-
#xnpv(rate) ⇒ BigDecimal
Net Present Value function that will be used to reduce the cashflow.
Instance Attribute Details
#cf ⇒ Object (readonly)
Returns the value of attribute cf.
8 9 10 |
# File 'lib/xirr/base.rb', line 8 def cf @cf end |
Instance Method Details
#initialize(cf) ⇒ Object
Must provide the calling Cashflow in order to calculate
12 13 14 |
# File 'lib/xirr/base.rb', line 12 def initialize(cf) @cf = cf end |
#periods_from_start(date) ⇒ Rational
Calculates days until last transaction
19 20 21 |
# File 'lib/xirr/base.rb', line 19 def periods_from_start(date) (date - cf.min_date) / cf.period end |
#xnpv(rate) ⇒ BigDecimal
Net Present Value function that will be used to reduce the cashflow
26 27 28 29 30 31 |
# File 'lib/xirr/base.rb', line 26 def xnpv(rate) cf.inject(0) do |sum, t| # sum + (xnpv_c rate, t.amount, periods_from_start(t.date)) sum + t.amount / (1+rate.to_f) ** periods_from_start(t.date) end end |