% 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