Problem with age weighted historical simulation (Value at Risk and Expected Shortfall)

Hi,
Im having some problem with my code on age/time-weighted historical simulation when i am trying to calculate VaR and ES on a rolling sample. My calculated VaR is never violated by the actual losses, so there must be something wrong in my code. Any help is appriciated.
Thanks.
data = Nameofdataset
dataTT = table2timetable(data);
head(dataTT,5)
Losses = -data.change; (makes losses positive)
T = size(Nameofdataset);
rT = 500; (my estimation window)
Lambda = 0.94;
weight = zeros(rT,1);
alpha = 0.975;
w(rT) = (1-Lambda)/(1-Lambda^rT);
for j=1:rT
w(j) = w(rT)*Lambda^(rT-j);
end
for j =rT:1:T
rollSample = Losses(1:j,1);
twLossesRoll = timetable(dataTT.Datum(j-(rT-1):j),Losses(j-(rT-1):j),w,'VariableNames',{'Losses','w'});
sortedtwLossesRoll = sortrows(twLossesRoll,1,'descend');
sumW = 0;
sortedWRoll = sortedtwLossesRoll.w;
i = 1;
while sumW<(1-alpha)
sumW = sumW + sortedWRoll(i);
i = i + 1;
end
twVaRj(j-rT+1,1) = sortedtwLossesRoll.Losses(i-1);
twES(j-rT+1,1) = mean(sortedtwLossesRoll.Losses(1:i-1));
end

1 comentario

Not much (as in anything) anybody here can do w/ no idea what it is you're trying to do first and without any data.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Preguntada:

el 12 de Mayo de 2022

Comentada:

dpb
el 12 de Mayo de 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by