Filter löschen
Filter löschen

ARIMA BIC LOOP including "zero"

1 Ansicht (letzte 30 Tage)
polar
polar am 30 Nov. 2016
Kommentiert: Brendan Hamm am 30 Nov. 2016
Hi, I found a script aimed to find the best arima(p,0,d) model as the one with the lowest BIC(or AIC) value in order to use a trading strategy based on ARIMA/GARCH model.
Here I report the code found (including my data):
Currency=xlsread('EURUSD.xls','exchange','A:B');
eur=Currency;
LOGL = zeros(4,4);
PQ = zeros(4,4);
for p = 1:4
for q = 1:4
mod = arima(p,0,q);
[fit,~,logL] = estimate(mod,eur,'print',false);
LOGL(p,q) = logL;
PQ(p,q) = p+q;
end
end
LOGL = reshape(LOGL,16,1);
PQ = reshape(PQ,16,1);
[~,bic] = aicbic(LOGL,PQ+1,100);
reshape(bic,4,4)
Ok, it works but in my case, I had already found out that an ARIMA (1,0,0) was the best fit,so my target is to include the "zero" value for "p" or "q" for future needs. The problem is that when p AND q are both zero, it clearly shows error. So I started using "continue" to skip the arima(0,0,0) and compute all other ones but...I always failed (I'm very poor in programming). If someone can help me.... ps: I'm helping myself with a "R" script but obviously I'm using Matlab :-)

Akzeptierte Antwort

Brendan Hamm
Brendan Hamm am 30 Nov. 2016
If you changed the loop to start at 0, you are trying to index LOGL and PQ at the index 0 which does not exist. MATLAB starts indexing at 1.
First pre-allocate the additional space:
LOGL = zeros(5,5);
PQ = zeros(5,5);
Error:
for p = 0:4
for q = 0:4
mod = arima(p,0,q);
[fit,~,logL] = estimate(mod,eur,'print',false);
LOGL(p,q) = logL;
PQ(p,q) = p+q;
end
end
So increase the indices by 1.
No Error:
for p = 0:4
for q = 0:4
mod = arima(p,0,q);
[fit,~,logL] = estimate(mod,eur,'print',false);
LOGL(p+1,q+1) = logL; % Index at the next row/col
PQ(p+1,q+1) = p+q; % Index at the next row/col
end
end
Bear in mind that now the log-likelihood of the ARIMA(2,0,3) model is in LOGL(3,4)
  2 Kommentare
polar
polar am 30 Nov. 2016
Very thanks Brendan I was stuck with the "continue" function in the loop, but your changes made it work! Thanks again!
Brendan Hamm
Brendan Hamm am 30 Nov. 2016
If this solved your problem please formally Accept this answer.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Conditional Mean Models finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by