Class: Xirr::Bisection
Overview
Bisection solver: repeatedly halves a bracket that straddles the root. It
always converges on a bracketed flow but only linearly, so it is slower than
RtSafe, which is the default. Kept for xirr(method: :bisection).
Instance Attribute Summary
Attributes included from Base
Instance Method Summary collapse
-
#xirr(midpoint, options) ⇒ Float
Calculates yearly Internal Rate of Return An initial guess rate will override the Cashflow#irr_guess.
Methods included from Base
#initialize, #periods_from_start, #xnpv, #xnpv_derivative
Instance Method Details
#xirr(midpoint, options) ⇒ Float
Calculates yearly Internal Rate of Return An initial guess rate will override the Cashflow#irr_guess
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/xirr/bisection.rb', line 14 def xirr(midpoint, ) # Initial values left = [-0.99999999, cf.irr_guess].min right = [9.99999999, cf.irr_guess + 1].max @original_right = right midpoint ||= cf.irr_guess midpoint, runs = loop_rates(left, midpoint, right, [:iteration_limit]) get_answer(midpoint, , runs) end |