/* ** Version 01 ** Date : 20/07/2001 ** -------------------------------------------------------------------------- ** Copyright K.Cuthbertson and D. Nitzsche ** "Financial Engineering:Derivatives and Risk Manangement" - J. Wiley 2001 ** ** SWAPS ** ** Valuation of Interest Rate and Currency Swaps as in Table 14.3 and p.375 ** */ new ; cls ; format /m1/rd 12,6; output on ; screen on ; /* ofile = "c:\\kcdn\\output.out" ; output file = ^ofile reset ; */ /* " ----------------------------------------------------------- " ; " Plain Vanilla Int. Rate Swap :Initialising the Parameters " ; " ----------------------------------------------------------- " ; " " ; " No. of payments in swap (n) " ; " Time to next payment (t1 in years) " ; " Tenor=time between payments - years (tenor) " ; " LIBOR rate at last fixing date (L0 %, simple rate) " ; " FIXED Coupon rate, (rx %, simple rate) " ; " Notional Principal (Q) " ; " Spot yields (yc %, contin. comp.) " ; " ------------------------------------------------------------ " ; */ /* ------------------------------------------------------------------------ ** USER INPUT: PLAIN VANILLA INTEREST RATE SWAP ** USER MAY CHANGE FIGURES IN THE NEXT SECTION ** Data from Table 14.1 "Derivatives" -Cuthbertson/Nitzsche J.Wiley 2001 ------------------------------------------------------------------------ */ n=3 ; @ number of remaining periods in swap @ yc = { 10.0 , 10.5, 11.0 } ; @ spot yields (cont. comp.%) n-elements @ t1 = 1/4 ; @ time to 1st payment - years @ tenor = 1/2 ; @ time between swap payments - years @ L0 = 10.2 ; @ simple interest %p.a. @ rx = 8.0 ; @ simple interest %p.a. @ Q = 100 ; @ principal in the swap (e.g USD) @ /* --------------------------------------------------------------------------------- ** END OF USER INPUT: PLAIN VANILLA INTEREST RATE SWAP --------------------------------------------------------------------------------- */ Call ir_swap(n,t1,tenor,L0,rx,Q,yc) ; /* --------------------------------------------------------------------------------- ** USER INPUT: PLAIN VANILLA CURRENCY SWAP ** USER MAY CHANGE FIGURES IN THE NEXT SECTION ** Data from CHT 14, p???? "Derivatives"-Cuthbertson/Nitzsche J.Wiley 2001 --------------------------------------------------------------------------------- */ n = 3 ; @ number of remaining periods in swap @ ycd = { 9.00 , 9.00, 9.00 } ; @ domestic spot yields (cont. comp.%) n-elements @ ycf = { 8.00 , 8.00, 8.00 } ; @ foreign spot yields (cont. comp.%) n-elements @ t1 = 1 ; @ time to 1st payment - years @ tenor = 1 ; @ time between swap payments -years @ rxd = 8.0 ; @ domestic coupon rate - simple interest %p.a. @ rxf = 11.2; @ foreign coupon rate - simple interest %p.a. @ Qd = 100 ; @ domestic currency, principal in the swap @ Qf = 500 ; @ foreign currency, principal in the swap @ S = 0.22 ; @ spot rate - domestic per unit of foreign currency @ /* --------------------------------------------------------------------------------- ** END OF USER INPUT: PLAIN VANILLA CURRENCY SWAP --------------------------------------------------------------------------------- */ Call curr_swap(n,t1,tenor,rxd,rxf,Qd,Qf,S,ycd,ycf) ; /* ---------------------------------------------------------------------------------- ** Procedure: Currency Swap ** ---------------------------------------------------------------------------------- */ proc(0) = curr_swap(n,t1,tenor,rxd,rxf,Qd,Qf,S,ycd,ycf) ; local ycd,ycf,t,cxd,cxf,dd,df,zzz_d,coupon_d,couponQ_d,zzz_f,coupon_f,couponQ_f ; local Vd , Vf, Vd_f, ffx, PVfwd, Vfwd ; local i ; ycd = ycd/100 ; ycf = ycf/100 ; t = t1|zeros(n-1,1) ; cxd = Qd*(rxd/100)*tenor ; cxf = Qf*(rxf/100)*tenor ; i = 2 ; do until i > n ; t[i] = t[i-1] + tenor ; i=i+1 ; endo ; dd = exp(-ycd.*t) ; df = exp(-ycf.*t) ; zzz_d = zeros(n-1,1)|Qd ; coupon_d = cxd.*ones(n,1) ; couponQ_d = cxd.*ones(n,1) + zzz_d ; zzz_f = zeros(n-1,1)|Qf ; coupon_f = cxf.*ones(n,1) ; couponQ_f = cxf.*ones(n,1) + zzz_f ; Vd = sumc(dd.*couponQ_d) ; Vf = sumc(df.*couponQ_f) ; Vd_f = Vd-S.*Vf ; /* ---------------------------------------------------------------------------------- Using Forward FX rates ------------------------------------------------------------------------------------- */ ffx = S.*exp( (ycd-ycf).*t ); PVfwd = (couponQ_d - ffx.*couponQ_f ).* exp(-ycd.*t); Vfwd = sumc( PVfwd) ; output on ; screen on; @ --------------------------------- Print the Output ----------------------------------- @ ?; " ------------------------------------------------------------------------------------- " ; " Receive fixed domestic currency - Pay fixed foreign currency: Value of Swap " ; " ------------------------------------------------------------------------------------- " ; ?; " No. of payments in currency swap (n) " n ; " Time to next payment (t1) " t1 ; " Tenor(time between payments (tenor) " tenor ; " Fixed domestic Coupon rate, (rxd %) " rxd ; " Fixed foreign Coupon rate, (rxf %) " rxf ; " Domestic Currency Notional Principal(Qd) " Qd ; " Foreign Currency Notional Principal (Qf) " Qf ; " Domestic Spot yields (contin. comp.)(ycd)% " 100.*ycd'; " Foreign Spot yields (contin. comp.)(ycf)% " 100.*ycf'; ?; " time to remaining coupon payments = " t' ; " domestic coupons inluding Q " couponQ_d' ; " foreign coupons inluding Q " couponQ_f' ; ?; " Value domestic and foreign bond " Vd~Vf ; ?; " Value of Currency swap (synthetic bond) " Vd_f ; ?; " forward rates (domestic per unit foreign) " ; ffx ; ?; " DPV of each net cash flow (dom currency) " ; PVfwd ; ?; " Value of Currency swap (forward FX rates) " Vfwd ; endp; /* ** ---------------------------------------------------------------------------------------- ** Procedure Interest Rate Swap ** ---------------------------------------------------------------------------------------- */ proc(0) = ir_swap(n,t1,tenor,L0,rx,Q,yc) ; local yc,t,cf1,cx,d,zzz,coupon,couponQ,Vfixed,Vfloat,Vfx_float,fc,tdiff ; local fs,cf,Vfwd,Vfx_float,i ; yc = yc/100 ; t = t1|zeros(n-1,1) ; cf1 = Q*(L0/100)*tenor ; cx = Q*(rx/100)*tenor ; i = 2 ; do until i > n ; t[i] = t[i-1] + tenor ; i=i+1 ; endo ; d = exp(-yc.*t) ; zzz = zeros(n-1,1)|Q ; coupon = cx.*ones(n,1) ; couponQ = cx.*ones(n,1) + zzz ; Vfixed = sumc(d.*couponQ) ; Vfloat = (Q + cf1).*exp(-yc[1,1]*t1) ; Vfx_float = Vfixed - Vfloat ; /* -------------------------------------------------------------------------------------- Contin. comp. implied forward rates ---------------------------------------------------------------------------------------- */ fc = zeros(n-1,1) ; tdiff = zeros(n-1,1) ; i = 2 ; do until i > n ; tdiff[i-1] = t[i] - t[i-1] ; fc[i-1] = ( yc[i]*t[i] - yc[i-1]*t[i-1] )/ tdiff[i-1] ; i=i+1 ; endo ; @ ---------------------------- LIBOR (L0) and Simple forward rates -------------------- @ fs = (1/tdiff).*( exp(fc.*tdiff) - 1 ) ; fs = (L0/100)|fs ; cf = fs.*tenor.*Q ; Vfwd = sumc( (cx - cf).*d ) ; output on ; screen on; @ --------------------------------- Print the Output ----------------------------------- @ ?; " -------------------------------------------------------------------------------------- " ; " Receive fixed - Pay float: Value of Interest Rate Swap " ; " -------------------------------------------------------------------------------------- " ; ?; " No. of payments in swap (n) " n ; " Time to next payment (t1) " t1 ; " Tenor(time between payments (tenor) " tenor ; " LIBOR rate at last fixing date " L0 ; " FIXED Coupon rate, (rx %) " rx ; " Notional Principal (Q) " Q ; " Spot yields (contin. comp.) (yc)% " 100.*yc'; " Discount rates " d' ; ?; " time to remaining coupon payments = " t' ; " fixed coupons inluding Q " couponQ' ; ?; " Implied cont. comp. forward interest rates " fc' ; " Time difference for forward interest rates " tdiff' ; " Initial LIBOR and Simple forward rates " fs'; " Fixed coupons in int. rate. swap " coupon' ; " "; " Vfixed and Vfloat of int. rate swap " Vfixed~Vfloat ; " Value of int. rate swap (synthetic bond) " Vfx_float ; " Value of int. rate swap (using forward int.rates) " Vfwd ; endp; end ;