2.10
Python
(a)表2.7
code
# 2.10a.py
# 2023-01-08
#
# bp, Baresls produced
# gr, Gross revenue
# ni, Net income
# op1, Option1
# op2, Option2
# da, Depletion allowance
# ti, Tax income
# ai, After-tax income
# input
n = 5
bp =[0, 80e3, 70e3, 50e3, 30e3, 10e3]
gr =[0, 1600e3, 1400e3, 1000e3, 600e3, 200e3]
ni =[0, 1200e3, 1000e3, 500e3, 200e3, 50e3]
# calculating
op1 = [min(x * 0.22, y * 0.5) for x, y in zip(gr, ni)]
op2 = [x * 5 for x in bp]
da = [max(x, y) for x, y in zip(op1, op2)]
ti = [x - y for x, y in zip(ni, da)]
tax = [x * 0.45 for x in ti]
ai = [x - y for x, y in zip(ni, tax)]
# output
print("2.10a.py")
fmt="{:>3}{:>8}{:>8}{:>8}{:>8}{:>8}{:>8}{:>8}{:>8}{:>8}"
header=["y", "bp", "gr", "ni", "opt1", "otp2", "da", "ti", "tax", "ai"]
print(fmt.format(*header))
print(75 * "-")
fmt2="{:3d}{:8.0f}{:8.0f}{:8.0f}{:8.0f}{:8.0f}{:8.0f}{:8.0f}{:8.0f}{:8.0f}"
for i in range(1, n + 1):
print(fmt2.format(i,bp[i],gr[i],ni[i],op1[i],op2[i],da[i],ti[i],tax[i],ai[i]))
print(75 * "-")
print("{:>43}{:8.0f}".format("sum of da=", sum(da)))
# end
output
2.10a.py y bp gr ni opt1 otp2 da ti tax ai --------------------------------------------------------------------------- 1 80000 1600000 1200000 352000 400000 400000 800000 360000 840000 2 70000 1400000 1000000 308000 350000 350000 650000 292500 707500 3 50000 1000000 500000 220000 250000 250000 250000 112500 387500 4 30000 600000 200000 100000 150000 150000 50000 22500 177500 5 10000 200000 50000 25000 50000 50000 0 0 50000 --------------------------------------------------------------------------- sum of da= 1200000
(b)現在価値
(2015-04-01, 2019-09-16)
code
# 2.10b1.py
# since 2015-04-01
# 2.10b1.py 1.2 2019/09/15 23:35:59 s Exp $
#
# r : interest rate
# cf : cash flow stream
# df : discount factor
# pv : present value
# input
r = 0.2
cf = [-1000e3, 840e3, 707500, 387500, 177500, 50e3]
# calculate
df = [1 / (1 + r) ** i for i in range(len(cf))]
pv = [x * y for x, y in zip(cf, df)]
sumpv = sum(pv)
# output
print("2.10b1.py")
print("r= ", r)
fmt1 = "{:>10}{:>10}{:>15}{:>15}"
print(fmt1.format("i", "cf", "1/(1+r)^i", "cf/(1+r)^i"))
print(50 * "-")
fmt2="{:10d}{:10.0f}{:15.3f}{:15.0f}"
for x1, x2, x3, x4 in zip(range(len(cf)), cf, df, pv):
print(fmt2.format(x1, x2, x3, x4))
print(50 * "-")
print("{:>35}{:15.0f}".format("present value=", round(sumpv)))
# end
output
2.10b1.py r= 0.2 i cf 1/(1+r)^i cf/(1+r)^i -------------------------------------------------- 0 -1000000 1.000 -1000000 1 840000 0.833 700000 2 707500 0.694 491319 3 387500 0.579 224248 4 177500 0.482 85600 5 50000 0.402 20094 -------------------------------------------------- present value= 521261
(b)内部収益率
code
# 2.10b2.py
# 22:16 2015-04-01
def f(c):
a=[-1e6,840e3,707500,387500,177500,50e3]
b=[1, c, c**2, c**3, c**4, c**5]
return sum(map(lambda x,y:x*y, a,b))
i=1
eps=1e-3
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
c=mid
irr=1/c-1
print("c= ",round(c,2))
print("f(c)={:.2e}".format(f(c)))
print("i=",i)
print("irr=1/c-1",round(irr,2))
# end
output
c= 0.65 f(c)=-3.94e-05 i= 31 irr=1/c-1 0.53
Julia
(a)表2.7
- 2.10.jl
Fortran
(a)表2.7
- 2.10a.f90(2025-02-01 open revised 2.10a.f90.)
(b)現在価値
- 2.10b1.f90
Gauche
(a)表2.7
- 2.10a.scm
(b)現在価値
- 2.10b1.scm
(b)内部収益率
- 2.10b2.scm
内部収益率
内部収益率の式を次に示す。
f(c) = -1,000,000 + 840,000c + 707,500c2 + 387,500c3 + 177,500c4 + 50,000c5 = 0
内部収益率の式のグラフを次に示す。
図化コマンド
図化コマンドを次のリンクに示す。(2011-10-26)
history
2005-07-01
revised on
2007-04-21 Awk codes(2.10a.awk, 2.10b1.awk, 2.10b2.awk) added.
2011-10-27 gnuplot script(2.10b2.plt) added.
2011-10-29 割引率 in Awk codes corrected to 割引係数 and image format changed
from gif to png.
2011-11-02 Awk code(2.10b2.awk) moved to link.
2014-02-15 Fortran codes(2.10a.f90, 2.10b1.f90, 2.10b2.f90) and
Gauche codes(2.10a.scm, 2.10b1.scm, 2.10b2.scm) added,
Awk codes(2.10a.awk, 2.10b1.awk, 2.10b2.awk) deleted.
2015-03-29 Python code(2.10a.py) added.
2015-04-01 Python codes(2.10b1.py, 2.10b2.py) added.
2016-09-28 Fortran and Gauche codes moved to link.
2018-01-04 XHTML1.0 changed to HTML5.
2018-01-13 png changed to svg.
2018-06-03 charset shift-jis to utf-8.
2019-09-16 2.10b1.py, 2.10b1.f90, and 2.10b1.scm revised.
2021-02-14 move history.
2023-01-08 revise (a)Python code.
2023-01-15 move Fortran codes to 2.10part3.
2023-05-03 add Julia code and Fortran codes.
2024-10-27 revise 2.10b1.scm.
2025-02-01 open revised 2.10a.f90.