/***************************************************************************************************************** SAS file name: Black_Scholes.sas File location: _________________________________________________________________________________________________________________ Purpose: Calculate Black-Scholes-Merton Put/Call prices Author: Peter Clemmensen Creation Date: 01/05/2016 Example Call: Call_Price = BS(100, 110, 0.05, 1, 0.2, 'C'); Equivalent to the assignment from the SAS function Call_Price = blkshclprc(110, 1, 100, 0.05, 0.2); This program supports the blog post "Black Scholes pricing in SAS" on SASnrd.com *****************************************************************************************************************/ proc iml; start BS(S, K, r, T, sigma, putcall); if upcase(putcall) not in ('C','P') then print ('Invalid Put/Call input'); /* Handle invalid Put/Call input */ d1 = (log(S/K) + (r + sigma##2/2)*T)/(sigma*sqrt(T)); /* Calculate d1 */ d2 = d1 - sigma * sqrt(T); /* Calculate d2 */ if upcase(putcall) = 'C' then price = S*cdf('normal', d1) - K*exp(-r*T)*cdf('normal', d2); /* Calculate BS Call Price */ else if upcase(putcall) = 'P' then price = K*exp(-r*T) * cdf('normal', -d2) - S*cdf('normal', -d1); /* Calculate BS Put Price */ return price; /* Return BS Price */ finish BS; Call_Price = BS(100, 110, 0.05, 1, 0.2, 'C'); print Call_Price; quit; /* Calculate Call Price in a Datastep */ data _null_; Call_Price = blkshclprc(110, 1, 100, 0.05, 0.2); put Call_Price; run;