-
Notifications
You must be signed in to change notification settings - Fork 0
/
desvioARIMA.m
48 lines (31 loc) · 1.42 KB
/
desvioARIMA.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function desvioPadrao = desvioARIMA(B, p, sigmahat, numPrev)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
% Cálculos baseados nas págs.252-256 do livro "Forecasting with UBJ Models", Alan Pankratz
ARcoefs = B(1:p,1);
MAcoefs = B(p+1:end,1);
desvioPadrao = zeros(1,numPrev); % vector-linha para armazenar um valor de desvio associado a cada previsão
%% CÁLCULO DE ROOT-MEAN-SQUARED ERROR (RMSE)
% n = length(resid);
% m = length([ARcoefs; MAcoefs]);
% RMSE = ( 1/(n-m) )* sum( resid.^2 );
%% CÁLCULO DOS COEFS. PSI()
PSIcoefs = zeros(1,numPrev);
PSIcoefs(1,1) = 1;
% MA() PURO
if (isempty(ARcoefs)==1)
PSIcoefs = [ 1, -1.*(MAcoefs'), zeros(1,numPrev-length(MAcoefs)) ]; % SEM CERTEZAS
% AR() COM/SEM MA()
elseif (isempty(ARcoefs)~=1) && (numPrev>1)
PSIcoefs(1,2) = ARcoefs(1,1) - sum(MAcoefs); % SEM CERTEZAS
for a=3:1:numPrev
for b=1:1: min( length(ARcoefs),a-1 )
PSIcoefs(1,a) = PSIcoefs(1,a) + ARcoefs(b)*PSIcoefs(a-b);
end
end
end
%% CÁLCULO FINAL DO DESVIO-PADRÃO DE CADA FORECAST
for a=1:1:numPrev
desvioPadrao(1,a) = sigmahat*sqrt( sum( PSIcoefs(1,1:a).^2 )); % NOTA: sqrt(RMSE) = std(resid)
end
end