FCMP Procedure

Example 2: Creating a CALL Routine and a Function

Features:

PROC FCMP statement option: OUTLIB=

OUTARGS statement

This example shows how to use PROC FCMP to create and store CALL routines and functions.

Program

proc fcmp outlib =
sasuser.exsubs.pkt1;
   subroutine calc_years(maturity, current_date, years);
      outargs years;
      years = (maturity - current_date) / 365.25;
   endsub;
   function garkhprc (type$, buysell$, amount,
                      E, t, S, rd, rf, sig);
      if buysell = "Buy" then sign = 1.;
      else do;
         if buysell = "Sell" then sign = -1.;
         else sign = .;
      end;

      if type = "Call" then
         garkhprc = sign * amount
                         * garkhptprc (E, t, S, rd, rf, sig);
      else do;
         if type = "Put" then
            garkhprc = sign * amount
                            * garkhptprc (E, t, S, rd, rf, sig);
         else garkhprc = .;
      end;
      return (garkhprc);
   endsub;
run;

Program Description

Specify the entry where the function package information is saved.The package is a three-level name.
proc fcmp outlib =
sasuser.exsubs.pkt1;
Create a function to calculate years to maturity.A generic function called CALC_YEARS is declared to calculate years to maturity from date variables that are stored as the number of days. The OUTARGS statement specifies the variable that will be updated by CALC_YEARS.
   subroutine calc_years(maturity, current_date, years);
      outargs years;
      years = (maturity - current_date) / 365.25;
   endsub;
Create a function for Garman-Kohlhagen pricing for FX options.A function called GARKHPRC is declared, which calculates Garman-Kohlhagen pricing for FX options. The function uses the SAS functions GARKHCLPRC and GARKHPTPRC.
   function garkhprc (type$, buysell$, amount,
                      E, t, S, rd, rf, sig);
      if buysell = "Buy" then sign = 1.;
      else do;
         if buysell = "Sell" then sign = -1.;
         else sign = .;
      end;

      if type = "Call" then
         garkhprc = sign * amount
                         * garkhptprc (E, t, S, rd, rf, sig);
      else do;
         if type = "Put" then
            garkhprc = sign * amount
                            * garkhptprc (E, t, S, rd, rf, sig);
         else garkhprc = .;
      end;
The RETURN statement returns the value of the GARKHPRC function.
      return (garkhprc);
   endsub;
Execute the FCMP procedure.The RUN statement executes the FCMP procedure.
run;

Output: Log

Output from Creating a CALL Routine and a Function

NOTE: Function garkhprc saved to sasuser.exsubs.pkt1.
NOTE: Function calc_years saved to sasuser.exsubs.pkt1.