module Xirr::Base
Base
module for XIRR calculation Methods
Attributes
cf[R]
Public Class Methods
new(cf)
click to toggle source
@param cf [Cashflow] Must provide the calling Cashflow
in order to calculate
# File lib/xirr/base.rb, line 11 def initialize(cf) @cf = cf end
Public Instance Methods
periods_from_start(date)
click to toggle source
Calculates days until last transaction @return [Rational] @param date [Date]
# File lib/xirr/base.rb, line 18 def periods_from_start(date) (date - cf.min_date) / cf.period end
xnpv(rate)
click to toggle source
Net Present Value function that will be used to reduce the cashflow @param rate [BigDecimal] @return [BigDecimal]
# 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