Class: Xirr::Bisection

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/xirr/bisection.rb

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

#cf

Instance Method Summary collapse

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

Parameters:

  • midpoint (Float)

Returns:

  • (Float)


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/xirr/bisection.rb', line 14

def xirr(midpoint, options)
  # 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, options[:iteration_limit])

  get_answer(midpoint, options, runs)
end