Expected Shortfall for asset returns
Mostra commenti meno recenti
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!!!
Risposta accettata
Più risposte (1)
KSSV
il 15 Giu 2022
[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
1 Commento
Marco Piazza
il 15 Giu 2022
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!