Chapter 18: Random Number Generation

RNMVTC

Given a Cholesky factorization of a correlation matrix, generates pseudorandom numbers from a Student’s t Copula distribution.

Required Arguments

DF — Degrees of freedom.   (Input)
DF must be greater than 2.

CHOL — Array of size n by n containing the upper-triangular Cholesky factorization of the correlation matrix of order n.   (Input)

R — Array of length n containing the pseudorandom numbers from a multivariate a Student’s t Copula distribution.   (Output)

FORTRAN 90 Interface

Generic:                              RNMVTC (DF, CHOL, R)

Specific:                             The specific interface names are S_RNMVTC and D_RNMVTC.

Description

RNMVTC generates pseudorandom numbers from a multivariate Student’s t Copula distribution which are uniformly distributed on the interval (0,1) representing the probabilities associated with Student’s t deviates with DF degrees of freedom imprinted with correlation information from input upper-triangular Cholesky matrix CHOL. Cholesky matrix CHOL is defined as the “square root” of a user-defined correlation matrix. That is, CHOL is an upper triangular matrix such that the transpose of CHOL times CHOL is the correlation matrix.  First, a length n array of independent random normal deviates with mean 0 and variance 1 is generated, and then this deviate array is post-multiplied by Cholesky matrix CHOL. Each of the n elements of the resulting vector of Cholesky-imprinted random deviates is then divided by, where = DF and s is a random deviate taken from a chi-squared distribution with DF degrees of freedom.  Each element of the Cholesky-imprinted standard normal N(0,1) array is a linear combination of normally distributed random numbers and is therefore itself normal, and the division of each element by  therefore insures that each element of the resulting array is Student’s t distributed.  Finally, each element of the Cholesky-imprinted Student’s t array is mapped to an output probability using the Student’s t cumulative distribution function (CDF) with DF degrees of freedom.

Random deviates from arbitrary marginal distributions which are imprinted with the correlation information contained in Cholesky matrix CHOL can then be generated by inverting the output probabilities using user-specified inverse CDF functions.

Example: Using Student’s t Copulas to Imprint and Extract Correlation Information

This example uses RNMVTC to generate a multivariate sequence tcdevt whose marginal distributions are user-defined and imprinted with a user-specified input correlation matrix corrin and then uses CANCOR to extract an output canonical correlation matrix  corrout from this multivariate random sequence.

This example illustrates two useful copula related procedures. The first procedure generates a random multivariate sequence with arbitrary user-defined marginal deviates whose dependence is specified by a user-defined correlation matrix. The second procedure is the inverse of the first: an arbitrary multivariate deviate input sequence is first mapped to a corresponding sequence of empirically derived variates, i.e. cumulative distribution function values representing the probability that each random variable has a value less than or equal to the input deviate. The variates are then inverted, using the inverse standard normal CDF function, to N(0,1) deviates; and finally, a canonical covariance matrix is extracted from the multivariate N(0,1) sequence using the standard sum of products.

This example demonstrates that subroutine RNMVTC correctly imbeds the user-defined correlation information into an arbitrary marginal distribution sequence by extracting the canonical correlation from these sequences and showing that they differ from the original correlation matrix by a small relative error.

Recall that a Gaussian Copula array sequence, whose probabilities are mapped directly from Cholesky-imprinted N(0,1) deviates, has the property that the relative error between the input and output correlation matrices generally decreases as the number of multivariate sequence vectors increases.  This is understandable because the correlation imprinting and extraction processes both act upon N(0,1) marginal distributions, and one would expect that a larger sample would therefore result in more accurate imprinting and extraction of correlation information.

