Portfolio simulation: robust versus classical statistics

Một phần của tài liệu Financial risk modelling and portfolio optimization with r second edition (Trang 191 - 197)

In this first empirical application a simulation comparing classical and robust estima- tors will be conducted. Returns for five fictional assets will be randomly generated according to one of the following data-generating processes (DGPs):

•Gauss copula with normally distributed margins

•Gauss copula witht-distributed margins

•Student’stcopula witht-distributed margins.

The first DGP corresponds to the case where the classical estimators are the best linear unbiased estimators for the Gauss copula with normal margins; the other two DGPs reflect the stylized facts of financial market returns, namely excess kurtosis and tail dependence. For thetdistribution five degrees of freedom have been chosen, and the sample sizes for all DGPs are 60, 120, and 240 observations. Assuming a monthly frequency, this corresponds to a 5-, 10-, and 20-year time span for the data in each of the portfolio optimizations. For each DGP a set of 1000 samples has been generated. An equally correlated dependence structure between the five assets has been assumed with a value of𝜌=0.5. The generation of these random samples is shown in Listing 10.1.

First, the required packages are loaded into the workspace. The random samples are generated by functions contained in the packagecopula(see Section 9.4.2). Next, copula objects for the Gauss and Student’stcopula are created and namedncopand tcop, respectively. The DGPs are created by utilizing the functionmvdc(). This requires an object of class copulaand alist object that contains the parame- ter information about the marginal distributions assumed. The objects are labeled NcopMargN,NcopMargT, andTcopMargTfor the three multivariate distribution models.

k k Rcode 10.1Portfolio simulation: data generation.

# # L o a d i n g o f p a c k a g e s 1

l i b r a r y ( c c c p ) 2

l i b r a r y ( c o p u l a ) 3

l i b r a r y ( r r c o v ) 4

# # C r e a t i n g c o p u l a o b j e c t s 5

ncop <− n o r m a l C o p u l a ( param = 0 . 5 , dim = 5 ) 6

t c o p <− t C o p u l a ( param = 0 . 5 , dim = 5 , d f = 5 , d f . f i x e d = TRUE) 7

# # C r e a t i n g DGPs 8

NcopMargN <− mvdc ( ncop , m a r g i n s = " norm " , 9

p a r a m M a r g i n s = l i s t ( l i s t ( mean = 0 , s d = 1 ) ) , 10

m a r g i n s I d e n t i c a l = TRUE) 11

NcopMargT <− mvdc ( ncop , m a r g i n s = " t " , 12

p a r a m M a r g i n s = l i s t ( d f = 5 ) , 13

m a r g i n s I d e n t i c a l = TRUE) 14

TcopMargT <− mvdc ( t c o p , m a r g i n s = " t " , 15

p a r a m M a r g i n s = l i s t ( d f = 5 ) , 16

m a r g i n s I d e n t i c a l = TRUE) 17

# # I n i t i a l i s i n g l i s t o b j e c t s f o r DGP 18

L o b j <− l i s t ( ) 19

l e n g t h ( L o b j ) <− 1000 20

# # S e t t i n g a s e e d 21

s e t . s e e d ( 1 2 3 4 5 ) 22

# # G e n e r a t i n g random s a m p l e s 23

rNcopMargN <− l a p p l y ( Lobj , f u n c t i o n ( x ) rMvdc ( 2 4 0 , NcopMargN ) ) 24

rNcopMargT <− l a p p l y ( Lobj , f u n c t i o n ( x ) rMvdc ( 2 4 0 , NcopMargT ) ) 25

rTcopMargT <− l a p p l y ( Lobj , f u n c t i o n ( x ) rMvdc ( 2 4 0 , TcopMargT ) ) 26

These objects are then employed to draw the random samples. In order to do so, first alistobject,Lobj, is created and the size of the simulation is assigned as its length.

Second, a seed is set for replication purposes. In principle, the 1000 random samples for each of the DGPs could be assigned as list elements with aforloop, but it is more in the nature ofRto uselapply()instead. In the last three lines the list objectLobj is used for this purpose and the results are stored in the objectsrNcopMargN,rN- copMargT, andrTcopMargT. These list objects consist of 1000 samples for each of the DGPs with 240 rows and five columns for the fictional asset returns. Sample data for the shorter sample spans can then be swiftly extracted from the list elements.

