/* ** Version 01 ** Date : 20/07/2001 ** -------------------------------------------------------------------------- ** Copyright K.Cuthbertson and D. Nitzsche ** "Financial Engineering:Derivatives and Risk Manangement" - J. Wiley 2001 ** ** PORTFOLIO INSURANCE ** ** Calculating the value of a 'Stock + Bond' replication portfolio. ** */ new ; cls ; /* ofile = "c:\\kcdn\\output.out" ; output file = ^ofile reset ; */ format /m1/rdn 16,8 ; output on ; screen on ; " ------------------------------------------------------------------------ " ; " " ; " FILE : Chp13 Tab4 Port Ins(Bonds).txt " ; " ===================================== " ; " " ; " Version 20/07/2001 " ; " " ; " Copyright K.Cuthbertson and D. Nitzsche " ; " 'Financial Engineering:Derivatives and Risk Manangement' - J. Wiley 2001 " ; " " ; " PORTFOLIO INSURANCE " ; " Calculating the value of a 'Stock + Bond' replication portfolio. " ; " " ; " ------------------------------------------------------------------------ " ; output off ; screen off ; " ---------------------------------------------------------- " ; " " ; " Definitions of Variables Used " ; " ----------------------------- " ; " " ; " S0 = Share Price (starting value) " ; " K = Strike Price " ; " r = Interest rates " ; " sigma = Volatility " ; " Drift = Drift parameter " ; " div_r = Dividend rate " ; " TT = Time to maturity (years) " ; " dt = Time step " ; " " ; " VAL = Value of the portfolio " ; " zf = Multiple of stock index futures contract " ; " M = Maturity / face value of T-bill/bond " ; " " ; " ---------------------------------------------------------- " ; /* ----------------------------------- START USER DATA INPUT --------------------------------- */ S0 = 280 ; K = 280 ; r = 0.1 ; sigma = 0.12 ; Drift = 0.15 ; div_r = 0 ; TT = 0.1 ; dt = 0.01 ; VAL = 560000 ; zf = 500 ; M = 100 ; /* --------------------------------------- END USER DATA INPUT ------------------------------- */ /* ------------------------------------- STARTING THE CALCULATION ---------------------------- */ @ Setting the global - GS @ _GS = ones(TT/dt+1,1) ; _GS = _GS*S0 ; @ Default of the global @ GS_vec = 280|279|278.8|278.5|278|277.5|277|276.5|276|275.5|275 ; @ Here first 11 elements are different from S0 @ _GS[1:11,1] = GS_Vec ; /* ** This procedure contains 2 switches - see Procedure for details ** CALLING THE PROCEDURE WHICH CALCULATES TO OBTAIN ALL THE VARIABLES */ {S,d1,d2,call_del,put_del,call_p,put_p,Size,timeleft} = calc1(S0, K, r, Drift, div_r, sigma, TT, dt, 0, 0) ; T_time = seqa(0,dt,TT/dt+1) ; N0_star = VAL/S0 ; @ Calculating the Hedge Position @ N0 = VAL/(S0+put_p[1,1]) ; /* ----------------------------------- CALCULATIONS FOR 'STOCK + PUT' PORTFOLIO ------------------------- */ dVS = zeros(Size,1) ; dVP = zeros(Size,1) ; dVSP = zeros(Size,1) ; VSP_T = zeros(Size,1) ; dVSP_T = zeros(Size,1) ; n = 1 ; VSP_T[n,1] = N0*(S[n,1] + put_p[n,1]) ; n = 2 ; do until n > Size ; dVS[n,1] = N0*(S[n,1]-S[n-1,1]) ; dVP[n,1] = N0*put_del[n-1,1]*(S[n,1]-S[n-1,1]) ; dVSP[n,1] = dVS[n,1] + dVP[n,1] ; VSP_T[n,1] = N0*(S[n,1] + put_p[n,1]) ; dVSP_T[n,1] = VSP_T[n,1] - VSP_T[n-1,1] ; n = n+1 ; endo ; /* ------------------------- CALCULATIOSN FOR 'STOCK + BOND' PORTFOLIO ----------------------- */ NS = zeros(Size,1) ; NsdS = zeros(Size,1) ; dVSB = zeros(Size,1) ; B = zeros(Size,1) ; NB = zeros(Size,1) ; NBB = zeros(Size,1) ; n = 1 ; NS[n,1] = N0*(call_del[n,1]) ; B[n,1] = M*exp(-r*timeleft[n,1]) ; NB[n,1] = (VSP_T[n,1]-NS[n,1]*S[n,1])/B[n,1] ; NBB[n,1]= B[n,1]*NB[n,1] ; n = 2 ; do until n > Size ; NS[n,1] = N0*(call_del[n,1]) ; NSdS[n,1] = NS[n-1,1]*(S[n,1]-S[n-1,1]) ; dVSB[n,1] = NSdS[n,1] ; B[n,1] = M*exp(-r*timeleft[n,1]) ; NB[n,1] = (VSP_T[n,1]-NS[n,1]*S[n,1])/B[n,1] ; NBB[n,1] = B[n,1]*NB[n,1] ; n = n+1 ; endo ; /* ----------------------------------------- PRINTING THE OUTPUT ------------------------------ */ output on ; screen on ; mask1 = 1~1~1~1~1~1~1~1~1 ; let fmt1[9,3] = " *.*lf" 6 2 " *.*lf" 9 2 " *.*lf" 14 2 " *.*lf" 16 4 " *.*lf" 10 4 " *.*lf" 16 4 " *.*lf" 12 4 " *.*lf" 16 4 " *.*lf" 12 4 ; PI_tab1 = T_time~timeleft~S~d1~d2~call_del~put_del~call_p~put_p ; mask2 = 1~1~1~1~1~1~1~1 ; let fmt2[8,3] = " *.*lf" 6 2 " *.*lf" 9 2 " *.*lf" 14 2 " *.*lf" 16 4 " *.*lf" 15 4 " *.*lf" 18 4 " *.*lf" 18 4 " *.*lf" 16 4 ; PI_tab2 = T_time~timeleft~S~dVS~dVP~dVSP~VSP_T~dVSP_T ; mask3 = 1~1~1~1~1~1~1~1~1 ; let fmt3[9,3] = " *.*lf" 6 2 " *.*lf" 9 2 " *.*lf" 14 2 " *.*lf" 15 4 " *.*lf" 14 4 " *.*lf" 15 4 " *.*lf" 17 2 " *.*lf" 12 4 " *.*lf" 14 2 ; PI_tab3 = T_time~timeleft~S~NS~NSdS~dVSB~NB~B~NBB ; @@ ""; @@ ""; @@ " TABLE 13.04 : PORTFOLIO INSURANCE " ; @@ " ('STOCK + BOND' REPLICATION PORTFOLIO) " ; @@ " ====================================== " ; @@ ""; @@ ftos(S0,"Initial Share Price, S : %*.*lf",13,2) ; @@ ftos(K,"Strike Price, K : %*.*lf",20,2) ; @@ ftos(put_p[1,1],"Initial put premium, P : %*.*lf",15,4) ; @@ ""; @@ ftos(r,"Interest rate : %*.*lf",22,2) ; @@ ftos(sigma,"Volatility : %*.*lf",25,2) ; @@ ftos(Drift,"Drift rate for stock : %*.*lf",15,2) ; @@ ftos(div_r,"Dividend rate : %*.*lf",22,2) ; @@ ftos(TT,"Time to maturity (years) : %*.*lf",11,2) ; @@ ftos(dt,"Time steps : %*.*lf",25,2) ; @@ ""; @@ ftos(VAL,"Initial value of stock portfolio : %*.*lf",25,2) ; @@ ftos(zf,"Multiple on stock index futures contract : %*.*lf",17,2) ; @@ ftos(M,"Maturity/face value of bill or bond : %*.*lf",22,2) ; @@ ""; @@ ftos(N0_star,"Number of stocks in 'Stock + Bond' portfolio : %*.*lf",13,2) ; @@ ftos(N0,"Number of stocks in 'Stock + Put' portfolio : %*.*lf",14,2) ; @@ ""; @@ ""; @@ "--------------------------------------------------------------------------------------------------------------------- " ; @@ " Time Time left Asset Price d1 d2 Delta of ... Option premium " ; @@ " Call Put Call Put " ; @@ "--------------------------------------------------------------------------------------------------------------------- " ; @@ call printfm(PI_tab1, mask1, fmt1) ; @@ "--------------------------------------------------------------------------------------------------------------------- " ; @@ "" ; @@ "" ; @@ "--------------------------------------------------------------------------------------------------------------------- " ; @@ " STOCK + PUT PORTFOLIO " ; @@ "" ; @@ " Time Time left Asset Price Delta of S Change in Change in True value True change " ; @@ " dV(S) value of puts value of S + put in value " ; @@ " dV(P) dV(S+P) V(S+P) dV(S+P) " ; @@ "--------------------------------------------------------------------------------------------------------------------- " ; @@ call printfm(PI_tab2, mask2, fmt2) ; @@ "--------------------------------------------------------------------------------------------------------------------- " ; @@ "" ; @@ "" ; @@ "--------------------------------------------------------------------------------------------------------------------- " ; @@ " STOCK + BOND PORTFOLIO " ; @@ "" ; @@ " Time Time left Asset Price Number of Change in Delta change Value Number of Bond price Value of " ; @@ " Stocks value of S of Stocks + Bonds bonds Bonds " ; @@ " NS dS dV(S+B) NB B NB x B " ; @@ "--------------------------------------------------------------------------------------------------------------------- " ; @@ call printfm(PI_tab3, mask3, fmt3) ; @@ "--------------------------------------------------------------------------------------------------------------------- " ; @@ "" ; /* ------------------------------------------------------ END OF PROGRAM ---------------------------------------------- */ /* ** ------------------------------------------------------------------------------------------------------- ** Procedure Procedure Procedure ** ------------------------------------------------------------------------------------------------------- ** Calculating outputs for the tables (10 outputs) ** ** INPUTS (10) : S0, K, r, Drift, div_r, sigma, TT, dt, T_count, S_rand ** ** T_count : 0 = Timeleft fixed at time to maturity ** 1 = Timeleft declines as T increases ** ** S_rand : 0 = S is fixed (as in book) ** 1 = S is determined by a stochastic process ** (if S_rand = 0 requires global GS) ** ** OUTPUT (9) : S, d1, d2, call_del, put_del, call_p, put_p, Size, timeleft ** ** GLOBALS : if S_rand = 0 one globas required - GS ** ------------------------------------------------------------------------------------------------------- */ proc(9) = calc1(S0, K, r, Drift, div_r, sigma, TT, dt, T_count, S_rand) ; local Size, n, S, d1, d2, timeleft, t, m ; local call_del, put_del, call_p, put_p ; Size = TT/dt+1 ; S = zeros(Size,1) ; d1 = zeros(Size,1) ; d2 = zeros(Size,1) ; call_del = zeros(Size,1) ; put_del = zeros(Size,1) ; call_p = zeros(Size,1) ; put_p = zeros(Size,1) ; if T_count .== 0 ; @ T_count switch to count down the time @ timeleft = ones(Size,1) ; timeleft = timeleft*TT ; @ NOTE : THIS SWITCH ALLOWS TIMELEFT TO BE FIXED @ elseif T_count .== 1 ; timeleft = zeros(Size,1) ; m = 1 ; t = 0 ; do until m > Size ; timeleft[m,1] = TT-t ; m = m+1 ; t = t+dt ; endo ; timeleft[Size,1] = 0.00001 ; endif ; n = 1 ; S[n,1] = S0 ; d1[n,1] = (ln(S[n,1]/K)+(r-div_r+(sigma^2)/2)*(timeleft[n,1])) /(sigma*sqrt(timeleft[n,1])) ; d2[n,1] = d1[n,1]-sigma*sqrt(timeleft[n,1]) ; call_del[n,1] = cdfn(d1[n,1]) ; put_del[n,1] = call_del[n,1]-1 ; call_p[n,1] = S[n,1]*exp(-div_r*(timeleft[n,1]))*cdfn(d1[n,1]) -K*exp(-r*timeleft[n,1])*cdfn(d2[n,1]) ; put_p[n,1] = -S[n,1]+call_p[n,1]+K*exp(-r*timeleft[n,1]) ; n = 2 ; do until n > Size-1 ; if S_rand .== 1 ; S[n,1] = S[n-1,1]*(1+Drift*dt+sigma*sqrt(dt)*rndn(1,1)) ; elseif S_rand .== 0 ; S[n,1] = _GS[n,1] ; @ Note : GS is a global @ endif ; d1[n,1] = (ln(S[n,1]/K)+(r-div_r+(sigma^2)/2)*(timeleft[n,1])) /(sigma*sqrt(timeleft[n,1])) ; d2[n,1] = d1[n,1] - sigma*sqrt(timeleft[n,1]) ; call_del[n,1] = cdfn(d1[n,1]) ; put_del[n,1] = call_del[n,1]-1 ; call_p[n,1] = S[n,1]*exp(-div_r*(timeleft[n,1]))*cdfn(d1[n,1]) -K*exp(-r*timeleft[n,1])*cdfn(d2[n,1]) ; put_p[n,1] = -S[n,1]+call_p[n,1]+K*exp(-r*timeleft[n,1]) ; n = n+1 ; endo ; if S_rand .== 1 ; S[Size,1] = S[Size-1,1] * (1+Drift*dt+sigma*sqrt(dt)*rndn(1,1)) ; elseif S_rand .== 0 ; S[Size,1] = _GS[Size,1] ; @ Note : GS is a global @ endif ; d1[Size,1] = (ln(S[Size,1]/K)+(r-div_r+(sigma^2)/2)*(timeleft[Size,1])) /(sigma*sqrt(timeleft[Size,1])) ; d2[Size,1] = d1[Size,1] - sigma*sqrt(timeleft[Size,1]) ; call_del[Size,1] = cdfn(d1[Size,1]) ; put_del[Size,1] = call_del[Size,1]-1 ; call_p[Size,1] = S[Size,1]*exp(-div_r*(timeleft[Size,1])) *cdfn(d1[Size,1]) -K*exp(-r*timeleft[Size,1])*cdfn(d2[Size,1]) ; put_p[Size,1] = -S[Size,1]+call_p[Size,1]+K*exp(-r*timeleft[Size,1]) ; retp(S,d1,d2,call_del,put_del,call_p,put_p,Size,timeleft) ; endp ; end ;