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

Instance Method Summary collapse

Instance Attribute Details

#cfObject (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

Parameters:



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

Parameters:

  • date (Date)

Returns:

  • (Rational)


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

Parameters:

  • rate (BigDecimal)

Returns:

  • (BigDecimal)


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