www.gusucode.com > econ 案例源码程序 matlab代码 > econ/EstimateTheCapitalAssestPricingModelUsingSURExample.m

    %% Estimate the Capital Asset Pricing Model Using SUR
% This example shows how to implement the capital asset pricing model (CAPM)
% using the Econometrics Toolbox(TM) multivariate time series framework. 
%%
% The CAPM model characterizes comovements between asset and market prices.
% Under this framework, individual asset returns are linearly associated
% with the return of the whole market (for details, see
% <docid:econ_ug.f0-2601>, <docid:econ_ug.brz_lcd>, and
% <docid:econ_ug.buwglyz>).  That is, given the return series of all
% stocks in a market ($M_t$) and the return of a riskless asset ($C_t$),
% the CAPM model for return series $j$ ($R_j$) is
%
% $$R_{jt} - C_t = a_j + b_j(M_t - C_t) + \varepsilon_{jt}$$
%
% for all assets $j = 1,...,n$ in the market.  
%%
% $a = [a_1\;...\; a_n]^\prime$ is an $n$-by-1 vector of _asset alphas_ that should
% be zero, and it is of interest to investigate assets whose asset alphas
% are significantly away from zero.
% $b = [b_1\;...\;b_n]^\prime$ is a $n$-by-1 vector of _asset betas_ that specify
% the degree of comovement between the asset being modeled and the market.
% An interpretation of element $j$ of $b$ is
%
% * If $b_j = 1$, then asset $j$ moves in the same direction and with the same volatility as the market, i.e., is positively
% correlated with the market .
% * If $b_j = -1$, then asset $j$ moves in the opposite direction, but with the same volatility as the market, i.e., is negatively correlated with the market. 
% * If $b_j = 0$, then asset $j$ is uncorrelated with the market.
%
% In general: 
%
% * ${\rm sign}(b_j)$ determines the direction that the asset is moving
% relative to the market as described in the previous bullets.
% * $|b_j|$ is the factor that determines how much more or less volatile
% asset $j$ is relative to the market.  For example, if $|b_j| = 10$, then
% asset $j$ is 10 times as volatile as the market.
%
%% Load and Process the Data
% Load the CAPM data set included in the Financial Toolbox(TM).
load CAPMuniverse
varWithNaNs = Assets(any(isnan(Data),1))
dateRange = datestr([Dates(1) Dates(end)])
%%
% The variable |Data| is a 1471-by-14 numeric matrix containing the daily
% returns of a set of 12 stocks (columns 1 through 12), one rickless asset
% (column 13), and the return of the whole market (column 14).  The returns
% were measured from 03Jan2000 through 07Nov2005.  |AMZN| and |GOOG| had
% their IPO during sampling, and so they have missing values.
%%
% Assign variables for the response and predictor series.
Y = bsxfun(@minus,Data(:,1:12),Data(:,14));
X = Data(:,13) - Data(:,14);
[T,n] = size(Y)
%%
% |Y| is a 1471-by-12 matrix of the returns adjusted by the riskless
% return.  |X| is a 1471-by-1 vector of the market return adjusted by the
% riskless return.  
%%
% Create block design matrices for each period, and put them into cells of
% a $T$-by-1 cell vector.  You can specify that each response series has
% its own intercept when you create the multivariate time series model
% object.  Therefore, do not consider the intercept when you create the
% block design matrices.
Design = kron(X,eye(n));
CellX = mat2cell(Design,n*ones(T,1));
nX = size(Design,2);
%% Create the Multivariate Time Series Model
% Create a multivariate time series model that characterizes the CAPM
% model.  You must specify the number of response series, whether to give
% each response series equation an intercept, and the number of regression
% variables.
Mdl = vgxset('n',n,'Constant',true,'nX',nX);
%%
% |Mdl| is a multivariate time series model object that characterizes the
% desired CAPM model.
%% Estimate the Multivariate Time Series Model
% Pass the CAPM model specification (|Mdl|), the response series (|Y|), and
% the cell vector of block design matrices (|CellX|) to |vgxvarx|.  Request
% to return the estimated multivariate time series model and the estimated
% coefficient standard errors.  |vgxvarx| maximizes the likelihood using
% the expectation-conditional-maximization (ECM) algorithm.  ECM
% accommodates missing response values directly (i.e., without imputation), but at
% the cost of computation time.
[EstMdl,EstCoeffSEMdl] = vgxvarx(Mdl,Y,CellX);
%%
% |EstMdl| and |EstCoeffSEMdl| have the same structure as |Mdl|, but |EstMdl|
% contains the parameter estimates and |EstCoeffSEMdl| contains the estimated
% standard errors of the parameter estimates.  |EstCoeffSEMdl|:
%
% * Contains the biased maximum likelihood standard errors.
% * Does not include the estimated standard errors of the intra-period
% covariances.  To include the standard errors of the intra-period
% covariances, specify the name-value pair |'StdErrType','all'| in
% |vgxvarx|.
%
%% Analyze Coefficient Estimates
%%
% Display the regression estimates, their standard errors, and their
% _t_ statistics.  By default, the software estimates, stores, and displays
% standard errors from maximum likelihood.  Specify to use the
% unbiased least squares standard errors.
dispMdl = vgxset(EstMdl,'Q',[]) % Suppress printing covariance estimates
vgxdisp(dispMdl,EstCoeffSEMdl,'DoFAdj',true)
%%
% To determine whether the parameters are significantly away from zero,
% suppose that a t statistic of 3 or more indicates significance.
%%
% Response series 6 has a significant asset alpha.
sigASymbol = Assets(6)
%%
% As a result, |GOOG| has exploitable economic properties.
%%
% All asset betas are greater than 3.  This indicates that all assets are
% significantly correlated with the market.
%%
% However, |GOOG| has an asset beta of approximately |0.62|, whereas all
% other asset betas are greater than 1.  This indicates that the magnitude
% of the volatility of |GOOG| is approximately 62% of the market
% volatility.  The reason for this is that |GOOG| steadily and almost
% consistently appreciated in value while the market experienced volatile
% horizontal movements.
%%
% For more details and an alternative analysis, see
% <docid:finance_examples.example-ex03245913>.