    PROGRAM s30jafe

!      S30JAF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : nag_wp, s30jaf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: jvol, lambda, r, s, sigma
       INTEGER                         :: i, ifail, j, ldp, m, n
       CHARACTER (1)                   :: calput
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: p(:,:), t(:), x(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'S30JAF Example Program Results'

!      Skip heading in data file
       READ (nin,*)

       READ (nin,*) calput
       READ (nin,*) lambda
       READ (nin,*) s, sigma, r, jvol
       READ (nin,*) m, n

       ldp = m
       ALLOCATE (p(ldp,n),t(n),x(m))

       READ (nin,*) (x(i),i=1,m)
       READ (nin,*) (t(i),i=1,n)

       ifail = 0
       CALL s30jaf(calput,m,n,x,s,t,sigma,r,lambda,jvol,p,ldp,ifail)

       WRITE (nout,*)
       WRITE (nout,*) 'Merton Jump-Diffusion Model'

       SELECT CASE (calput)
       CASE ('C','c')
          WRITE (nout,*) 'European Call :'
       CASE ('P','p')
          WRITE (nout,*) 'European Put :'
       END SELECT

       WRITE (nout,99998) '  Spot       = ', s
       WRITE (nout,99998) '  Volatility = ', sigma
       WRITE (nout,99998) '  Rate       = ', r
       WRITE (nout,99998) '  Jumps      = ', lambda
       WRITE (nout,99998) '  Jump vol   = ', jvol

       WRITE (nout,*)
       WRITE (nout,*) '   Strike    Expiry    Option Price'

       DO i = 1, m

          DO j = 1, n
             WRITE (nout,99999) x(i), t(j), p(i,j)
          END DO

       END DO

99999  FORMAT (1X,2(F9.4,1X),6X,F9.4)
99998  FORMAT (A,1X,F8.4)
    END PROGRAM s30jafe
