Search code examples
sastradingvolatility

SAS: Calculating multiple Implied Volatilities for dataset of options


I want to calculate daily the implied volatility for a data set of option chains. I have all necessary data in a dataset with the columns:

OptionID opt_price strike today exp eq_price intrate

The SAS code for the IV is:

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;

Source: https://documentation.sas.com/?docsetId=proc&docsetTarget=p1xoknqns865t7n1wehj6xarwhdb.htm&docsetVersion=9.4&locale=en#p0ymk0vrf7cecfn1kec073rxqm7z

Now, this function somehow does not need sigma. Why?

Second, how can I feed in and output a dataset with option series for a few years? I tried by optionID but I don't know how I feed in the data correctly and then add it in a dataset (new variable called bsvolty.


Solution

  • Use the FCMP options DATA= and OUT= to provide inputs and capture outputs.

    As for the missing value (.) in the sigma argument position, the SOLVE documentation states:

    The SOLVE function finds the value of the specified argument that makes the expression of the following form equal to zero.

    • expected-value -
      function-name
      (argument-1,argument-2,
      ..., argument-n)

    You specify the argument of interest with a missing value (.), which appears in place of the argument in the parameter list that is shown above. If the SOLVE function finds the value, then the value that is returned for this function is the implied value.

    So, the SOLVE() is for the blkshclprc sigma (i.e. the volatilty)

    Example code:

    data have;
    input OptionID opt_price strike today: date9. exp: date9. eq_price intrate;
    format today exp date9.;
    datalines;
    1 5 50 20jul2010 21oct2010  50 0.05
    2 5 75 21jul2010 22oct2010  50 0.05
    3 5 55 22jul2010 23oct2010  50 0.05
    4 5 60 23jul2010 24oct2010  50 0.05
    ;
    
    proc fcmp data=have out=want;
    
      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);
    
        put volty=;  /* show the SOLVE iterations in the OUTPUT window */
    
        return ( blkshclprc ( 
          strike,       /* E: exercise prices */
          time/365.25,  /* t: time to maturity (years) */
          eq_price,     /* S: share price */
          intrate,      /* r: annualized risk-free interest rate, continuouslycompounded */
          volty         /* sigma: volatility of the underlying asset */
        ));
      endsub;
    
      bsvolty=solve("blksch", opts, opt_price, strike,
                               time, eq_price, intrate, .);
    run;
    

    The output data set
    enter image description here

    The OUTPUT window
    enter image description here