| Category: | Compute Implicit Values |
| Note: | This special purpose function is automatically provided by the FCMP procedure for convenience. |
proc fcmp;
function garkhprc(type$, buysell$, amount, E, t, S, rd, rf, sig)
kind=pricing label='FX option pricing';
if buysell='Buy' then sign=1.;
else do;
if buysell='Sell' then sign=-1.;
else sign=.;
end;
if type='Call' then
garkhprc=sign*amount*(E+t+S+rd+rf+sig);
else do;
if type='Put' then
garkhprc=sign*amount*(E+t+S+rd+rf+sig);
else garkhprc=.;
end;
return(garkhprc);
endsub;
subroutine gkimpvol(n, premium[*], typeflag[*], amt_lc[*],
strike[*], matdate[*], valudate, xrate,
rd, rf, sigma);
outargs sigma;
array solvopts[1] initial (0.20);
sigma = 0;
do i = 1 to n;
maturity = (matdate[i] - valudate) / 365.25;
stk_opt = 1./strike[i];
amt_opt = amt_lc[i] * strike[i];
price = premium[i] * amt_lc[i];
if typeflag[i] eq 0 then type = "Call";
if typeflag[i] eq 1 then type = "Put";
/* solve for volatility */
sigma = sigma + solve("GARKHPRC", solvopts, price,
type, "Buy", amt_opt, stk_opt,
maturity, xrate, rd, rf, .);
end;
sigma = sigma / n;
endsub;
run;options pageno=1 nodate ls=80 ps=64;
proc fcmp;
opt_price = 5;
strike = 50;
today = '20jul2010'd;
exp = '21oct2010'd;
eq_price = 50;
intrate = .05;
time = exp - today;
array opts[5] initial abconv relconv maxiter status
(.5 .001 1.0e-6 100 -1);
function blksch(strike, time, eq_price, intrate, volty);
return(blkshclprc(strike, time/365.25,
eq_price, intrate, volty));
endsub;
bsvolty = solve("blksch", opts, opt_price, strike,
time, eq_price, intrate, .);
put 'Option Implied Volatility:' bsvolty
'Initial value: ' opts[1]
'Solve status: ' opts[5];
run;