Skip to main content
added 32 characters in body
Source Link
SRKX
  • 11.2k
  • 4
  • 42
  • 84
% overlapping rolling covariance
[n,m] = size(returns_sec); % n-> number of dates, m->number of assets
rolling_window = 10;
cov_test = nan(m*(n - rolling_window + 1),m);
for i = rolling_window:n
    start_index = m*(i - rolling_window) + 1; % aggregate covariance matrix start index
    end_index = m*(i - rolling_window +1); % aggregate covariance matrix end index
    covariance_mtx = cov(returns_sec(i-rolling_window +1:i,:));
    cov_test(start_index:end_index,:) = covariance_mtx;
end

% non-overlapping rolling covariance
[n,m] = size(returns_sec); % n-> numberg of dates, m->number of assets
rolling_window = 10;
num = floor(n/rolling_window); % number of non-overllaping intervals
cov_test = nan(m*num,m);
for i = 1:num
    start_index = m*(i - 1) + 1; % aggregate covariance matrix start index
    end_index = m*i; % aggregate covariance matrix end index
    covariance_mtx = cov(returns_sec(rolling_window*(i - 1) + 1: rolling_window*i,:));
    cov_test(start_index:end_index,:) = covariance_mtx;
end
% overlapping rolling covariance
[n,m] = size(returns_sec); % n-> number of dates, m->number of assets
rolling_window = 10;
cov_test = nan(m*(n - rolling_window + 1),m);
for i = rolling_window:n
    start_index = m*(i - rolling_window) + 1; % aggregate covariance matrix start index
    end_index = m*(i - rolling_window +1); % aggregate covariance matrix end index
    covariance_mtx = cov(returns_sec(i-rolling_window +1:i,:));
    cov_test(start_index:end_index,:) = covariance_mtx;
end

% non-overlapping rolling covariance
[n,m] = size(returns_sec); % n-> numberg of dates, m->number of assets
rolling_window = 10;
num = floor(n/rolling_window); % number of non-overllaping intervals
cov_test = nan(m*num,m);
for i = 1:num
    start_index = m*(i - 1) + 1; % aggregate covariance matrix start index
    end_index = m*i; % aggregate covariance matrix end index
    covariance_mtx = cov(returns_sec(rolling_window*(i - 1) + 1: rolling_window*i,:));
    cov_test(start_index:end_index,:) = covariance_mtx;
end
% overlapping rolling covariance
[n,m] = size(returns_sec); % n-> number of dates, m->number of assets
rolling_window = 10;
cov_test = nan(m*(n - rolling_window + 1),m);
for i = rolling_window:n
    start_index = m*(i - rolling_window) + 1; % aggregate covariance matrix start index
    end_index = m*(i - rolling_window +1); % aggregate covariance matrix end index
    covariance_mtx = cov(returns_sec(i-rolling_window +1:i,:));
    cov_test(start_index:end_index,:) = covariance_mtx;
end

% non-overlapping rolling covariance
[n,m] = size(returns_sec); % n-> numberg of dates, m->number of assets
rolling_window = 10;
num = floor(n/rolling_window); % number of non-overllaping intervals
cov_test = nan(m*num,m);
for i = 1:num
    start_index = m*(i - 1) + 1; % aggregate covariance matrix start index
    end_index = m*i; % aggregate covariance matrix end index
    covariance_mtx = cov(returns_sec(rolling_window*(i - 1) + 1: rolling_window*i,:));
    cov_test(start_index:end_index,:) = covariance_mtx;
end
% overlapping rolling covariance
[n,m] = size(returns_sec); % n-> number of dates, m->number of assets
rolling_window = 10;
cov_test = nan(m*(n - rolling_window + 1),m);
for i = rolling_window:n
    start_index = m*(i - rolling_window) + 1; % aggregate covariance matrix start index
    end_index = m*(i - rolling_window +1); % aggregate covariance matrix end index
    covariance_mtx = cov(returns_sec(i-rolling_window +1:i,:));
    cov_test(start_index:end_index,:) = covariance_mtx;
end

% non-overlapping rolling covariance
[n,m] = size(returns_sec); % n-> numberg of dates, m->number of assets
rolling_window = 10;
num = floor(n/rolling_window); % number of non-overllaping intervals
cov_test = nan(m*num,m);
for i = 1:num
    start_index = m*(i - 1) + 1; % aggregate covariance matrix start index
    end_index = m*i; % aggregate covariance matrix end index
    covariance_mtx = cov(returns_sec(rolling_window*(i - 1) + 1: rolling_window*i,:));
    cov_test(start_index:end_index,:) = covariance_mtx;
end
deleted 1 character in body
Source Link
user18489
user18489

I would recommend you to use rolling overlapping window (1st implementation) instead of non-overllapingoverlapping (your example - 2nd implementation)

