在MATLAB中计算c成熟。我怎么解决呢?

时间:2016-08-19 06:28:46

标签: matlab math

我有一个`x =(t * n)股票收益矩阵,n是投资组合中股票的数量,t是时间。我想要计算

c=M{[x(it)-k(x)][y(it)-k(y)]} 
 where x(it) 
  return of stock i in time t 
  and the median M is taken with respect to the joint CDF of x(t) 
  and y(t), and k(x) and k(y) are the population medians of x(t) and y(t)

例如:

x=[1 2 3;6 7 5;3 5 6;7 8 9]

x =

 1     2     3
 6     7     5
 3     5     6
 7     8     9

 t=size(x,1) 
 n=size(x,2)
 medianx=median(x)

 medianx =

   4.5000    6.0000    5.5000

 q=x-medianx(ones(t,1),:)

  q =

    -3.5000   -4.0000   -2.5000
     1.5000    1.0000   -0.5000
    -1.5000   -1.0000    0.5000
     2.5000    2.0000    3.5000

我可以在这里做到这一点,我不知道如何在matlab中达到c矩阵。我手动计算c:

c =

   4.2500    3.2500    4.0000
   3.2500    2.5000    3.2500
   4.0000    3.2500    3.2500

,其中

  c(11)=median of(column1*colum1 of matrix q)=4.25
  c(22)=median of(column2*colum2 of matrix q)=2.5
  c(33)=median of(column3*colum3 of matrix q)=3.25
  c(12) & c(21)=median of(column1*column2 of matrix q)=3.25
  c(13) & c(31)=median of(column1*column3 of matrix q)=4
  c(23) & c(32)=median of(column2*column3 of matrix q)=3.25

注意我有一个t * n矩阵,矩阵x就是一个例子。感谢

1 个答案:

答案 0 :(得分:0)

您可以使用以下方式从c计算q

c=zeros(3,3);  %Pre-allocation
for m=1:3
   for n=1:3
       c(m,n)= median(q(:,m).*q(:,n));
   end
end