Professional Documents
Culture Documents
%&#($/'0"&12#'3333&
&&
!"#$%&$'()*(+,%,#-(.,/01('2#-,#%&3/( ,1&/4(+#%-#5.
INDEX
1. Load data using the Editor window and m-file 2. Learning to save results from the Editor window. 3. Computing the Sharpe Ratio 4. Obtaining the Treynor Ratio 5. The Alpha from the CAPM 6. The Alpha from the Fama and French three factors model. 7. Making ranking and obtaining conclusions.
!"#$%&%"'()*+",-.$/-"01%%-2*(3$"4.-5$%%-."6/*)$.%*37"8(.9-%":::;""
<=<>"
!"#"$%&'"()*&+,$%"$#-.(&/*-(0&!$#%$1&2!"#$%&'()'*()")+%,'-)(.%&#($/'0"&12#'3333&
&&
!"#$%&'#'&(&#)*+,-#(./#01'+(%2#3+,'%34#&,'#056 7+8/4
In this practice you will use a sample of Equity Mutual Funds from one of the most prestigious mutual fund database, the CRSP (Chicago Research Security Prices). In this database there are data from 1960 until 2006, and for all mutual fund categories (equity, fixed income, balanced, etc). However, given that this is only an exercise you will use data from 55 Equity mutual funds in the Aggressive Growth Category and from January 2002 until December 2004. The frequency of the data will be monthly (24 observations for each fund). All this data are in a matlab file name DATAFUNDS.mat Moreover, you will need some other additional data, as Treasure Bills returns, Market returns, or the Fama and French factors. And these additional data are in a file named ADDITIONAL_DATA.mat.
Second, write some comments at the beginning that permits you to identify this code.
>> %% This code has been created to evaluate Equity Mutual Funds - Mater in Finance >> %% Date: February-2012
!"#$%&%"'()*+",-.$/-"01%%-2*(3$"4.-5$%%-."6/*)$.%*37"8(.9-%":::;""
?=<>"
!"#"$%&'"()*&+,$%"$#-.(&/*-(0&!$#%$1&2!"#$%&'()'*()")+%,'-)(.%&#($/'0"&12#'3333&
&&
rMF: This contains the returns of all mutual funds. Each mutual fund is represented in a different column. So rMF is a 24 x 55 matrix. rtbills: It is a vector (24x1) with the monthly risk-free rate. rMk: It contains the returns of a Market index. smb: A column vector with the Small-minus-Big factor to be use in the Fama and Frech model. hml: A column vector with the High-minus-Low factor for the Fama and French model. wml: A column vector with the momentum factor for the Carhart model.
You can find all these factors in the following webpage: http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html
If you want, you could plot each of the variables to check that they are right or there are not extreme outliers, etc. >> >> >> >> >> >> >> plot(rtbills) plot(rMk) plot(SMB) plot(HML) for i=1:30 plot(rMF(:,i)) end
!"#$%&%"'()*+",-.$/-"01%%-2*(3$"4.-5$%%-."6/*)$.%*37"8(.9-%":::;""
@=<>"
!"#"$%&'"()*&+,$%"$#-.(&/*-(0&!$#%$1&2!"#$%&'()'*()")+%,'-)(.%&#($/'0"&12#'3333&
&&
9"#$/&2,+,-#(%#*&:/#2/*)8(*#72%5#(./#1'+(%2# 3+,'%3" #
First, to save results you will use the save command. I you want to save all the variables in the workspace
>> save DavidResults.mat
If you want to save only a variable in a Matlab file. >> save DavidResults_X1.mat X1 If you want to save only one variable in Excel (may be to do another operations with it), the command will be >> save DavidResults_X1.txt X1 -ascii -tabs
# # # #
!"#$%&%"'()*+",-.$/-"01%%-2*(3$"4.-5$%%-."6/*)$.%*37"8(.9-%":::;""
A=<>"
!"#"$%&'"()*&+,$%"$#-.(&/*-(0&!$#%$1&2!"#$%&'()'*()")+%,'-)(.%&#($/'0"&12#'3333&
&&
;"#<%5=)(+,-#(./#>.&2=/#?&(+%# #
First, we compute the average return obtained by each mutual fund, and we can do it with the function mean.
>>meanrMF=mean(rMF);
Remember that the function "mean" is computing the average or mean for each column in the matrix. When you have the returns of the mutual funds in rows instead of in columns, you have to transpose the data [mean(rMF')]
Third, we compute the standard deviation of each mutual funds, using the function std.
>> stdrMF=std(rMF);
It is must be noted that you are using ./ and not /. Because actually you do not want to do a matrix division. Instead you need to divide each mutual fund excess return by its standard deviation. Additionally, you could compute the Average Sharpe Ratio (or the median) for all the mutual funds, or plot the Sharpe Ratios to analyze them. >> >> figure bar(Sharpe)
!"#$%&%"'()*+",-.$/-"01%%-2*(3$"4.-5$%%-."6/*)$.%*37"8(.9-%":::;""
B=<>"
!"#"$%&'"()*&+,$%"$#-.(&/*-(0&!$#%$1&2!"#$%&'()'*()")+%,'-)(.%&#($/'0"&12#'3333&
&&
0.5
0.4
0.3
0.2
0.1
-0.1
-0.2
10
20
30
40
50
60
!"#$%&%"'()*+",-.$/-"01%%-2*(3$"4.-5$%%-."6/*)$.%*37"8(.9-%":::;""
>=<>"
!"#"$%&'"()*&+,$%"$#-.(&/*-(0&!$#%$1&2!"#$%&'()'*()")+%,'-)(.%&#($/'0"&12#'3333&
&&
@"#AB(&+,+,-#(./#C2/D,%2#?&(+%#
In this ratio we can use some of the variables computed in the previous performance measure. Because the numerator is equal than in the Sharpe ratio, we only need to compute the beta (denominator of Treynor Ratio). First, we compute the beta of each mutual fund
In this case we can not use matrix operators but we need to compute the beta for each mutual fund independently, thus we need to use the command FOR to repeat some operations a specific number of times. Moreover, we need excess returns to compute the Beta.
Finally, to analyze the results we can plot it or compute some statistics. >> meanTreynor=mean(Treynor); >> medianTreynor=median(Treynor); >> figure >> bar(Treynor) >> title(Treynor Ratio from Equity Mutual Funds)
!"#$%&%"'()*+",-.$/-"01%%-2*(3$"4.-5$%%-."6/*)$.%*37"8(.9-%":::;""
C=<>"
!"#"$%&'"()*&+,$%"$#-.(&/*-(0&!$#%$1&2!"#$%&'()'*()")+%,'-)(.%&#($/'0"&12#'3333&
&&
Treynor Ratio of Equity Mutual Funds 0.03 0.025 0.02 0.015 0.01 0.005 0 -0.005 -0.01
10
20
30
40
50
60
!"#$%&%"'()*+",-.$/-"01%%-2*(3$"4.-5$%%-."6/*)$.%*37"8(.9-%":::;""
D=<>"
!"#"$%&'"()*&+,$%"$#-.(&/*-(0&!$#%$1&2!"#$%&'()'*()")+%,'-)(.%&#($/'0"&12#'3333&
&&
E"#<%5=)(+,-#(./#F8=.H%5#(./#<FGH#
We are computing the alpha as a coefficient estimated in the following regression (solved by Ordinary Least Squeares, OLS)
To estimate that equation by OLS we could use the function regress or regstats. But we are using regstats because this function will give us more information (t-statistics, R-squared, pvalues,...). Moreover, in the regstats function by default we estimate a model with a constant or intercept and this is the easier for us than in regress, where we have to introduce a colum vector of ones to use a constant. [B, BINT]=regress(Y,X)
>> help regress REGRESS Multiple linear regression using least squares. B = REGRESS(Y,X) returns the vector B of regression coefficients in the linear model Y = X*B. X is an n-by-p design matrix, with rows corresponding to observations and columns to predictor variables. Y is an n-by-1 vector of response observations. [B,BINT] = REGRESS(Y,X) returns a matrix BINT of 95% confidence intervals for B.
[STATS]=regstats(Y,X, 'linear')
>> help regstats REGSTATS Regression diagnostics for linear models. STATS = REGSTATS(RESPONSES,DATA,MODEL,WHICHSTATS) creates an output structure STATS containing the statistics listed in WHICHSTATS. WHICHSTATS can be a single string such as 'leverage' or a cell array of strings such as {'leverage' 'standres' 'studres'}. By default, REGSTATS returns all statistics. Valid statistic strings are:
!"#$%&%"'()*+",-.$/-"01%%-2*(3$"4.-5$%%-."6/*)$.%*37"8(.9-%":::;""
E=<>"
!"#"$%&'"()*&+,$%"$#-.(&/*-(0&!$#%$1&2!"#$%&'()'*()")+%,'-)(.%&#($/'0"&12#'3333& Name Meaning 'Q' Q from the QR Decomposition of the design matrix 'R' R from the QR Decomposition of the design matrix 'beta' Regression coefficients 'covb' Covariance of regression coefficients 'yhat' Fitted values of the response data 'r' Residuals 'mse' Mean squared error 'rsquare' R-square statistic 'adjrsquare' Adjusted R-square statistic 'leverage' Leverage 'hatmat' Hat (projection) matrix 's2_i' Delete-1 variance 'beta_i' Delete-1 coefficients 'standres' Standardized residuals 'studres' Studentized residuals 'dfbetas' Scaled change in regression coefficients 'dffit' Change in fitted values 'dffits' Scaled change in fitted values 'covratio' Change in covariance 'cookd' Cook's distance 'tstat' t statistics for coefficients 'fstat' F statistic 'dwstat' Durbin Watson statistic 'all' Create all of the above statistics
&&
First, we need to crate the Y and X matrixes. Y variable is very easy to compute given that it is equal to mutual fund excess returns. >> >> >> >> >> >> >> >> >> >> for j=1:55 Y=rMF2(:,j); X= rMk2; stats=regstats(Y, X,'linear'); coefic=stats.beta; Beta(j,1)=coefic(2) alpha_J(j,1)=coefic(1) t_Jensen(j,1)=stats.tstat.t(1); clear Y X coefic stats end
!"#$%&%"'()*+",-.$/-"01%%-2*(3$"4.-5$%%-."6/*)$.%*37"8(.9-%":::;""
<F=<>"
!"#"$%&'"()*&+,$%"$#-.(&/*-(0&!$#%$1&2!"#$%&'()'*()")+%,'-)(.%&#($/'0"&12#'3333&
&&
Remember that you can introduce titles with the command "title', and the text in the axes with the commands "xlabel", "ylabel"
>> >>
hist(alpha_J) meanAlpha=mean(alpha_J);
0.02
0.015
0.01
alpha
0.005
-0.005
-0.01
10
50
60
12
10
0 -0.01
-0.005
0.005
0.01
0.015
0.02
!"#$%&%"'()*+",-.$/-"01%%-2*(3$"4.-5$%%-."6/*)$.%*37"8(.9-%":::;""
<<=<>"
!"#"$%&'"()*&+,$%"$#-.(&/*-(0&!$#%$1&2!"#$%&'()'*()")+%,'-)(.%&#($/'0"&12#'3333&
&&
I"#<%5=)(+,-#(./#F8=.H%5#(./#JJ#5%'/8#
We are computing the alpha as a coefficient estimated in the following multivariate regression (solved by Ordinary Least Squeares, OLS)
Second, we can analyze results by plotting them. >> >> bar(alphaFF) hist(alphaFF)
<?=<>"
!"#$%&%"'()*+",-.$/-"01%%-2*(3$"4.-5$%%-."6/*)$.%*37"8(.9-%":::;""
!"#"$%&'"()*&+,$%"$#-.(&/*-(0&!$#%$1&2!"#$%&'()'*()")+%,'-)(.%&#($/'0"&12#'3333&
&&
>>
meanAlphaFF=mean(alphaFF);
Alpha`s FF model from Equity Mutual Funds
0.01
0.005
alpha FF
-0.005
-0.01
-0.015
-0.02
-0.025
10
50
60
14
12
10
0 -0.025
-0.02
-0.015
-0.01
-0.005
0.005
0.01
!"#$%&%"'()*+",-.$/-"01%%-2*(3$"4.-5$%%-."6/*)$.%*37"8(.9-%":::;""
<@=<>"
!"#"$%&'"()*&+,$%"$#-.(&/*-(0&!$#%$1&2!"#$%&'()'*()")+%,'-)(.%&#($/'0"&12#'3333&
&&
Third, we can analyze the differences between using Jensens Alpha and Alpha from the FF three factors model. >> >> >> >> Diff_alpha=alpha-alphaFF figure plot(Diff_alpha,s-r) title(Difference among Alphas), grid on
0.015
0.01
0.005
-0.005
-0.01
10
20
30
40
50
60
!"#$%&%"'()*+",-.$/-"01%%-2*(3$"4.-5$%%-."6/*)$.%*37"8(.9-%":::;""
<A=<>"
!"#"$%&'"()*&+,$%"$#-.(&/*-(0&!$#%$1&2!"#$%&'()'*()")+%,'-)(.%&#($/'0"&12#'3333&
&&
K"#H&L+,-#2&,L+,-*#&,'#%B(&+,+,-#M%,M8)*+%,*"# #
One of the most relevance functions of performance measures is to achieve rankings of the mutual funds. These rankings are published in newspapers, magazines, etc. and are used by investors to allocate their funds.
First, we can sort the mutual funds with the function sort. >> help sort SORT for vectors, SORT(X) sorts the elements of X in ascending order.
>>
[SharpeRank, SharpeRank2]=sort(Sharpe)
You must note that in SharpeRank variable you have the Sharpe Ratio values for each mutual fund ranked by Sharpe Ratio. But in the variable SharpeRank2 you have the number (from colums in rMF) of the mutual fund in that position.
Now, we can built a new matrix with the index of each funds in the rankings computed previously. >>
TableRank = 25 25 25 25 7 7 24 49 24 24 7 50
!"#$%&%"'()*+",-.$/-"01%%-2*(3$"4.-5$%%-."6/*)$.%*37"8(.9-%":::;""
<B=<>"
!"#"$%&'"()*&+,$%"$#-.(&/*-(0&!$#%$1&2!"#$%&'()'*()")+%,'-)(.%&#($/'0"&12#'3333&
27 17 19 33 17 27 27 19 49 49 33 33 52 38 37
&&
33
Finally, we can analyze all performance measures together using the command subplot
>> >> >> >> >> subplot(2,2,1) bar(Sharpe) subplot(2,2,2) bar(Treynor).... .....
Treynor
20 alpha
40
60
20 alphaFF
40
60
0.02
0.01 0 -0.01
0.01
-0.02 -0.03
-0.01
20
40
60
20
40
60
!"#$%&%"'()*+",-.$/-"01%%-2*(3$"4.-5$%%-."6/*)$.%*37"8(.9-%":::;""
<>=<>"