Using Expected Shortfall Estimation and Backtesting Code
Mostrar comentarios más antiguos
Hi All,
I use the following coding and would like to test it against the portfolio I have created. Unfortunately I get the same error every time:Array indices must be positive integers or logical values.
H = readtable('CAPM2.csv');
symbol = {'PBIT'};
nAsset = numel(symbol);
Convert prices to returns
Returns = (H{:,symbol});
Select assets into portfolio
symbol2 = {'Datum'};
Datum = (H{:,symbol2});
DateReturns = Datum(1:end);
SampleSize = length(Returns);
TestWindowStart = find(year(DateReturns)==2015,1);
TestWindowEnd = find(year(DateReturns)==2019,1,'last');
TestWindow = TestWindowStart:TestWindowEnd;
EstimationWindowSize = 250;
DatesTest = DateReturns(TestWindow);
ReturnsTest = Returns(TestWindow);
VaRLevel = 0.975;
VaR_Hist = zeros(length(TestWindow),1);
ES_Hist = zeros(length(TestWindow),1);
for t = TestWindow
i = t - TestWindowStart + 1;
EstimationWindow = t-EstimationWindowSize:t-1;
[VaR_Hist(i),ES_Hist(i)] = hHistoricalVaRES(Returns(EstimationWindow),VaRLevel);
end
Array indices must be positive integers or logical values.
The problem arises when creating the EstimationWindow. The result is always negative. Unfortunately I have already tried to convert it to positive, unfortunately without success.
2 comentarios
Sai Sri Pathuri
el 29 de Abr. de 2020
Can you attach the file 'CAPM2.csv'?
jens pauwels
el 29 de Abr. de 2020
Respuestas (1)
Sai Sri Pathuri
el 29 de Abr. de 2020
I am assuming that you want to declare EstimationWindow as first 250 indices for t = 1 and shift it by 1 for every loop. The window you declared is,
EstimationWindow = t-EstimationWindowSize:t-1;
For t = 1, this EstimationWindow will take the values -249 to 0. But, in MATLAB, the indices start from 1. Hence, the error is being thrown. You may declare the EstimationWindow as
EstimationWindow = t:EstimationWindowSize-t+1;
Categorías
Más información sobre Market Risk en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!