# 2.15.2.jl # 2023-01-01 # $Id: 2.15.2.jl 1.1 2023/01/01 00:00:00 s Exp $ # bc, before-tax cash flow # nbc, nominal before-tax cash flow # da, depreciation amount # ti, taxable income # ta, tax # ac, after-tax cash flow # tr, tax rate # ir, infration rate # ic, initial capital expenditure # dr, discount rate # df, discount factor # ny, number of years # pv, present value of ac using Printf # input tr = 0.34 ir = 0.04 dr = 0.12 ic = 10e6 ny = 5 bc = [-ic, 2990e3, 2990e3, 2990e3, 2990e3, 2990e3] da = [0, ic/ny, ic/ny, ic/ny, ic/ny, ic/ny ] # calculate nbc = bc .* (1 + ir) .^ (0:length(bc) - 1) # ドット演算子を使用 ti = map((x, y)-> x-y > 0 ? x-y : 0, nbc, da) # 三項演算子を使用 ta = ti .* tr ac = nbc .- ta df = 1 ./ (1 + dr) .^ (0:length(bc) - 1) pv = ac .* df sumpv = sum(pv) # output println("2.15.2.jl") @printf("%9s%10s%10s%10s%10s%10s%10s%10s\n","year", "bc", "da", "ti", "tax", "ac", "df", "pv") println(repeat("-",79)) for i = 1:length(bc) @printf("%9d%10d%10d%10d%10d%10d%10.3f%10d\n", i-1, bc[i], da[i], ti[i], ta[i], ac[i], df[i], pv[i]) end println(repeat("-", 79)) @printf("%69s%10d\n", "sum of pv=", sumpv) #eof