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

%reference

%the most general methodology to create a valid correlation matrix for risk
management and option pricing purposes
%riccardo rebonato, peter j�ackel, quantitative research centre of the natwest
group, 19 th october 1999
%http://www.quarchome.org/correlationmatrix.pdf

n=40; %dimension of the correlation matrix


%generating random correlation matrix
k=(rand(n)*2-1); k=(k+k')/2; %random symmetric matrix
c=k.*not(eye(n))+eye(n) %principal diagonal elements set to
unity

%spectral decomposition
[cvec, cval]=eig(c); %original eigenvectors and
eigenvalues stored
cval_colvector=eig(c); %eigenvales in a column vector
postest=cval_colvector>=0 %testing if all eigenvalues are
non-negative
%cval_colvector_cor=cval_colvector.*postest; %setting -ve eigenvalues to
zero
cval_colvector_cor=cval_colvector.*postest + (not(postest)*0.00000001); %setting
-ve eigenvalues to a very small positive value
cval_cor=cval_colvector_cor*ones(1, n).*eye(n); %corrected eigenvalue matrix

bdash=cvec.*((ones(n)*cval_cor).^0.5); %eigenvector scaled by


"square root of" individual corrected eigenvalues.
b=bdash./repmat(sum((bdash.^2),2).^0.5, 1, n); %normalized to have row
vectors of unit length
cdash=b*b'

%simpler alternate approach to above three lines


t=repmat(sum(cvec.*cvec.*repmat(cval_colvector_cor', n, 1), 2).^(-1), 1,
n).*eye(n); %diagonal scaling matrix
b_alternate=(t.^0.5)*cvec*(cval_cor.^0.5);
cdash_alternate=b_alternate*b_alternate';

chol(cdash)

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