Matlab时变协方差矩阵环

时间:2014-06-19 22:42:02

标签: matlab matrix conditional covariance

我有资产组合,我喜欢计算投资组合的方差。我计算了资产的权重和协方差矩阵。两者都是时变的。为了得到方差,我需要下面的公式:

Wt'* SIGMA_1 * Wt =差异投资组合

在Matlab中,我使用以下代码计算每个资产的权重:

for t=1:n
    At_1(:,t)    = inv(SIGMA_1(:,:,t))*FIT_1';
    Wt_1(t,1)    = At_1(1,t)/sum(At_1(:,t));
    Wt_1(t,2)    = At_1(2,t)/sum(At_1(:,t));
    Wt_1(t,3)    = At_1(3,t)/sum(At_1(:,t));
    Wt_1(t,4)    = At_1(4,t)/sum(At_1(:,t));
    Wt_1(t,5)    = At_1(5,t)/sum(At_1(:,t));
    Wt_1(t,6)    = At_1(6,t)/sum(At_1(:,t));
    Wt_1(t,7)    = At_1(7,t)/sum(At_1(:,t));
    Wt_1(t,8)    = At_1(8,t)/sum(At_1(:,t));
    Wt_1(t,9)    = At_1(9,t)/sum(At_1(:,t));
    Wt_1(t,10)    = At_1(10,t)/sum(At_1(:,t));


end

其中SIGMA_1是协方差矩阵。 现在我需要一个循环来计算投资组合的时变方差。我有10个随时间变化的权重,以及时变协方差SIGMA_1。我为此写了一个循环。有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

你试过这个吗?

 for t=1:n
    At_1(:,t)    = inv(SIGMA_1(:,:,t))*FIT_1';

    for k=1:10
       Wt_1(t,k)    = At_1(k,t)/sum(At_1(:,t)); 
    end
 end