LEAST SQUARES Estimation code

Anybody know the code to estimate an ARMA model using LEAST SQUARES?
Thanks.

 Risposta accettata

Shashank Prasanna
Shashank Prasanna il 8 Feb 2013
Modificato: Shashank Prasanna il 8 Feb 2013
To show you an example I am going to generate some data from the following ARMA model. I am generating this using the ARIMA function in the econometrics toolbox. If you don't have it don't worry because I am using this data to demonstrate how to estimate the coefficients using least squares. How ever I would like to inform you that that a more popular approach is to use MLE.
Generate some data to simulate.
Here AR lag 1, coeff 0.3
MA lag 1, coeff 0.2
rng(5);
simModel = arima('AR',0.3,'MA',0.2,'Constant',0,'Variance',1);
% simModel = arima('AR',0.4,'Constant',0,'Variance',1);
Y = simulate(simModel,500);
The following code will estimate the coefficients using least squares using MATLAB's \ operator.
>> rng(5);
inn=randn(500,1);
[Y -[0;Y(1:end-1)] -[0;inn(1:end-1)]]\inn
ans =
1.0000
0.3000
0.2000
The first number is for y(t) which is 1. the AR is 0.3 and MA is 0.2.

3 Commenti

dav
dav il 8 Feb 2013
Thank you very much.
since I am still new to matlab I still have to understand the following:
does rng mean - random number generator? what does 5 do? what is inn and how do you get that equation?
It may be hard to answer all the above question. So would you please let me know of a good place to read on those functions.
Thanks.
Ps- I know MLe is the popular method. However, I have to do this using matlab.
RNG is used to set the random number generator seed, it could be anything, i just used 5. Notice that I reuse it again while I estimate so that I use the exact same random numbers during estimation that I used during data generation.
inn is commonly known as innovations or error terms, and it is assumed to be white noise or normally distributed with 0 mean 1 var, but could be something else. i use the randn function to generate some inn. The equation I used is just the solution to a linear system Ax=b which can be solved in MATLAB for x by performing A\b.
Lastly, MLE is indeed a popular mathod and MATLAB is capable to solving MLEs as long as you formulate you problem that way. search documentation for MLE
hth
dav
dav il 16 Feb 2013
Thanks alot. what I really have to do is as follows. I used the following R code to estimate ARMA model. Note that first, I have generated a garch data set. Now, according to a theory I know epsi^2 has an ARMA model. So when when I estimate epsi^2 using LEAST SQUARES, I should get parameter estimates close to the same parameter values of the GARCH model. I have to have an additional condition that constraint that parameter estimates are greater than zero. I am actually trying to write a code to do step 1 of the paper titled " computationally efficient bootstrap prediction intervals for arch and garch processes " by Bei Cheng.
If you could help me with this, it is greatly appreciated.
R CODE: a0 = 0.05; a1 = 0.1; b1 = 0.85
nu = rnorm(2300)
epsi = rep(0, 2300)
h = rep(0, 2300)
for (i in 2: 2300) { h[i] = a0 + a1 * epsi[i-1]^2 + b1 * h[i-1] ; epsi[i] = nu[i] * sqrt(h[i])}
epsi = epsi[2001:2300]
epsi=epsi*epsi
arma(epsi,order=c(1,1))
(my problem with using R is that it doent have enough memory to do the entire process)

Accedi per commentare.

Più risposte (1)

Azzi Abdelmalek
Azzi Abdelmalek il 7 Feb 2013

1 voto

4 Commenti

dav
dav il 7 Feb 2013
I am somewhat new to matlab. Is it possible for you to give me an example code so that I can understand it easily.
Suppose the order is (1 , 1). I want to estimate the parameters using least squares.
Thanks
the order is (1 , 1).? It's not clear, the order of your system is the order of your denominator
Azzi Abdelmalek
Azzi Abdelmalek il 7 Feb 2013
Modificato: Azzi Abdelmalek il 7 Feb 2013
% n: is the order of your system
% u: input signal
% y : output signal
k1=5 % k1 >n
k2=30
teta=least_square(u,y,n,k1,k2)
yem
yem il 16 Dic 2014
hi i need to identify systems with 2 delays with least square algorithm anyhelp please

Accedi per commentare.

Richiesto:

dav
il 7 Feb 2013

Commentato:

yem
il 16 Dic 2014

Community Treasure Hunt

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

Start Hunting!

Translated by