NAG Library Manual, Mark 27.3
Interfaces:  FL   CL   CPP   AD 

NAG FL Interface Introduction
Example description
    Program s30bbfe

!     S30BBF Example Program Text

!     Mark 27.3 Release. NAG Copyright 2021.

!     .. Use Statements ..
      Use nag_library, Only: nag_wp, s30bbf
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: q, r, s, sigma
      Integer                          :: i, ifail, j, ldp, m, n
      Character (1)                    :: calput
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: charm(:,:), colour(:,:), crho(:,:),  &
                                          delta(:,:), gamma(:,:), p(:,:),      &
                                          rho(:,:), sm(:), speed(:,:), t(:),   &
                                          theta(:,:), vanna(:,:), vega(:,:),   &
                                          vomma(:,:), zomma(:,:)
!     .. Executable Statements ..
      Write (nout,*) 'S30BBF Example Program Results'

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

      Read (nin,*) calput
      Read (nin,*) s, sigma, r, q
      Read (nin,*) m, n

      ldp = m
      Allocate (charm(ldp,n),colour(ldp,n),crho(ldp,n),delta(ldp,n),           &
        gamma(ldp,n),p(ldp,n),rho(ldp,n),sm(m),speed(ldp,n),t(n),theta(ldp,n), &
        vanna(ldp,n),vega(ldp,n),vomma(ldp,n),zomma(ldp,n))

      Read (nin,*)(sm(i),i=1,m)
      Read (nin,*)(t(i),i=1,n)

      ifail = 0
      Call s30bbf(calput,m,n,sm,s,t,sigma,r,q,p,ldp,delta,gamma,vega,theta,    &
        rho,crho,vanna,charm,speed,colour,zomma,vomma,ifail)

      Write (nout,*)
      Write (nout,*) 'Floating-Strike Lookback'

      Select Case (calput)
      Case ('C','c')
        Write (nout,*) 'European Call :'
      Case ('P','p')
        Write (nout,*) 'European Put :'
      End Select

      Write (nout,99997) '  Spot       = ', s
      Write (nout,99997) '  Volatility = ', sigma
      Write (nout,99997) '  Rate       = ', r
      Write (nout,99997) '  Dividend   = ', q

      Write (nout,*)

      Do j = 1, n
        Write (nout,*)
        Write (nout,99999) t(j)
        Write (nout,*) 'S-Max/Min     Price     Delta     Gamma' //            &
          '      Vega      Theta      Rho      CRho'

        Do i = 1, m
          Write (nout,99998) sm(i), p(i,j), delta(i,j), gamma(i,j), vega(i,j), &
            theta(i,j), rho(i,j), crho(i,j)
        End Do

        Write (nout,*) 'S-Max/Min     Price     Vanna     Charm' //            &
          '     Speed     Colour    Zomma     Vomma'

        Do i = 1, m
          Write (nout,99998) sm(i), p(i,j), vanna(i,j), charm(i,j),            &
            speed(i,j), colour(i,j), zomma(i,j), vomma(i,j)
        End Do

      End Do

99999 Format (1X,'Time to Expiry : ',1X,F8.4)
99998 Format (8(1X,F9.4))
99997 Format (A,1X,F8.4)
    End Program s30bbfe