Back-test comparison for stock portfolio

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

In this example, the results of a conditional draw-down at risk strategy are compared to the outcome of a minimum-variance allocation. The portfolio solutions consist of the constituents of the Euro Stoxx 50 index. The purpose of this example is to show that a global minimum-variance allocation is not a shelter from losses per se. The first section of the code is provided in Listing 12.5.

First, the necessary packages are brought into the workspace. The packageFRAPO will be employed for the data set used (EuroStoxx50) and to conduct the CDaR optimizations. The data set is also used in Cesarone et al. (2011). It is included in the package as a data frame with 265 weekly observations of 48 members of the index.

The sample starts on 3 March 2003 and ends on 24 March 2008. The solutions of the global minimum-variance portfolios are determined by means of the functions contained in the packagefPortfolio, and the analysis of the simulations is carried out

k k Rcode 12.5Back-test: GMV versus CDaR portfolio optimization.

l i b r a r y ( FRAPO ) 1

l i b r a r y ( f P o r t f o l i o ) 2

l i b r a r y ( P e r f o r m a n c e A n a l y t i c s ) 3

# # L o a d i n g o f d a t a s e t 4

d a t a ( E u r o S t o x x 5 0 ) 5

# # C r e a t i n g t i m e S e r i e s o f p r i c e s and r e t u r n s 6

p r <− t i m e S e r i e s ( E u r o S t o x x 5 0 , c h a r v e c = rownames ( E u r o S t o x x 5 0 ) ) 7

N A s s e t s <− n c o l ( p r ) 8

RDP <− na . o m i t ( ( p r / l a g ( pr , k = 1 ) − 1 ) 1 0 0 ) 9

# # B a c k t e s t o f GMV v s . CDaR 10

# # S t a r t and end d a t e s 11

t o <− t i m e ( RDP ) [ 2 0 8 : nrow ( RDP ) ] 12

fr om <− r e p ( s t a r t ( RDP ) , l e n g t h ( t o ) ) 13

# # P o r t f o l i o s p e c i f i c a t i o n s 14

# # CDaR p o r t f o l i o 15

DDbound <− 0 . 1 0 16

DDalpha <− 0 . 9 5 17

# # GMV p o r t f o l i o 18

mvspec <− p o r t f o l i o S p e c ( ) 19

BoxC <− c ( " minsumW [ 1 : N A s s e t s ] = 0 . 0 " , "maxsumW [ 1 : N A s s e t s ] = 1 . 0 " ) 20

# # I n i t i a l i s i n g w e i g h t m a t r i c e s 21

wMV <− wCD <− m a t r i x (NA, n c o l = n c o l ( RDP ) , nrow = l e n g t h ( t o ) ) 22

# # C o n d u c t i n g b a c k t e s t 23

f o r ( i i n 1 : l e n g t h ( t o ) ) { 24

s e r i e s <− window ( RDP , s t a r t = f r om [ i ] , end = t o [ i ] ) 25

p r i c e s <− window ( pr , s t a r t = f r om [ i ] , end = t o [ i ] ) 26

mv <− m i n v a r i a n c e P o r t f o l i o ( d a t a = s e r i e s , 27

s p e c = mvspec , 28

c o n s t r a i n t s = BoxC ) 29

cd <− PCDaR ( p r i c e s , a l p h a = DDalpha , bound = DDbound , 30

s o f t B u d g e t = TRUE ) 31

wMV[ i , ] <− c ( g e t W e i g h t s ( mv ) ) 32

wCD[ i , ] <− W e i g h t s ( cd ) 33

} 34

# # L a g g i n g o p t i m a l w e i g h t s and subs a m p l e o f r e t u r n s 35

wMV <− r b i n d ( r e p (NA, n c o l ( RDP ) ) , wMV[−nrow (wMV) , ] ) 36

wMVL1 <− t i m e S e r i e s (wMV, c h a r v e c = t o ) 37

c o l n a m e s (wMVL1) <− c o l n a m e s ( RDP ) 38

wCD <− r b i n d ( r e p (NA, n c o l ( RDP ) ) , wCD[−nrow (wCD) , ] ) 39

wCDL1 <− t i m e S e r i e s (wCD, c h a r v e c = t o ) 40

c o l n a m e s ( wCDL1 ) <− c o l n a m e s ( RDP ) 41

RDPback <− RDP [ t o , ] 42

c o l n a m e s ( RDPback ) <− c o l n a m e s ( RDP ) 43

k k using the packagePerformanceAnalytics. After the packages have been loaded, the

