Class: Xirr::NewtonMethod
- Inherits:
-
Object
- Object
- Xirr::NewtonMethod
- Includes:
- Newton, Base
- Defined in:
- lib/xirr/newton_method.rb
Overview
Class to calculate IRR using Newton Method
Defined Under Namespace
Classes: Function
Instance Attribute Summary
Attributes included from Base
Instance Method Summary collapse
-
#xirr(guess, _options) ⇒ BigDecimal
Calculates XIRR using Newton method.
Methods included from Base
#initialize, #periods_from_start, #xnpv
Instance Method Details
#xirr(guess, _options) ⇒ BigDecimal
Calculates XIRR using Newton method
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/xirr/newton_method.rb', line 48 def xirr(guess, ) func = Function.new(self, :xnpv) rate = [guess || cf.irr_guess] begin nlsolve(func, rate) (rate[0] <= -1 || rate[0].nan?) ? nil : rate[0].round(Xirr.config.precision) # rate[0].round(Xirr.config.precision) rescue nil end end |