/* ** Version 01 ** Date : 20/07/2001 ** -------------------------------------------------------------------------- ** Copyright K.Cuthbertson and D. Nitzsche ** "Financial Engineering:Derivatives and Risk Manangement" - J. Wiley 2001 ** ** OPTION SPREADS AND STOCK OPTIONS ** ** Option payoff profiles (at expiry and before). ** */ new ; cls ; @ ==== next 2 statements required for GAUSS graphs ==== @ library gauss pgraph ; graphset ; /* ofile = "c:\\kcdn\\output.out" ; output file = ^ofile reset ; */ format /m1/rdn 16,8 ; output off ; screen off ; " ------------------------------------------------------------ " ; " " ; " Definitions of Variables Used " ; " ----------------------------- " ; " " ; " " ; " K = Strike price " ; " " ; " LONG_SHORT = indicate whether you go long or short in the " ; " first option " ; " Choose either 'long' or 'short' " ; " " ; " OPTION = indicate wethre the option is a call or put " ; " option " ; " Choose either 'c_option' or 'p_option' " ; " " ; " T = Time to maturity of option " ; " (Default : 1 - expiry) " ; " " ; " r = Current interest rates " ; " (Default : 0.1 - 10%) " ; " " ; " sigma = Volatility of underlying asset " ; " (Default : 0.2 - 20%) " ; " " ; " Graph_Start = Starting value for plotting the graph " ; " (Default : K - 20) " ; " " ; " ------------------------------------------------------------ " ; /* ------------------------------ START USER DATA INPUT ---------------------------- */ K = 120 ; LONG_SHORT = "short" ; @ Note : use either "long" or "short" here @ OPTION = "c_option" ; @ Note : use either "c_option" or "p_option" here @ T = 1 ; r = 0.1 ; sigma = 0.2 ; Graph_Start = K-20 ; @ This parameter sets the starting point of the graph @ /* -------------------------- END USER DATA INPUT ----------------------------------- */ /* ------------------------ STARTING THE CALCULATION -------------------------------- */ S0 = K ; if OPTION $== "c_option" ; {Premium} = bscall(K,S0,sigma,T,r); elseif OPTION $== "p_option" ; {Premium} = bsput(K,S0,sigma,T,r); endif ; if Graph_Start <= 0 ; Graph_Start = 1 ; endif ; Graph_End = 2*(K-Graph_Start) + 1 ; if K > 25 ; Step = 1 ; ST = seqa(Graph_Start, Step, Graph_End) ; elseif K > 10 ; Step = 0.5 ; ST = seqa(Graph_Start, Step, 2*Graph_End) ; else ; Step = 0.1 ; ST = seqa(Graph_Start, Step, 10*Graph_End) ; endif ; n = rows(ST) ; Zeroline = zeros(n,1) ; @ Creating the Zero Line for graph @ KK = zeros(n,1) ; KK = K ; ssigma = zeros(n,1) ; ssigma = sigma ; rr = zeros(n,1) ; rr = r ; TT = zeros(n,1) ; TT = T ; PayOff = zeros(n,1) ; /* ----------------------------- Calculating Payoff Profile --------------------- */ /* ---------------------------- for different S ---------------------- */ if OPTION $== "c_option" ; {PO_T} = bscall(KK,ST,ssigma,TT,rr); Opt_long = ST-K ; @ Call payoff @ i = 1 ; do until i > n ; if Opt_long[i,.] > 0 ; PayOff[i,.] = Opt_long[i,.] ; else ; PayOff[i,.] = 0 ; endif ; i = i+1 ; endo ; if long_short $== "long" ; @ dn new @ PayOff = PayOff - Premium ; else ; @ Here Short now @ PayOff = -PayOff + Premium ; endif ; elseif OPTION $== "p_option" ; {PO_T} = bsput(KK,ST,ssigma,TT,rr); Opt_long = K-ST ; @ Put payoff @ i = 1 ; do until i > n ; if Opt_long[i,.] > 0 ; PayOff[i,.] = Opt_long[i,.] ; else ; PayOff[i,.] = 0 ; endif ; i = i+1 ; endo ; if long_short $== "long" ; @ dn new @ PayOff = PayOff - Premium ; else ; @ Here Short now @ PayOff = -PayOff + Premium ; endif ; endif ; if LONG_SHORT $== "short" ; PO_T = -PO_T ; endif ; if OPTION $== "c_option" ; @ Calculating the break even points @ SBE = K + Premium ; elseif OPTION $== "p_option" ; SBE = K - Premium ; endif ; /* -------------------------- Printing Output and the Graph ----------------- */ output on; screen on ; @@ "" ; " ------------------------------------------------------------------------ " ; " " ; " FILE : Chp10 Single Payoff.txt " ; " ============================== " ; " " ; " Version 20/07/2001 " ; " " ; " Copyright K.Cuthbertson and D. Nitzsche " ; " 'Financial Engineering:Derivatives and Risk Manangement' - J. Wiley 2001 " ; " " ; " OPTION SPREADS AND STOCK OPTIONS " ; " Ploting payoff Profile for single option " ; " " ; " ------------------------------------------------------------------------ " ; @@ "" ; @@ "" ; @@ " Parameter Inputs " ; @@ " ================ " ; @@ "" ; @@ ftos(K,"Strike Price of Option : %*.*lf",25,2) ; @@ "" ; @@ ftos(Premium,"Option Premium as calculated using BS : %*.*lf",10,2) ; @@ "" ; @@ ftos(T,"Time to expiry : %*.*lf",33,2) ; @@ ftos(r,"Current interest rates : %*.*lf",25,2) ; @@ ftos(sigma,"Volatility : %*.*lf",37,2) ; @@ "" ; @@ "" ; @@ "" ; if OPTION $== "c_option" ; if LONG_SHORT $== "long" ; @@ " The payoff diagram shows a LONG CALL " ; @@ " ==================================== " ; @@ "" ; elseif LONG_SHORT $== "short" ; @@ " The payoff diagram shows a SHORT CALL " ; @@ " ===================================== " ; @@ "" ; endif ; elseif OPTION $== "p_option" ; if LONG_SHORT $== "long" ; @@ " The payoff diagram shows a LONG PUT " ; @@ " =================================== " ; @@ "" ; elseif LONG_SHORT $== "short" ; @@ " The payoff diagram shows a SHORT PUT " ; @@ " ==================================== " ; @@ "" ; endif ; endif ; @@ ftos(S0,"Stock Price used for BS premium calculations : %*.*lf",9,2) ; @@ "" ; @@ ftos(Premium,"BS option premium (call or put) : %*.*lf",22,2) ; @@ "" ; @@ ftos(SBE,"Break even stock price : %*.*lf",31,2) ; @@ "" ; title("Payoff profile of a single option") ; xy (ST,PayOff~PO_T~Zeroline) ; /* ----------------------------------- END OF PROGRAM --------------------------- */ /* --------------------------------------------------------------------------- */ /* BS Call and Put Procedures */ /* -------------------------------------------------------------------------- */ proc bscall(k,s,sigma,tau,r); local d1,d2,c; d2=(ln(s./(k.*exp(-r.*tau))))./(sigma.*sqrt(tau))-0.5*sigma.*sqrt(tau); d1=d2+sigma.*sqrt(tau); c=s.*cdfn(d1)-k.*exp(-r.*tau).*cdfn(d2); retp(c); endp; proc bsput(k,s,sigma,tau,r); local d1,d2,p; d2=(ln(s./(k.*exp(-r.*tau))))./(sigma.*sqrt(tau))-0.5*sigma.*sqrt(tau); d1=d2+sigma.*sqrt(tau); p=-s.*cdfn(-d1)+k.*exp(-r.*tau).*cdfn(-d2); retp(p); endp; end ;