data set is brought into memory and converted to atimeSeriesobject, and the discrete returns of the stock prices are assigned to the objectRDP. The back-test is then carried out in the form of a recursive window with an initial length of 208 obser- vations, which coincides with a span of four years. Lines 10–22 define the parameters and portfolio specifications employed. The CDaR portfolio will be optimized for a conditional draw-down as high as 10% for a confidence level of 95%. The GMV portfolio is defined with long-only and soft-budget constraints, such that the sum of weights is in the interval[0,1]. This restriction is created as a two-element charac- ter vector which defines the lower and upper bounds. In the last line of this chunk

Rcode 12.6Back-test: evaluation of results, part one.

# # P o r t f o l i o e q u i t i e s o f s t r a t e g i e s 1

MVRetFac <− 1 + rowSums (wMVL1 RDPback ) / 100 2

MVRetFac [ 1 ] <− 100 3

MVPort <− t i m e S e r i e s ( cumprod ( MVRetFac ) , 4

c h a r v e c = names ( MVRetFac ) ) 5

CDRetFac <− 1 + rowSums ( wCDL1 RDPback ) / 100 6

CDRetFac [ 1 ] <− 100 7

CDPort <− t i m e S e r i e s ( cumprod ( CDRetFac ) , 8

c h a r v e c = names ( CDRetFac ) ) 9

# # P r o g r e s s i o n o f w e a l t h 10

y l i m s <− r a n g e ( c b i n d ( MVPort , CDPort ) ) 11

p l o t ( CDPort , main = " " , y l i m = y l i m s , y l a b = " I n d e x v a l u e s " , 12

x l a b = " " ) 13

l i n e s ( MVPort , c o l = " d a r k g r e y " ) 14

l e g e n d ( " t o p l e f t " , l e g e n d = c ( "CDaR" , "GMV" ) , 15

c o l = c ( " b l a c k " , " d a r k g r e y " ) , 16

l t y = 1 ) 17

# # P o r t f o l i o r e t u r n s 18

MVRet <− r e t u r n s ( MVPort , method = " d i s c r e t e " , 19

p e r c e n t a g e = FALSE , t r i m = TRUE) 20

CDRet <− r e t u r n s ( CDPort , method = " d i s c r e t e " , 21

p e r c e n t a g e = FALSE , t r i m = TRUE) 22

# # Draw down t a b l e 23

t a b l e . Drawdowns ( MVRet ) 24

t a b l e . Drawdowns ( CDRet ) 25

# # P l o t o f draw down c u r v e s 26

MVD <− 100 P e r f o r m a n c e A n a l y t i c s : : : Drawdowns ( MVRet ) 27

CDD <− 100 P e r f o r m a n c e A n a l y t i c s : : : Drawdowns ( CDRet ) 28

p l o t (CDD, main = " " , y l a b = " P e r c e n t a g e s " , x l a b = " " , 29

y l i m = c ( min ( c (MVD, CDD) ) , 0 ) ) 30

l i n e s (MVD, c o l = " b l u e " ) 31

a b l i n e ( h = 0 , c o l = " l i g h t g r e y " ) 32

a b l i n e ( h = −10 , c o l = " l i g h t g r e y " , l t y = 2 ) 33

l e g e n d ( " b o t t o m l e f t " , l e g e n d = c ( "CDaR" , "GMV" ) , 34

c o l = c ( " b l a c k " , " b l u e " ) , l t y = 1 ) 35

k k of code thematrixobjectswMVandwCDare created so that the necessary mem-

ory is reserved in advance. The simulation itself is then carried out with the ensuing forloop. Within this closure, the subsamples of the returns and prices are extracted and each data set is then passed into the calls ofminvariancePortfolio()for the GMV andPCDaR()for the CDaR solutions, respectively. The optimal portfolio weights are then assigned to theith row of thematrixobjectswMVandwCDwhere the relevant methods for extracting the weight vectors have been utilized. Next, the weights are lagged by one period, such that the portfolio equities can be computed by direct multiplication with the returns for the back-test period.

In the first lines of Listing 12.6, the return factors for each strategy are assigned to the objectsMVRetFacandCDRetFac, where an initial wealth of 100 monetary units has been assumed. The trajectory of the portfolios’ equity is then given as the cumulative product of the return factors. These equity values are stored as objects MVPortfor the GMV strategy andCDPortfor the CDaR solution.

The R code for the evaluation of the two simulations is shown in the bottom part of Listing 12.6 and in Listing 12.7. First, the wealth trajectories are depicted in Figure 12.9.

