Example description
    Program s30nbfe

!     S30NBF Example Program Text

!     Mark 27.0 Release. NAG Copyright 2019.

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

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

      Read (nin,*) calput
      Read (nin,*) s, r, q
      Read (nin,*) kappa, eta, var0, sigmav, corr, grisk
      Read (nin,*) m, n

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

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

      ifail = 0
      Call s30nbf(calput,m,n,x,s,t,sigmav,kappa,corr,var0,eta,grisk,r,q,p,ldp, &
        delta,gamma,vega,theta,rho,vanna,charm,speed,zomma,vomma,ifail)

      Write (nout,*)
      Write (nout,*) 'Heston''s Stochastic volatility Model'

      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 of vol      = ', sigmav
      Write (nout,99997) '  Mean reversion         = ', kappa
      Write (nout,99997) '  Correlation            = ', corr
      Write (nout,99997) '  Variance               = ', var0
      Write (nout,99997) '  Mean of variance       = ', eta
      Write (nout,99997) '  Risk aversion          = ', grisk
      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,*)                                                         &
          '  Strike       Price      Delta      Gamma      Vega       ' //     &
          'Theta      Rho'

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

        Write (nout,*)                                                         &
          '  Strike       Price      Vanna      Charm      Speed      ' //     &
          'Zomma      Vomma'

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

      End Do

99999 Format (1X,'Time to Expiry : ',1X,F8.4)
99998 Format (1X,7(F10.4,1X))
99997 Format (A,1X,F10.4)
    End Program s30nbfe