contents

2.8

Let CFSA、CFSB denote the cash flow streams of option A and option B, and they are the following.

CFSA = (-6000, -8000, -8000, -8000, -8000, 0)
CFSB = (-30000, -2000, -2000, -2000, -2000, 10000)

Let CFSA->B denote CFSA - CFSB, and it is the following.

CFSA->B = CFSB - CFSA
       =(-24000, 6000, 6000, 6000, 6000, 10000)

The internal rate of return is found by solving the equation

f(c) = -24000 + 6000c + 6000c2 + 6000c3 + 6000c4 + 10000c5

(Fig.2.8 shows the above equation.)
fig of f(c)

The solution can be found to be 0.89, and thus
∴ IRR = (1 / c) - 1 = (1 / 0.89) - 1 = 0.12

note: gnuplot input file

The file is linked below.


Python with numpy.irr

codeの説明

関数 numpy.irr() を用いて、内部収益率 irr を求める。(added on 2016-12-03)

code

# 2.8.numpy.irr.py
# create on 2016/12/03

import numpy

# input
cfs = [-24, 6, 6, 6, 6, 10]

# calculate
a   = numpy.irr(cfs)

# output
print(round(a, 3))

# end

output

0.118

Python with numpy.polynomial.Polynomial

codeの説明

code


# 2.8.poly.py
# created on 2016-11-19

import numpy

# input
p = numpy.polynomial.Polynomial([-24, 6, 6, 6, 6, 10]) 

# calculate
root1 = p.roots() 
index1 = numpy.isreal(root1)
root2 = root1[index1]
root3 = numpy.real(root2)
root4 = root3[0]

# output
print('2.8.poly.py')
print('p=', p)
print('root1=', root1)
print()
print('real root?', index1)
print('{:10}{:20}{:20}'.format('root2=', str(root2), ' (=complex array)'))
print('{:10}{:20}{:20}'.format('root3=', str(root3), ' (=real array)'   ))
print('{:10}{:20}{:20}'.format('root4=',     root4,  ' (=real number)'  ))
# end

output


2.8.poly.py
p= poly([-24.   6.   6.   6.   6.  10.])
root1= [-1.06272954-0.7431193j  -1.06272954+0.7431193j   0.31566636-1.22333315j
  0.31566636+1.22333315j  0.89412636+0.j        ]

real root? [False False False False  True]
root2=    [ 0.89412636+0.j]    (=complex array)   
root3=    [ 0.89412636]        (=real array)      
root4=      0.8941263576148393 (=real number)     

Python

codeの説明

code


# 2.8.py
# 16:35 2015-03-29

def f(x):
  return -24e3 + 6e3*x + 6e3*x**2 + 6e3*x**3 + 6e3*x**4 + 1e4*x**5

# input
i = 1
eps = 1e-5
left = 0
right = 1
mid = (left + right) / 2

while abs(f(mid))>eps:
  if(f(mid))>0:
    right = mid
  else:
    left = mid
  mid = (left + right) / 2
  i = i + 1

# output
print("c= ", round(mid, 2))
print("f(c)= {:.2e}".format(f(mid)))
print("i= ", i)

# end

output


c=  0.89
f(c)= -8.36e-06
i=  29


Fortran code

An Fortran code to solve f(c) = 0 in bisection method is below.

2.8.f90(2025-02-01 open revised 2.8.f90)

Gauche code

An Gauche code to solve f(c) = 0 in bisection method is below.

2.8.scm

JavaScript code

(added on 2016-02-07)

2.8.js

Maxima

Maxima で f(c) = 0 の根を求める。(added on 2016-11-04)


下記は、(-24000) + 6000*c + 6000*c^2 + 6000*c^3 + 6000*c^4 + 10000*c^5 = 0 の根を閉区間[0, 1]上で見つける。見つけた根は、0.894...である。


Maxima 5.38.1 http://maxima.sourceforge.net
using Lisp SBCL 1.3.4
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) find_root((-24000)+6000*c+6000*c^2+6000*c^3+6000*c^4+10000*c^5 = 0,c,0,1);
(%o1)                         0.8941263576148387
(%i2)


history

2004-4-10, revised on 2004-05-01, 2007-04-21, 2009-11-01, 2011-10-27, 2011-11-02, 2012-06-08, 2014-02-12, 2015-03-29, 2016-02-07, 2016-09-28.
2016-09-28 Fortran, Gauche, Javascript codes moved to link.
2016-11-04 Maxima added.
2016-11-18 Python 3 code with numpy added.
2018-01-02 png changed to svg.
2018-01-04 XHTML1.0 changed to HTML5.
2018-06-03 charset shift-jis to utf-8.
2021-02-14 move history.
2025-02-01 open revised 2.8.f90.