In contrast, the imprinting of correlation information onto Student’s t vector sequence is accomplished by imprinting onto an N(0,1) array and then dividing the array components by a scaled chi-squared random deviate, thereby introducing noise into the imprinting process.  (An array of Student’s t deviates cannot be Cholesky-imprinted directly, because a linear combination of Student’s t deviates is not Student’s t distributed.)  A larger sample would thus contain additional correlation information and additional noise, so the accuracy would be expected to plateau.  This is illustrated in the following example, which should be compared with the Gaussian Copula example given for FNL routine RNMVGC.

 

      use rnmvtc_int

      use cancor_int

      use anorin_int

      use chiin_int

      use fin_int

      use amach_int

      use rnopt_int

      use rnset_int

      use umach_int

      use chfac_int

      implicit none

 

      integer, parameter:: lmax=15000, nvar=3

      real corrin(nvar,nvar), tol, chol(nvar,nvar), &

         tcvart(nvar), tcdevt(lmax,nvar), corrout(nvar,nvar), &

         relerr, df

      integer irank, k, kmax, kk, i, j, nout

 

      data corrin /&

        1.0, -0.9486832, 0.8164965, &

        -0.9486832, 1.0, -0.6454972, &

        0.8164965, -0.6454972,  1.0/

     

      call umach (2, nout)

 

      write(nout,*) "Off-diagonal Elements of Input " // &

         "Correlation Matrix: "

      write(nout,*)

 

      do i = 2, nvar

         do j = 1, i-1

            write(nout,'(" CorrIn(",i2,",",i2,") = ", f10.6)') &

               i, j, corrin(i,j)

         end do

      end do

 

      df = 5.0

      write(nout,'(/" Degrees of freedom df = ", f6.2/)') df

      write(nout,*) "Imprinted random sequences distributions:"

      write(nout,*) "1: Chi, 2: F, 3: Normal:"

 

      write(nout,*)

      write(nout,*) "Off-diagonal Elements of Output Correlation " //&

         "Matrices calculated from"

      write(nout,*) "Student's t Copula imprinted multivariate sequence:"

 

!     Compute the Cholesky factorization of CORRIN.

      tol=amach(4)

      tol=100.0*tol

      call chfac (corrin, irank, chol, tol=tol)

 

      kmax = lmax/100

      do kk = 1, 3

         write (nout, '(/" # vectors in multivariate sequence:  ", &

             i7/)') kmax

 

         call rnopt(1)

         call rnset (123457)

 

         do k = 1, kmax

!     Generate an array of Gaussian Copula random numbers.

            call rnmvtc (df, chol, tcvart)

 

            do j = 1, nvar

!     Invert Student's t Copula probabilities to deviates.

 

               if (j .eq. 1) then

!     ChiSquare(df=10) deviates:

                    tcdevt(k, j) = chiin(tcvart(j), 10.e0)

               else if (j .eq. 2) then

!     F(dfn=15,dfd=10) deviates:

                    tcdevt(k, j) = fin(tcvart(j), 15.e0, 10.e0)

               else

!     Normal(mean=0,variance=1) deviates:

                    tcdevt(k, j) = anorin(tcvart(j))

               end if

            end do

         end do

!     Extract Canonical Correlation matrix.

         call cancor (tcdevt(:kmax,:), corrout)

 

         do i = 2, nvar

            do j = 1, i-1

               relerr = abs(1.0 - (corrout(i,j) / corrin(i,j)))

               write(nout,'(" CorrOut(",i2,",",i2,") = ",&

                 f10.6, "; relerr = ", f10.6)')&

                 i, j, corrout(i,j), relerr

            end do

         end do

         kmax = kmax*10

      end do

      end

Output

 

 Off-diagonal Elements of Input Correlation Matrix:

 

 CorrIn( 2, 1) =  -0.948683

 CorrIn( 3, 1) =   0.816496

 CorrIn( 3, 2) =  -0.645497

 

 Degrees of freedom df =   5.00

 

 Imprinted random sequences distributions:

 1: Chi, 2: F, 3: Normal:

 

 Off-diagonal Elements of Output Correlation Matrices calculated from

 Student's t Copula imprinted multivariate sequence:

 

 # vectors in multivariate sequence:      150

 

 CorrOut( 2, 1) =  -0.953573; relerr =   0.005154

 CorrOut( 3, 1) =   0.774720; relerr =   0.051166

 CorrOut( 3, 2) =  -0.621419; relerr =   0.037302

 

 # vectors in multivariate sequence:     1500

 

 CorrOut( 2, 1) =  -0.944316; relerr =   0.004603

 CorrOut( 3, 1) =   0.810163; relerr =   0.007757

 CorrOut( 3, 2) =  -0.636348; relerr =   0.014174

 

 # vectors in multivariate sequence:    15000

 

 CorrOut( 2, 1) =  -0.946770; relerr =   0.002017

 CorrOut( 3, 1) =   0.808562; relerr =   0.009718

 CorrOut( 3, 2) =  -0.636322; relerr =   0.014215



http://www.vni.com/
PHONE: 713.784.3131
FAX:713.781.9260