As the next step, a function is created that returns the dispersion estimates for the classical and robust methods. This function can then be applied for the simulated data sets for each of the DGPs and then used for optimizing the minimum-variance portfo- lios. The comparative simulation will encompass the classical estimators and the M-, MM, S-, MCD, MVE, SD, and OGK robust estimators. The function specification is shown in Listing 10.2, where the estimators of therrcovpackage are used.

The function is specified with three arguments. The first,x, is used for the random data set, the second for determining what kind of estimator is employed, and the

k k Rcode 10.2Portfolio simulation: function for estimating moments.

# # F u n c t i o n f o r Moment E s t i m a t i o n 1

Moments <− f u n c t i o n ( x , method = c ( " C o v C l a s s i c " , " CovMcd " , 2

" CovMest " , " CovMMest " , " CovMve " , " CovOgk " , 3

" CovSde " , " C o v S e s t " ) , . . . ) { 4

method <− m a t c h . a r g ( method ) 5

a n s <− do . c a l l ( method , l i s t ( x = x , . . . ) ) 6

r e t u r n ( g e t C o v ( a n s ) ) 7

} 8

Rcode 10.3Portfolio simulation: estimates for data processes.

# # D i m e n s i o n s o f S i m u l a t i o n 1

DGP <− c ( " rNcopMargN " , " rNcopMargT " , " rTcopMargT " ) 2

EST <− c ( " C o v C l a s s i c " , " CovMcd " , " CovMest " , " CovMMest " , 3

" CovMve " , " CovOgk " , " CovSde " , " C o v S e s t " ) 4

SAMPLE <− c ( 6 0 , 1 2 0 , 2 4 0 ) 5

# # C r e a t i n g l i s t o b j e c t s f o r c o m b i n a t i o n s o f 6

# # DGP and s a m p l e s i z e s 7

# # i n i t i a l i s i n g v e c t o r f o r d a t a o b j e c t s 8

d a t n a m e s <− NULL 9

f o r ( i i n DGP) { 10

f o r ( j i n SAMPLE) { 11

o b j n a m e <− p a s t e ( i , j , s e p = " " ) 12

d a t n a m e s <− c ( d a t n a m e s , o b j n a m e ) 13

c a t ( p a s t e ( " C r e a t i n g l i s t o b j e c t " , objname , " \ n " ) ) 14

a s s i g n ( objname , l a p p l y ( e v a l ( a s . name ( i ) ) , 15

f u n c t i o n ( x ) x [ 1 : j , ] ) ) 16

} 17

} 18

# # C r e a t i n g l i s t o b j e c t s w i t h e s t i m a t e s o f 19

# # l o c a t i o n and d i s p e r s i o n f o r c o m b i n a t i o n s o f 20

# # DGP, s a m p l e s i z e s and e s t i m a t o r s 21

# # i n i t i a l i s i n g v e c t o r f o r l i s t o b j e c t s 22

o b j n a m e s <− NULL 23

f o r ( i i n d a t n a m e s ) { 24

f o r ( j i n EST ) { 25

o b j n a m e <− p a s t e ( j , i , s e p = " " ) 26

o b j n a m e s <− c ( o b j n a m e s , o b j n a m e ) 27

c a t ( p a s t e ( " C r e a t i n g l i s t o b j e c t " , objname , " \ n " ) ) 28

a s s i g n ( objname , l a p p l y ( e v a l ( a s . name ( i ) ) , Moments , 29

method = j ) ) 30

} 31

} 32

k k third is the ellipsis argument that is passed down todo.call()so that the user has

command of the arguments of the estimating function. In the first line of the function body, partial matching for the name of the estimating function is included. In the second line, the function determined by the argumentmethodis applied to the data setx. Finally, the estimate is extracted from the objectansby means of the access functiongetCov()and its result is returned.

This function can now be used to estimate the second moment for each of the list elements and for each of the DGPs and sample sizes. Listing 10.3 shows how this task can be swiftly accomplished. First, the dimension of the simulation study is defined:

