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.
7 8 9 |
# File 'lib/xirr/base.rb', line 7 def cf @cf end |
Instance Method Details
#initialize(cf) ⇒ Object
Must provide the calling Cashflow in order to calculate
11 12 13 |
# File 'lib/xirr/base.rb', line 11 def initialize(cf) @cf = cf end |
#periods_from_start(date) ⇒ Rational
Calculates days until last transaction
18 19 20 |
# File 'lib/xirr/base.rb', line 18 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
25 26 27 28 29 |
# File 'lib/xirr/base.rb', line 25 def xnpv(rate) cf.inject(0) do |sum, t| sum + (xnpv_c rate, t.amount, periods_from_start(t.date)) end end |