!!----------------------------------------------------------------------------
!! $Id: calcpayoff.f90,v 1.8 1997/11/12 02:03:48 svmcguir Exp $
!! subroutine calculate_payoff(max_params,params,stockprice,payoff)
!!    This subroutine will take in the stock price and interest rate, etc.
!!    to determine the payoff function
!!    will have the payoffs
!!    Author: Scott A. Klasky
!!    Date  : 10/19/97
!!----------------------------------------------------------------------------
subroutine calculate_payoff(max_params,params,stockprice,payoff)
use PATHS
use input_params
implicit none

integer,intent(IN)                       :: max_params
real*8,dimension(max_params),intent(IN)  :: params
real*8,dimension(:,:),intent(IN)         :: stockprice
real*8,dimension(:,:),intent(OUT)        :: payoff

integer                                  :: i,j
integer                                  :: ntime
real*8                                   :: time

   ntime = int(params(P_NTIME))
   do j = 1, int(params(P_NPATH))
      do i = 1, ntime 
         time = -1.0d0*(i-1)/12.0d0
         payoff(i,j) = max(0.0d0,(params(P_STRIKE)-stockprice(i,j))* &
              exp(params(P_RATE)*time))
      end do !i
   end do !j

return
end subroutine calculate_payoff

