When working in Matlab, I'm receiving this warning...
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 6.001064e-34.
Here is my code...
clear
clc
P = [];
X = importdata('MSFT.csv',',');
P = [P X.data(:,5)];
X = importdata('ORCL.csv',',');
P = [P X.data(:,5)];
X = importdata('TEVA.csv',',');
P = [P X.data(:,5)];
TCR = {'msft', 'orcl', 'teva'};
N = 252;
r_ar = P(2:end, :)./P(1:end-1, :) - 1;
mu_d = mean(r_ar(1:end, :));
sigma_d = cov(r_ar(1:end, :));
mu_a = (mu_d + 1).^N -1;
sigma_a =
(sigma_d + (mu_d'+1)*(mu_d+1)).^N - (mu_d'+1).^N * (mu_d+1).^N;
rho =inv(sqrt(diag(diag(sigma_a))))*sigma_a*inv(sqrt(diag(diag(sigma_a))));
mu = mu_a';
S1 = inv(sigma_a);
The Warning is given for the line,
S1 = inv(sigma_a);
As I need to take the inverse of the sigma_a matrix is there any way to fix this warning? It's effecting other parts of my code.