ARIMA BIC LOOP including "zero"

2 次查看(过去 30 天)
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 :-)

采纳的回答

Brendan Hamm
Brendan Hamm 2016-11-30
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 个评论
polar
polar 2016-11-30
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 2016-11-30
If this solved your problem please formally Accept this answer.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Conditional Variance Models 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by