Can anyone help me calculating the average covariance of return?
조회 수: 4 (최근 30일)
이전 댓글 표시
- Hi everyone. I'm trying to convert this formula into MatLab code:
where :
Fcvc is a target matrix used for shrinking the sample covariance matrix of return towards their average variance and average covariance, in order to obtain a better estimator. The topic is fromt De Nard paper "Oops! I Shrunk the Sample Covariance Matrix Again: Blockbuster Meets Shrinkage"
I don't know how to compute the average covariance (average of off-diagonal entries of a simmetric matrix), can anyone help me?
댓글 수: 0
답변 (1개)
William Rose
2022년 10월 27일
편집: William Rose
2022년 10월 27일
[Edit: change the name of the initial matrix; it should not be Fcvc, it should be S. Add code to construct Fcvc using the which we calculate.]
You can just write a nested for loop (i,j) that does the calculation:
%Make a 4x4 covariance matrix
N=4; S=eye(N); %identity matrix
for i=1:N,
for j=i+1:N
S(i,j)=-1+2*rand(1,1);
S(j,i)=S(i,j);
end
end
S=10*S %multiply by some arbitray constant
That looks like a reasonable covariance matrix: it is positive along the diagonal, and the absolute value of off-diagonal element are less than the diagoonal, and it is symmetric.
Now compute and :
siibar=sum(sum(S))/N^2;
sijbar=0;
for i=1:N
for j=i+1:N
sijbar=sijbar+S(i,j);
end
end
sijbar=sijbar/((N^2-N)/2);
fprintf('siibar=%.4f, sijbar=%.4f\n',siibar,sijbar)
Those values look reasonable.
Use siibar and sijbar to make Fcvc
Fcvc=sijbar*(ones(N)-eye(N))+siibar*eye(N)
That looks good.
댓글 수: 2
William Rose
2022년 10월 27일
You may note that when calculating sijbar = , I added up the values on one side of the diagonal, then divided by (N^2-N)/2. In the formula you quoted, they added up the values on both sides of the diagonal and divided by (N^2-N). Since the matrix is symmetric (covariance matrices are alway ssymmetric), the result is the same for these two different ways of doing it.
참고 항목
카테고리
Help Center 및 File Exchange에서 Financial Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!