This project is read-only.

moving correlations

Topics: Database Management, Times Series
Jun 25, 2014 at 11:32 PM
Hello. Is there a way to compute moving correlations with a given variable within a database? Say if a database has 300 variables and I want to create a database of 10 year moving correlations of the 299 variables with the remaining variable in the dataset. Please advise.
Jun 26, 2014 at 9:42 PM
Edited Jun 26, 2014 at 9:43 PM
The most straightforward way is simply the following nested loops
% Let's say this is your database:
d = struct();
d.x = tseries(yy(1970):qq(2014),@rand);
d.y = tseries(yy(1970):qq(2014),@rand);
d.z = tseries(yy(1970):qq(2014),@rand);
d.u = tseries(yy(1970):qq(2014),@rand);
d.w = tseries(yy(1970):qq(2014),@rand);

% Here, compute the 10-year moving corr coefficients between x and every other series:
list = fieldnames(d);
for i = 1 : length(list)
    name = list{i};
    corr_name = ['corr_x','_',name];
    d.(corr_name) = tseries();
    for t = yy(1979) : yy(2014)
        c = corrcoef(d.x(t-9:t),d.(name)(t-9:t));
        d.(corr_name)(t) = c(2,1);
Marked as answer by jaromirbenes on 6/26/2014 at 1:43 PM
Jun 26, 2014 at 9:43 PM

Great. Many thanks Jaromir.