PRACTICE 1: MUTUAL FUNDS EVALUATION USING MATLAB. INDEX 1. Load data usng the Edtor wndow and m-fle 2. Learnng to save results from the Edtor wndow. 3. Computng the Sharpe Rato 4. Obtanng the Treynor Rato 5. The Alpha from the CAPM 6. The Alpha from the Fama and French three factors model. 7. Makng rankng and obtanng conclusons. Jesús Davd Moreno (Assocate Professor Unversty Carlos III) 1/16
1. Load data usng the Edtor wndow and mfle In ths practce you wll use a sample of Equty Mutual Funds from one of the most prestgous mutual fund database, the CRSP (Chcago Research Securty Prces). In ths database there are data from 196 untl 26, and for all mutual fund categores (equty, fxed ncome, balanced, etc). However, gven that ths s only an exercse you wll use data from 55 Equty mutual funds n the Aggressve Growth Category and from January 22 untl December 24. The frequency of the data wll be monthly (24 observatons for each fund). All ths data are n a matlab fle name DATAFUNDS.mat Moreover, you wll need some other addtonal data, as Treasure Blls returns, Market returns, or the Fama and French factors. And these addtonal data are n a fle named ADDITIONAL_DATA.mat. Frst, we must mport data usng the Edtor Wndow. Thus, we must open a new M-Fle Second, wrte some comments at the begnnng that permts you to dentfy ths code. >> %% Ths code has been created to evaluate Equty Mutual Funds - Mater n Fnance >> %% Date: February-212 Thrd, we must use the LOAD functon to mport the varable. >> clear all >> load DATAFUNDS.mat >> load ADDITIONAL_DATA.mat Jesús Davd Moreno (Assocate Professor Unversty Carlos III) 2/16
Fourth, we run the program to check the data loaded. To get t, clck on the con save and on the con Run The data you have mported are: rmf: Ths contans the returns of all mutual funds. Each mutual fund s represented n a dfferent column. So rmf s a 24 x 55 matrx. rtblls: It s a vector (24x1) wth the monthly rsk-free rate. rmk: It contans the returns of a Market ndex. smb: A column vector wth the Small-mnus-Bg factor to be use n the Fama and Frech model. hml: A column vector wth the Hgh-mnus-Low factor for the Fama and French model. wml: A column vector wth the momentum factor for the Carhart model. You can fnd all these factors n the followng webpage: http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_lbrary.html If you want, you could plot each of the varables to check that they are rght or there are not extreme outlers, etc. >> plot(rtblls) >> plot(rmk) >> plot(smb) >> plot(hml) >> for =1:3 >> plot(rmf(:,)) >> end Or you can also use a subplot command. Jesús Davd Moreno (Assocate Professor Unversty Carlos III) 3/16
2. Learnng to save results from the Edtor wndow. Frst, to save results you wll use the save command. I you want to save all the varables n the workspace >> save DavdResults.mat If you want to save only a varable n a Matlab fle. >> save DavdResults_X1.mat X1 If you want to save only one varable n Excel (may be to do another operatons wth t), the command wll be >> save DavdResults_X1.txt X1 -asc -tabs Jesús Davd Moreno (Assocate Professor Unversty Carlos III) 4/16
3. Computng the Sharpe Rato Frst, we compute the average return obtaned by each mutual fund, and we can do t wth the functon mean. >>meanrmf=mean(rmf); Remember that the functon "mean" s computng the average or mean for each column n the matrx. When you have the returns of the mutual funds n rows nstead of n columns, you have to transpose the data [mean(rmf')] Second, we compute the average return obtaned by the rsk-free asset. >> meanrtblls=mean(rtblls); Thrd, we compute the standard devaton of each mutual funds, usng the functon std. >> stdrmf=std(rmf); Fourth, we can compute the Sharpe Rato as >> Sharpe=(meanrMF-meanrtblls)./ stdrmf; It s must be noted that you are usng./ and not /. Because actually you do not want to do a matrx dvson. Instead you need to dvde each mutual fund excess return by ts standard devaton. Addtonally, you could compute the Average Sharpe Rato (or the medan) for all the mutual funds, or plot the Sharpe Ratos to analyze them. >> fgure >> bar(sharpe) Jesús Davd Moreno (Assocate Professor Unversty Carlos III) 5/16
>> ttle('sharpe Rato of Equty Mutual Funds') >> medansharpe=medan(sharpe) >> meansharpe=mean(sharpe).5 Sharpe Rato of Equty Mutual Funds.4.3.2.1 -.1 -.2 1 2 3 4 5 6 Jesús Davd Moreno (Assocate Professor Unversty Carlos III) 6/16
4. Obtanng the Treynor Rato In ths rato we can use some of the varables computed n the prevous performance measure. Because the numerator s equal than n the Sharpe rato, we only need to compute the beta (denomnator of Treynor Rato). Frst, we compute the beta of each mutual fund In ths case we can not use matrx operators but we need to compute the beta for each mutual fund ndependently, thus we need to use the command FOR to repeat some operatons a specfc number of tmes. Moreover, we need excess returns to compute the Beta. >> for j=1:55 >> rmf2(:,j)=rmf(:,j)-rtblls; >> rmk2=rmk-rtblls; >> varanrmk2=var(rmk2); >> covarmatrx=cov(rmf2(:,j),rmk2); >> covarmf=covarmatrx(1,2); >> Beta(1,j)=covarMF/varanrMk2; >> end Second, we can compute the Treynor Rato. >> Treynor=(meanrMF-meanrtblls)./Beta; Fnally, to analyze the results we can plot t or compute some statstcs. >> meantreynor=mean(treynor); >> medantreynor=medan(treynor); >> fgure >> bar(treynor) >> ttle( Treynor Rato from Equty Mutual Funds ) Jesús Davd Moreno (Assocate Professor Unversty Carlos III) 7/16
.3 Treynor Rato of Equty Mutual Funds.25.2.15.1.5 -.5 -.1 1 2 3 4 5 6 Jesús Davd Moreno (Assocate Professor Unversty Carlos III) 8/16
5. Computng the Alpha from the CAPM We are computng the alpha as a coeffcent estmated n the followng regresson (solved by Ordnary Least Squeares, OLS) r r r M = ˆ α + ˆ β ( r ) + ε R where = = R r M f r f M To estmate that equaton by OLS we could use the functon regress or regstats. But we are usng regstats because ths functon wll gve us more nformaton (t-statstcs, R-squared, pvalues,...). Moreover, n the regstats functon by default we estmate a model wth a constant or ntercept and ths s the easer for us than n regress, where we have to ntroduce a colum vector of ones to use a constant. [B, BINT]=regress(Y,X) >> help regress REGRESS Multple lnear regresson usng least squares. B = REGRESS(Y,X) returns the vector B of regresson coeffcents n the lnear model Y = X*B. X s an n-by-p desgn matrx, wth rows correspondng to observatons and columns to predctor varables. Y s an n-by-1 vector of response observatons. [B,BINT] = REGRESS(Y,X) returns a matrx BINT of 95% confdence ntervals for B. [STATS]=regstats(Y,X, 'lnear') >> help regstats REGSTATS Regresson dagnostcs for lnear models. STATS = REGSTATS(RESPONSES,DATA,MODEL,WHICHSTATS) creates an output structure STATS contanng the statstcs lsted n WHICHSTATS. WHICHSTATS can be a sngle strng such as 'leverage' or a cell array of strngs such as {'leverage' 'standres' 'studres'}. By default, REGSTATS returns all statstcs. Vald statstc strngs are: Jesús Davd Moreno (Assocate Professor Unversty Carlos III) 9/16
Name Meanng 'Q' Q from the QR Decomposton of the desgn matrx 'R' R from the QR Decomposton of the desgn matrx 'beta' Regresson coeffcents 'covb' Covarance of regresson coeffcents 'yhat' Ftted values of the response data 'r' Resduals 'mse' Mean squared error 'rsquare' R-square statstc 'adjrsquare' Adjusted R-square statstc 'leverage' Leverage 'hatmat' Hat (projecton) matrx 's2_' Delete-1 varance 'beta_' Delete-1 coeffcents 'standres' Standardzed resduals 'studres' Studentzed resduals 'dfbetas' Scaled change n regresson coeffcents 'dfft' Change n ftted values 'dffts' Scaled change n ftted values 'covrato' Change n covarance 'cookd' Cook's dstance 'tstat' t statstcs for coeffcents 'fstat' F statstc 'dwstat' Durbn Watson statstc 'all' Create all of the above statstcs Frst, we need to crate the Y and X matrxes. Y varable s very easy to compute gven that t s equal to mutual fund excess returns. >> for j=1:55 >> Y=rMF2(:,j); >> X= rmk2; >> stats=regstats(y, X,'lnear'); >> coefc=stats.beta; >> Beta(j,1)=coefc(2) >> alpha_j(j,1)=coefc(1) >> t_jensen(j,1)=stats.tstat.t(1); >> clear Y X coefc stats >> end Second, we can analyze results by plottng them. >> bar(alpha_j) Jesús Davd Moreno (Assocate Professor Unversty Carlos III) 1/16
Remember that you can ntroduce ttles wth the command "ttle', and the text n the axes wth the commands "xlabel", "ylabel" >> hst(alpha_j) >> meanalpha=mean(alpha_j);.2 Alpha`s Jensen from Equty Mutual Funds.15.1 alpha.5 -.5 -.1 1 2 3 4 5 6 number of mutual fund 12 hstogram from alpha`s Jensen 1 8 6 4 2 -.1 -.5.5.1.15.2 Jesús Davd Moreno (Assocate Professor Unversty Carlos III) 11/16
6. Computng the Alpha from the FF model We are computng the alpha as a coeffcent estmated n the followng multvarate regresson (solved by Ordnary Least Squeares, OLS) R R R M SMB HML = ˆ α + β ( RM ) + β ( SMB) + β ( HML) ε where = r r = r M f ˆ r f ˆ To estmate that equaton by OLS we use the functon regstats. [stats]=regstats(y,x,'lnear') ˆ Frst, we need to crate the Y and X matrxes. >> for j=1:55 >> Y=rMF2(:,j); >> X= [rmk2, SMB, HML]; >> stats=regstats(y, X,'lnear'); >> coefc=stats.beta; >> alphaff(j,1)=coefc(1) >> t_ff(j,1)=stats.tstat.t(1); >> clear Y X coefc stats >> end Second, we can analyze results by plottng them. >> bar(alphaff) >> hst(alphaff) Jesús Davd Moreno (Assocate Professor Unversty Carlos III) 12/16
>> meanalphaff=mean(alphaff);.1 Alpha`s FF model from Equty Mutual Funds.5 alpha FF -.5 -.1 -.15 -.2 -.25 1 2 3 4 5 6 number of mutual fund 14 hstogram from alpha FF model 12 1 8 6 4 2 -.25 -.2 -.15 -.1 -.5.5.1 Jesús Davd Moreno (Assocate Professor Unversty Carlos III) 13/16
Thrd, we can analyze the dfferences between usng Jensen s Alpha and Alpha from the FF three factors model. >> Dff_alpha=alpha-alphaFF >> fgure >> plot(dff_alpha, s-r ) >> ttle( Dfference among Alphas ), grd on.15 Dfference among Alphas.1.5 -.5 -.1 1 2 3 4 5 6 Jesús Davd Moreno (Assocate Professor Unversty Carlos III) 14/16
7. Makng rankngs and obtanng conclusons. One of the most relevance functons of performance measures s to acheve rankngs of the mutual funds. These rankngs are publshed n newspapers, magaznes, etc. and are used by nvestors to allocate ther funds. Frst, we can sort the mutual funds wth the functon sort. >> help sort SORT order. for vectors, SORT(X) sorts the elements of X n ascendng >> [SharpeRank, SharpeRank2]=sort(Sharpe) You must note that n SharpeRank varable you have the Sharpe Rato values for each mutual fund ranked by Sharpe Rato. But n the varable SharpeRank2 you have the number (from colums n rmf) of the mutual fund n that poston. >> [TreynorRank, TreynorRank2]=sort(Treynor) >> [alpharank, alpharank2]=sort(alpha) >> [alphaffrank, alphaffrank2]=sort(alphaff) Now, we can bult a new matrx wth the ndex of each funds n the rankngs computed prevously. >> TableRank=[SharpeRank2, TreynorRank2, alpharank2, alphaffrank2 ] TableRank = 25 25 25 25 7 7 24 49 24 24 7 5 The worst fund Jesús Davd Moreno (Assocate Professor Unversty Carlos III) 15/16
27 17 27 52 17 27 19 38 19 49 49 37 33 33 33 33 The best fund Fnally, we can analyze all performance measures together usng the command subplot >> subplot(2,2,1) >> bar(sharpe) >> subplot(2,2,2) >> bar(treynor)... >>....6 Sharpe.3 Treynor.4.2.2.1 -.2 2 4 6 -.1 2 4 6.2 alpha.1 alphaff.1 -.1 -.2 -.1 2 4 6 -.3 2 4 6 Jesús Davd Moreno (Assocate Professor Unversty Carlos III) 16/16