covariance and correlation
Mostrar comentarios más antiguos
Hi everybody, I have a 2 time series returns of 1x789 size (X and Y).
I want to compare how similar they are and for this want to calculate the covariance and correlation. Could anybody please show me the code on how to do this?
Best wishes,
Respuesta aceptada
Más respuestas (1)
Satadru Mukherjee
el 30 de Mzo. de 2020
Editada: Satadru Mukherjee
el 30 de Mzo. de 2020
0 votos
Execute the below code , in th cova variable covariance & in the corr variable , correlation result will be stored...
clc
clear all
close all
x=input('Enter the data points:');
a1=mean(x);
z=[];
for i=1:length(x)
z=[z (x(i)-a1)^2];
end
s1=sum(z);
s1=s1/(length(x)-1);
s1=sqrt(s1);
y=input('Enter the data points:');
a2=mean(y);
z=[];
for i=1:length(y)
z=[z (y(i)-a2)^2];
end
s2=sum(z);
s2=s2/(length(x)-1);
s2=sqrt(s2);
x=x-a1;
y=y-a2;
ak=x*y';
cova=ak/(length(x)-1);
corr=cova/(s1*s2);
Categorías
Más información sobre Correlation and Convolution en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!