Expected Shortfall for asset returns
显示 更早的评论
Hi everybody!!!
I'm trying to compute the Conditional VaR (Expected Shortfall) for some funds' returns. I have a large matrix (time series) of returns (132x1773) where 132 indicates the number of months and 1773 the number of funds. For those values has been quite easy to compute the Value at Risk for each fund but now I need to compute the conditional one.
As theory suggets, CVaR is the mean of the values above the VaR itself but I'm having lots of trouble ciomputing it.
I already tried 1) storing the value in a matrix with a for loop but since each fund has different number of values below tha VaR, the storage matrix is no more a matrix and 2) using the find function
I'll try to write down some codes to make it easier to understand:
Ret %is my 132x1773 matrix of returns
VaR %is my 1x1773 row vector
[rownum, columnum] = size(Ret);
store = zeros(1,columnum)
for i = 1:columnum
ind(i) = find(Ret(:,i)>VaR(i))
Ret(:,ind(i)) = [];
CVaR(i) = mean(Ret(:,i));
end
Unable to perform assignment because the indices on the left side are not compatible with the size of the
right side.
Thanks a lot in advance!!!
采纳的回答
更多回答(1 个)
KSSV
2022-6-15
[rownum, columnum] = size(Ret);
store = zeros(1,columnum)
CVaR = cell(columnum,1) ;
for i = 1:columnum
ind(i) = find(Ret(:,i)>VaR(i))
Ret(:,ind(i)) = [];
CVaR{i} = mean(Ret(:,i));
end
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!