% overlapping rolling covariance
[n,m] = size(returns_sec); % n-> numbergnumber of dates, m->number of assets
rolling_window = 10;
cov_test = nan(m*(n - rolling_window + 1),m);
for i = rolling_window:n
    start_index = m*(i - rolling_window) + 1; % aggregate covariance matrix start index
    end_index = m*(i - rolling_window +1); % aggregate covariance matrix end index
    covariance_mtx = cov(returns_sec(i-rolling_window +1:i,:));
    cov_test(start_index:end_index,:) = covariance_mtx;
end

% non-overlapping rolling covariance
[n,m] = size(returns_sec); % n-> numberg of dates, m->number of assets
rolling_window = 10;
num = floor(n/rolling_window); % number of non-overllaping intervals
cov_test = nan(m*num,m);
for i = 1:num
    start_index = m*(i - 1) + 1; % aggregate covariance matrix start index
    end_index = m*i; % aggregate covariance matrix end index
    covariance_mtx = cov(returns_sec(rolling_window*(i - 1) + 1: rolling_window*i,:));
    cov_test(start_index:end_index,:) = covariance_mtx;
end

I would recommend you to use rolling overlapping window (1st implementation) instead of non-overllaping (your example - 2nd implementation)

% overlapping rolling covariance
[n,m] = size(returns_sec); % n-> numberg of dates, m->number of assets
rolling_window = 10;
cov_test = nan(m*(n - rolling_window + 1),m);
for i = rolling_window:n
    start_index = m*(i - rolling_window) + 1; % aggregate covariance matrix start index
    end_index = m*(i - rolling_window +1); % aggregate covariance matrix end index
    covariance_mtx = cov(returns_sec(i-rolling_window +1:i,:));
    cov_test(start_index:end_index,:) = covariance_mtx;
end

% non-overlapping rolling covariance
[n,m] = size(returns_sec); % n-> numberg of dates, m->number of assets
rolling_window = 10;
num = floor(n/rolling_window); % number of non-overllaping intervals
cov_test = nan(m*num,m);
for i = 1:num
    start_index = m*(i - 1) + 1; % aggregate covariance matrix start index
    end_index = m*i; % aggregate covariance matrix end index
    covariance_mtx = cov(returns_sec(rolling_window*(i - 1) + 1: rolling_window*i,:));
    cov_test(start_index:end_index,:) = covariance_mtx;
end

I would recommend you to use rolling overlapping window (1st implementation) instead of non-overlapping (your example - 2nd implementation)

% overlapping rolling covariance
[n,m] = size(returns_sec); % n-> number of dates, m->number of assets
rolling_window = 10;
cov_test = nan(m*(n - rolling_window + 1),m);
for i = rolling_window:n
    start_index = m*(i - rolling_window) + 1; % aggregate covariance matrix start index
    end_index = m*(i - rolling_window +1); % aggregate covariance matrix end index
    covariance_mtx = cov(returns_sec(i-rolling_window +1:i,:));
    cov_test(start_index:end_index,:) = covariance_mtx;
end

% non-overlapping rolling covariance
[n,m] = size(returns_sec); % n-> numberg of dates, m->number of assets
rolling_window = 10;
num = floor(n/rolling_window); % number of non-overllaping intervals
cov_test = nan(m*num,m);
for i = 1:num
    start_index = m*(i - 1) + 1; % aggregate covariance matrix start index
    end_index = m*i; % aggregate covariance matrix end index
    covariance_mtx = cov(returns_sec(rolling_window*(i - 1) + 1: rolling_window*i,:));
    cov_test(start_index:end_index,:) = covariance_mtx;
end
Source Link
user18489
user18489

I would recommend you to use rolling overlapping window (1st implementation) instead of non-overllaping (your example - 2nd implementation)

% overlapping rolling covariance
[n,m] = size(returns_sec); % n-> numberg of dates, m->number of assets
rolling_window = 10;
cov_test = nan(m*(n - rolling_window + 1),m);
for i = rolling_window:n
    start_index = m*(i - rolling_window) + 1; % aggregate covariance matrix start index
    end_index = m*(i - rolling_window +1); % aggregate covariance matrix end index
    covariance_mtx = cov(returns_sec(i-rolling_window +1:i,:));
    cov_test(start_index:end_index,:) = covariance_mtx;
end

% non-overlapping rolling covariance
[n,m] = size(returns_sec); % n-> numberg of dates, m->number of assets
rolling_window = 10;
num = floor(n/rolling_window); % number of non-overllaping intervals
cov_test = nan(m*num,m);
for i = 1:num
    start_index = m*(i - 1) + 1; % aggregate covariance matrix start index
    end_index = m*i; % aggregate covariance matrix end index
    covariance_mtx = cov(returns_sec(rolling_window*(i - 1) + 1: rolling_window*i,:));
    cov_test(start_index:end_index,:) = covariance_mtx;
end