I tried to create covariance matrices over an rolling window to calculate the portfolio weights for the next period of time.
covMat = cov(mon_ret) ;
[corMat, std] = corrcov(covMat);
port_size = length(covMat) ;
Aeq = ones(1,port_size);
Beq = 1;
lbnds = zeros(1,port_size);
ubnds = ones (1,port_size);
n = 70;
m = 60;
n1 = 1.0/port_size;
w0 = repmat(n1, port_size, 1);
for mth = 1 : n - m
covMat_1 = arrayfun(@(k)cov(mon_ret(k:m+k-1,:)),1:(n-m+1),'UniformOutput',false);
mvfunction = @(w_mv) mv(covMat_1{1,mth}, w_mv);
w_mv_1 = arrayfun(@(w_mv)fmincon(mvfunction, w0, ...
[], [], Aeq, Beq, lbnds, ubnds, []),1:(n-m+1),'UniformOutput',false) ;
end
So covMat_1 delivers an 1X11 "cell" with each cell containing the covariance matrix for specific rolling window.
But when I am trying to create the variable w_mv_1 with the goal to get all new calculated portfolio weights in it, I get an 1X11 "cell" with each cell containing the weights calcualted for the first covariance matrix from covMat_1 (covMat{1,1}).
Can anybody help me out fixing this so that I get the weights for the respective rolling window?
I'd appreciate every help.
Best regards