The hump-shaped pattern during the financial crises is eye-catching and much more pronounced for the GMV than for the CDaR strategy. The final wealth of the GMV portfolio is slightly greater than that of the CDaR allocation. It is noteworthy that dur- ing the back-test period the GMV strategy yielded a fully invested solution, whereas according to the CDaR strategy not all capital was allocated to stocks at each rebal- ancing date. In particular, during the heyday of the financial crisis in 2007 and 2008 only between roughly 55% and 85% would have been allotted to stocks. This also partly explains the rather shallow wealth trajectory at the end of the back-test period.

Accrued interest from the wealth not invested in stocks was not considered.

Index values

2007−04−01 2007−10−01

100110120130

CDaR GMV

Figure 12.9 Comparison of wealth trajectories.

k k Table 12.2 Overview of draw-downs (positive, percentages).

Portfolio From Trough To Depth → ↘ ↗

GMV

1 2007-12-10 2008-03-17 20.11 17 15

2 2007-06-04 2007-08-13 2007-10-08 9.75 19 11 8

3 2007-10-15 2007-11-05 2007-11-26 3.34 7 4 3

4 2007-03-12 2007-03-12 2007-03-19 2.30 2 1 1

5 2007-04-23 2007-04-23 2007-04-30 0.76 2 1 1

CDaR

1 2007-11-12 2008-01-21 11.53 21 11

2 2007-06-04 2007-09-03 2007-10-08 5.58 19 14 5

3 2007-05-07 2007-05-07 2007-05-14 0.51 2 1 1

4 2007-03-12 2007-03-12 2007-03-19 0.49 2 1 1

5 2007-10-22 2007-10-29 2007-11-05 0.30 3 2 1

In lines 16–20 of Listing 12.6 the portfolio returns for each strategy are assigned to the objectsMVRetandCDRet, respectively. These objects are utilized in the com- putation of characteristic portfolio statistics. The first of these is an overview of the five greatest draw-downs within each strategy (see the results in Table 12.2).

As is evident from this table, the portfolio draw-downs are all larger for the GMV strategy than for the CDaR allocation. The conditional draw-down level for the CDaR strategy has been violated in one instance, albeit marginally. The draw-downs are displayed in lines 24–33, now expressed as negative percentages (see Figure 12.10).

Percentages

2007−04−01 2007−10−01

−20−15−10−50

CDaR GMV

Figure 12.10 Comparison of draw-down trajectories.

k k Rcode 12.7Back-test: evaluation of results, part two.

# # P o r t f o l i o S t a t i s t i c s 1

# # VaR 2

MVVAR <− −100 VaR ( MVRet , p = 0 . 9 5 , method = " g a u s s i a n " ) 3

CDVAR <− −100 VaR ( CDRet , p = 0 . 9 5 , method = " g a u s s i a n " ) 4

# # ES 5

MVES <− −100 ES ( MVRet , p = 0 . 9 5 , method = " g a u s s i a n " ) 6

CDES <− −100 ES ( CDRet , p = 0 . 9 5 , method = " g a u s s i a n " ) 7

# # S h a r p e 8

MVSR <− S h a r p e R a t i o ( MVRet ) 9

CDSR <− S h a r p e R a t i o ( CDRet ) 10

# # A n n u a l i s e d r e t u r n s 11

MVRA <− R e t u r n . a n n u a l i z e d ( MVRet , s c a l e = 5 2 ) 12

CDRA <− R e t u r n . a n n u a l i z e d ( CDRet , s c a l e = 5 2 ) 13

# # Draw downs 14

MVDD <− −100 f i n d D r a w d o w n s ( MVRet ) $ r e t u r n 15

MVDD <− MVDD[MVDD! = 0 . 0 ] 16

l e n g t h (MVDD) 17

summary (MVDD) 18

CDDD <− −100 f i n d D r a w d o w n s ( CDRet ) $ r e t u r n 19

CDDD <− CDDD[CDDD! = 0 . 0 ] 20

l e n g t h (CDDD) 21

summary (CDDD) 22

In Listing 12.7 some key portfolio performance statistics are computed. A sum- mary of these is provided in Table 12.3.

In retrospect, the Gaussian tail risks VaR and ES for the GMV portfolio are both greater than the respective numbers for the CDaR strategy at the 95% level. Because the higher riskiness of the former strategy is roughly balanced against the more favor- able annualized return for the GMV, the portfolios’ Sharpe ratios are almost equal.

The summary statistics for the portfolio draw-downs all indicate a less risky alloca- tion of the CDaR strategy, except for the number of draw-downs. As stated at the beginning of this section, the purpose of this example is to remind the reader that a GMV optimization is not a panacea against large losses per se, and the often en- countered corner solutions of such a strategy can turn into the opposite of what was initially intended.

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

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

(436 trang)