there are three models for the multivariate distributions,DGP. Theselistobjects were created in Listing 10.1. Each list object contains 1000 elements in the form of (240×5)matrices. Next, the function names of the estimators to be used are collected in the character vectorEST. Finally, the sample sizes are set in the numeric vector SAMPLE. In the ensuing code section the samples of different sizes are created. In the first doubleforloop, the object names are created and displayed by thecat()func- tion so that the user can better track the progress of the loop. In addition, the names of these list objects are saved in the vectordatnamesfor use in the secondforloop construction. In the last line,lapply()is used to extract for eachlistelement and for each DGP the number of rows according toSAMPLE. Thus, after the execution of the loop has finished, nine newlistobjects have been created. With these data sets at hand, one can now proceed and estimate the moments for each single list element.

This is done in the second doubleforloop. First, the names of the list objects that will store the estimates for the mean and covariance are created, and these names are displayed to enable progress monitoring when theforloop is executed. Similar to the first loop, the names of these objects are saved in the character vectorobjnames.

In the final line,lapply()is used to apply the functionMoments()to eachlist element for each of the DGPs and sample sizes. After the successful completion of this loop, a total of 3×3×8=72listobjects have been created and each contains a dispersion estimate. The portfolio optimizations are then conducted with respect to these 72 objects, which implies a total of 72 000 optimizations to be done.

Having created all the necessary data objects, one can proceed with the portfolio optimizations. In Listing 10.4 the functionPortMinVar()has been defined. The optimization is carried out by employing cccp() from the package cccp. The minimum-variance optimization takes place under the constraints of being fully invested (objectsa1andb1) and with only long positions allowed (objectsnno1).

The function returns the weight vector. In the ensuingforloop the optimizations are carried out and the 1000 portfolio risk figures are stored for each of the DGP, estimator, and sample size combinations. Finally, the median and interquartile range (IQR) are computed for the portfolio risks.

The simulation results are summarized in Table 10.1. The medians and interquar- tile ranges are reported in the columns for each of the three DGPs. The results are grouped by sample size. A couple of conclusions can be drawn from this table. Even in the case of the Gauss copula with normally distributed margins the classical co- variance estimator does not yield a portfolio structure of lowest risk on average, and the dispersion of the portfolio risks is also not the smallest. This result holds for all

k k Rcode 10.4Portfolio simulation: minimum-variance optimizations.

# # F u n c t i o n f o r minimumv a r i a n c e p o r t f o l i o 1

# # C o n s t r a i n t s : F u l l y i n v e s t e d , l o n go n l y 2

P o r t M i n V a r <− f u n c t i o n ( x ) { 3

k <− n c o l ( x ) 4

nno1 <− nnoc (G = −d i a g ( k ) , h = r e p ( 0 , k ) ) 5

A1 <− m a t r i x ( r e p ( 1 , k ) , nrow = 1 ) 6

b1 <− 1 . 0 7

o p t <− c c c p ( P = x , q = r e p ( 0 , k ) , A = A1 , b = b1 , 8

c L i s t = l i s t ( nno1 ) , 9

o p t c t r l = c t r l ( t r a c e = FALSE ) ) 10

g e t x ( o p t ) 11

} 12

# # C o n d u c t o p t i m i s a t i o n 13

p o r t n a m e s <− NULL 14

i d x <− 1 : 1 0 0 0 15

f o r ( i i n o b j n a m e s ) { 16

o b j n a m e <− p a s t e ( " P o r t " , i , s e p = " " ) 17

p o r t n a m e s <− c ( p o r t n a m e s , o b j n a m e ) 18

o b j <− e v a l ( a s . name ( i ) ) 19

w e i g h t s <− l a p p l y ( o b j , P o r t M i n V a r ) 20

a s s i g n ( objname , s a p p l y ( i d x , f u n c t i o n ( x ) 21

s q r t ( c r o s s p r o d ( w e i g h t s [ [ x ] ] , o b j [ [ x ] ] ) %% 22

w e i g h t s [ [ x ] ] ) ) ) 23

} 24

# # C a l u c u l a t e m e d i a n and IQR o f p o r t f o l i o r i s k s 25

mednames <− NULL 26

i q r n a m e s <− NULL 27

