Computing the Nearest Correlation Matrix a Problem From Finance
This algorithm by Nicholas Higham finds the nearest correlation matrix given an example matrix. It does this by alternate projections onto unit diagonal and positive semidefinite matrices. The paper can be found via: http://citeseer.ist.psu.edu/higham02computing.html
Here are some matlab snippets for computing the nearest correlation matrix:
function [U] = projU(U)
x = size(U);
n = x(1,1);
for i=1:n
U(i,i) = 1;
end
function [M] = projS(A)
[V,D] = eig(A);
x = size(D);
n = x(1,1);
for i=1:n
D(i,i) = max(D(i,i), 0);
end
M = V*D*V’;
function [Y] = nearCorr(A)
temp = size(A);
n = temp(1,1);
deltaS = zeros(n);
Y = A;
X = A;
R = A;
for i=1:40
R = Y - deltaS;
X = projS(R);
deltaS = X - R;
Y = projU(X);
end