0

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

Dirty Dan
  • 15
  • 5

1 Answers1

0

To whom it might concern, I figuered out how to do it.

First of all the value of variable w_mv_1 was a cell array that contained not the weigths of the first covariance matrix but the tenth.

Anyways this is the solution:

covMat_1 = arrayfun(@(k)cov(mon_ret(k:m+k-1,:)),1:(n-m+1),'UniformOutput',false);
w_mv_1 = arrayfun(@(k)fmincon(@(w_mv) mv(covMat_1{1,k}, w_mv), w0, ...
    [], [], Aeq, Beq, lbnds, ubnds, []),1:(n-m+1),'UniformOutput',false) ;

Apparently there was a problem with "arrayfun" as I put the wrong variable into it. With this code it works without the for-loop.

Dirty Dan
  • 15
  • 5