f o r ( i i n p o r t n a m e s ) { 28

o b j n a m e 1 <− p a s t e ( "Med" , i , s e p = " " ) 29

o b j n a m e 2 <− p a s t e ( " IQR " , i , s e p = " " ) 30

mednames <− c ( mednames , o b j n a m e 1 ) 31

i q r n a m e s <− c ( i q r n a m e s , o b j n a m e 2 ) 32

a s s i g n ( objname1 , m e d i a n ( e v a l ( a s . name ( i ) ) ) ) 33

a s s i g n ( objname2 , IQR ( e v a l ( a s . name ( i ) ) ) ) 34

} 35

sample sizes, but the differences are becoming negligible forT =240 with respect to the median risks. Lower portfolio risks can be achieved with the robust OGK and Stahel–Donoho estimators for this DGP. ForT=60 the M-, MM, and S-estimators excel likewise.

For the second DGP, a multivariate distribution with excess kurtosis but no tail de- pendence, two observations can be made. First, the risk levels increase for all types of estimator and this increase is most pronounced for the classical estimator. In con- trast, the increase in the median risks for the robust estimators is rather negligible, and

k k Table 10.1 Portfolio simulation: summary of portfolio risks

Estimator Normal / Normal Normal / Student Student / Student

Median IQR Median IQR Median IQR

T=60

Classic 0.75 0.098 0.91 0.142 0.92 0.158

MCD 0.76 0.147 0.79 0.178 0.82 0.172

M 0.73 0.131 0.76 0.161 0.79 0.159

MM 0.74 0.100 0.82 0.121 0.82 0.129

MVE 0.74 0.154 0.77 0.173 0.80 0.165

OGK 0.66 0.117 0.67 0.129 0.67 0.129

SDE 0.70 0.141 0.72 0.149 0.75 0.164

S 0.73 0.110 0.80 0.127 0.82 0.144

T=120

Classic 0.76 0.067 0.95 0.106 0.96 0.121

MCD 0.77 0.091 0.82 0.102 0.83 0.111

M 0.75 0.081 0.79 0.105 0.81 0.107

MM 0.76 0.067 0.85 0.084 0.84 0.090

MVE 0.76 0.096 0.81 0.106 0.83 0.114

OGK 0.69 0.080 0.71 0.089 0.69 0.090

SDE 0.74 0.094 0.77 0.098 0.80 0.109

S 0.75 0.075 0.82 0.086 0.84 0.096

T=240

Classic 0.77 0.052 0.97 0.084 0.97 0.097

MCD 0.77 0.058 0.83 0.074 0.85 0.077

M 0.77 0.059 0.82 0.077 0.82 0.077

MM 0.76 0.051 0.86 0.067 0.86 0.066

MVE 0.77 0.064 0.84 0.079 0.85 0.083

OGK 0.70 0.056 0.72 0.068 0.71 0.065

SDE 0.76 0.061 0.80 0.074 0.81 0.075

S 0.76 0.052 0.84 0.068 0.86 0.068

all of these estimators outperform the classic estimator, that is, producing portfolio allocations of lower risk. The OGK estimator fares best.

This picture remains pretty much unchanged for the third DGP, where now tail dependencies exist between the included assets. The differences between the second and third DGPs in the median levels are rather small for all estimators and sample sizes. One can conclude that tail dependence does not have a material impact on the overall portfolio risk for the given simulation design.

The two main take-home messages are, first, that even in the case of the multivariate normal distribution, it can be advantageous to employ a robust estimator, in particular OGK, instead of the classical estimator; and second, all robust estimators are quite

k k immune with respect to different DGPs, but violations of the model assumptions exert

a great impact on portfolio riskiness when a classical estimator is utilized.

When the interquartile ranges of the portfolio risks for each of the estimators and sample sizes are compared, two features emerge. First, in the case of the Gaussian DGP, the portfolio risks are more concentrated compared to the robust estimators for all sample sizes. This result confirms the best linear unbiased estimator property of the classical estimator. Second, by slightly violating the assumption of normality the implied portfolio risks of the classical estimator are dispersed more widely compared to most of the robust estimators. For the latter, the interquartile range remains pretty much the same, regardless of DGP.

Một phần của tài liệu Financial risk modelling and portfolio optimization with r second edition (Trang 191 - 197)

Tải bản đầy đủ (PDF)

(436 trang)