# 3.10.jl # create 2023-01-02. # $Id: 3.10.jl 1.1 2023/01/02 00:00:00 s Exp $ using Printf # k : period, 期 # n : the number of years remaining, 満期までの年数 # m : the number of coupon payments per year, 1年当り利払回数 # λ : the yield to maturity, 満期利回り # f : face value, 額面価値 # r : coupon rate, クーポン率 # c : payment, 支払 # input λ = 0.1 n = 10 r = 0.08 m = 2 f = 100 # calculating c = f * r / m j = Array(1: n*m) A = Array(1/m: 1/m: n) B = fill(c, n*m) B[n*m] += f C = 1 ./ (1 .+ λ ./ m) .^ j D = B .* C price = sum(D) E = D ./ price F = A .* E duration = sum(F) # output println("3.10.jl") println(repeat("-", 65)) @printf("%10s%10s%10s%15s%10s%10s\n","A", "B", "C", "D", "E", "F") @printf("%10s%10s%10s%15s%10s%10s\n","", "", "Discount", "Present Value", "", "") @printf("%10s%10s%10s%15s%10s%10s\n","", "", "factor", "of payment", "Weight", "") @printf("%10s%10s%10s%15s%10s%10s\n","Year","Payment","(@10%)","(BxC)","(D/Price)","AxE") println(repeat("-", 65)) for k = 1:length(A) @printf("%10.1f%10.0f%10.3f%15.3f%10.3f%10.3f\n",A[k], B[k], C[k], D[k], E[k], F[k]) end println(repeat("-", 65)) @printf("%10s%20s%15.3f%10.3f%10.3f\n", "Sum", "", price, sum(E), duration) @printf("%45s%20s\n", "Price", "Duration") println(repeat("-", 65)) # eof