Вы находитесь на странице: 1из 16

Mutual Funds Evaluation Using Matlab (Master in Finance, University Carlos III)

PRACTICE 1: MUTUAL FUNDS EVALUATION


USING MATLAB.

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.

Jess David Moreno (Associate Professor University Carlos III) 1/16


Mutual Funds Evaluation Using Matlab (Master in Finance, University Carlos III)

1. Load data using the Editor window and m-

file

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.

First, we must import data using the Editor Window.


Thus, we must open a new M-File

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

Third, we must use the LOAD function to import the variable.


>> clear all

>> load DATAFUNDS.mat


>> load ADDITIONAL_DATA.mat

Jess David Moreno (Associate Professor University Carlos III) 2/16


Mutual Funds Evaluation Using Matlab (Master in Finance, University Carlos III)

Fourth, we run the program to check the data loaded.


To get it, click on the icon save and on the icon Run

The data you have imported are:

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

Or you can also use a subplot command.

Jess David Moreno (Associate Professor University Carlos III) 3/16


Mutual Funds Evaluation Using Matlab (Master in Finance, University Carlos III)

2. Learning to save results from the Editor

window.

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

Jess David Moreno (Associate Professor University Carlos III) 4/16


Mutual Funds Evaluation Using Matlab (Master in Finance, University Carlos III)

3. Computing the Sharpe Ratio

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')]

Second, we compute the average return obtained by the risk-free asset.


>> meanrtbills=mean(rtbills);

Third, we compute the standard deviation of each mutual funds, using the
function std.
>> stdrMF=std(rMF);

Fourth, we can compute the Sharpe Ratio as

>> Sharpe=(meanrMF-meanrtbills)./ stdrMF;

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)

Jess David Moreno (Associate Professor University Carlos III) 5/16


Mutual Funds Evaluation Using Matlab (Master in Finance, University Carlos III)

>> title('Sharpe Ratio of Equity Mutual Funds')


>> medianSharpe=median(Sharpe)
>> meanSharpe=mean(Sharpe)

Sharpe Ratio of Equity Mutual Funds


0.5

0.4

0.3

0.2

0.1

-0.1

-0.2
0 10 20 30 40 50 60

Jess David Moreno (Associate Professor University Carlos III) 6/16


Mutual Funds Evaluation Using Matlab (Master in Finance, University Carlos III)

4. Obtaining the Treynor Ratio

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.

>> for j=1:55

>> rMF2(:,j)=rMF(:,j)-rtbills;
>> rMk2=rMk-rtbills;
>> varianrMk2=var(rMk2);

>> covarMatrix=cov(rMF2(:,j),rMk2);
>> covarMF=covarMatrix(1,2);
>> Beta(1,j)=covarMF/varianrMk2;
>> end

Second, we can compute the Treynor Ratio.


>> Treynor=(meanrMF-meanrtbills)./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)

Jess David Moreno (Associate Professor University Carlos III) 7/16


Mutual Funds Evaluation Using Matlab (Master in Finance, University Carlos III)

Treynor Ratio of Equity Mutual Funds


0.03

0.025

0.02

0.015

0.01

0.005

-0.005

-0.01
0 10 20 30 40 50 60

Jess David Moreno (Associate Professor University Carlos III) 8/16


Mutual Funds Evaluation Using Matlab (Master in Finance, University Carlos III)

5. Computing the Alpha from the CAPM


We are computing the alpha as a coefficient estimated in the following
regression (solved by Ordinary Least Squeares, OLS)

ri = i + i (rM ) +
where
ri = Ri r f
rM = RM r f

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:

Jess David Moreno (Associate Professor University Carlos III) 9/16


Mutual Funds Evaluation Using Matlab (Master in Finance, University Carlos III)

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

Second, we can analyze results by plotting them.

>> bar(alpha_J)

Jess David Moreno (Associate Professor University Carlos III) 10/16


Mutual Funds Evaluation Using Matlab (Master in Finance, University Carlos III)

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);

Alpha`s Jensen from Equity Mutual Funds


0.02

0.015

0.01
alpha

0.005

-0.005

-0.01
0 10 20 30 40 50 60
number of mutual fund

histogram from alpha`s Jensen


12

10

0
-0.01 -0.005 0 0.005 0.01 0.015 0.02

Jess David Moreno (Associate Professor University Carlos III) 11/16


Mutual Funds Evaluation Using Matlab (Master in Finance, University Carlos III)

6. Computing the Alpha from the FF model

We are computing the alpha as a coefficient estimated in the following


multivariate regression (solved by Ordinary Least Squeares, OLS)

Ri = i + i ( RM ) + SMB ( SMB ) + HML ( HML)


where
Ri = ri rf
RM = rM rf

To estimate that equation by OLS we use the function regstats.

[stats]=regstats(Y,X,'linear')

First, we need to crate the Y and X matrixes.

>> for j=1:55


>> Y=rMF2(:,j);
>> X= [rMk2, SMB, HML];
>> stats=regstats(Y, X,'linear');
>> coefic=stats.beta;
>> alphaFF(j,1)=coefic(1)
>> t_FF(j,1)=stats.tstat.t(1);
>> clear Y X coefic stats
>> end

Second, we can analyze results by plotting them.

>> bar(alphaFF)
>> hist(alphaFF)

Jess David Moreno (Associate Professor University Carlos III) 12/16


Mutual Funds Evaluation Using Matlab (Master in Finance, University Carlos III)

>> meanAlphaFF=mean(alphaFF);

Alpha`s FF model from Equity Mutual Funds


0.01

0.005

-0.005
alpha FF

-0.01

-0.015

-0.02

-0.025
0 10 20 30 40 50 60
number of mutual fund

histogram from alpha FF model


14

12

10

0
-0.025 -0.02 -0.015 -0.01 -0.005 0 0.005 0.01

Jess David Moreno (Associate Professor University Carlos III) 13/16


Mutual Funds Evaluation Using Matlab (Master in Finance, University Carlos III)

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

Difference among Alphas


0.015

0.01

0.005

-0.005

-0.01
0 10 20 30 40 50 60

Jess David Moreno (Associate Professor University Carlos III) 14/16


Mutual Funds Evaluation Using Matlab (Master in Finance, University Carlos III)

7. Making rankings and obtaining conclusions.

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.

>> [TreynorRank, TreynorRank2]=sort(Treynor)


>> [alphaRank, alphaRank2]=sort(alpha)
>> [alphaFFRank, alphaFFRank2]=sort(alphaFF)

Now, we can built a new matrix with the index of each funds in the
rankings computed previously.

>> TableRank=[SharpeRank2, TreynorRank2, alphaRank2, alphaFFRank2]

TableRank =
25 25 25 25
The worst fund
7 7 24 49
24 24 7 50

Jess David Moreno (Associate Professor University Carlos III) 15/16


Mutual Funds Evaluation Using Matlab (Master in Finance, University Carlos III)

27 17 27 52
17 27 19 38
19 49 49 37

33 33 33 33 The best fund

Finally, we can analyze all performance measures together using the


command subplot

>> subplot(2,2,1)
>> bar(Sharpe)
>> subplot(2,2,2)
>> bar(Treynor)....
>> .....

Sharpe Treynor
0.6 0.03

0.4 0.02

0.2 0.01

0 0

-0.2 -0.01
0 20 40 60 0 20 40 60

alpha alphaFF
0.02 0.01

0
0.01
-0.01
0
-0.02

-0.01 -0.03
0 20 40 60 0 20 40 60

Jess David Moreno (Associate Professor University Carlos III) 16/16

Вам также может понравиться