% Solution to Correlation Question

% Read in data and generate correlation matrix
format short
[x,ifail] = getcorrelation

% Set correlation between 1st and 10th stocks
x(1,10) = 0.2;
x(10,1) = 0.2;

% Test for true correlation matix
smallest = min(eig(x))
if (smallest < 0)
   fprintf(' Matrix is not a correlation matrix,\n');
   fprintf(' there are negative eigenvalues\n');
end

% Generate nearest correlation matrix
[c, ifail] = getnearest(x)
smallest = min(eig(c))