Lindo Systems

MODEL:
SETS:      
! optonfx;
! Keywords: foreign exchange, option pricing, 
   binomial option pricing, derivative;
! Binomial option pricing model on foreign exchange:
  What is the value in $ of an option to buy one unit of
  a foreign currency at specified/strike exchange rate?
  We assume that the exchange rate can either go up 
  from one period to the next with probability PUP,
  or down with probability (1 - PUP).  ;

! No. of discrete periods to use, including time now
  ( 6 means 5 future periods);
   PERIOD /1..6/:;
ENDSETS

DATA: 
! Based on example in DeRosa(1992);
! Current exchange rate, $ per foreign unit;
   XCURR = .5893;
! Strike exchange rate, i.e., right to exchange
   $ for foreign at this rate;
   XSTRK =.58;
! Yearly interest rate in $ country;
   IRD = .0581;
! Yearly interest rate in foreign country;
   IRF = .0881;
! Years to maturity for the option;
   MATRT = .098630137; !( = 36/365);
! Yearly variance in exchange rate;
   SIG = .13;
ENDDATA
!------------------------------------------------------;
SETS:

! Generate state matrix for the DP.  STATE( S, T) may
  be entered from STATE( S, T - 1) if FX rate went down,
  or from STATE( S - 1, T - 1) if FX rate went up;
 STATE( PERIOD, PERIOD)| &1 #LE# &2:
         FXRATE,  ! There is an FX rate, and...;
         VAL;     ! a value of the option;
ENDSETS

! Compute number of periods;
   LASTP = @SIZE( PERIOD);
! Initialize the FXRATE table;
   FXRATE( 1, 1) = XCURR;
! Compute some constants;
!   To avoid warning messages when IRDIFM < 0;
   @FREE( IRDIFM);
   IRDIFM = ( IRD - IRF) * MATRT/( LASTP - 1);
   SIGMSR = SIG * (( MATRT/( LASTP - 1))^.5);
   DISF = @EXP( - IRD * MATRT/( LASTP - 1));
! The up factor;
   UPF = @EXP( IRDIFM + SIGMSR);
! The down factor;
   DNF = @EXP( IRDIFM - SIGMSR);
! Probability of an up move( assumes SIG > 0);
   PUP =  (@EXP( IRDIFM)- DNF)/( UPF - DNF);
   PDN = 1 - PUP;
! First the states where it goes down every period;
   @FOR( PERIOD( T) | T #GT# 1:
      FXRATE( 1, T) = FXRATE( 1, T - 1) * DNF);

! Now compute for all other states S, period T;
   @FOR( STATE( S, T)| T #GT# 1 #AND# S #GT# 1:
      FXRATE( S, T) = FXRATE( S - 1, T - 1) * UPF);

! Do the dynamic programing;
! Set values in the final period;
   @FOR( PERIOD( S):
     VAL( S, LASTP) = @SMAX( FXRATE( S, LASTP) - XSTRK, 0));
! and for the earlier periods;
   @FOR( STATE( S, T) | T #LT# LASTP:
      VAL( S, T) = @SMAX( FXRATE( S, T) - XSTRK,
                      DISF * ( PUP * VAL( S + 1, T + 1) +
                               PDN * VAL( S, T + 1))));

! Finally, the value of the option now;
 VALUE = VAL( 1, 1);
END