//
//arma command. 
//
//This command is used for arma modeling that is binded  AR(Auto Regression) and MA(Moving Average Model)
//

//Syntax 
arma data/
(options)
;

//Options
ar:xx     //Auto regression degree(default 5).
ma:yy     //Moving average degree(default 5).
predict=xx   //xx is predicting period using fourie transform(default 0).

//Example 
get stockdata.csv@;
plot line data1;

if(# > 229) delrec //This wave has 250 steps,and 229 steps are trainning step. put train; //use tmtrend command for fitting 229 step and predicting 21 step using 4 degree spline. get train; tmtrend data1/ dim=4 period=21 ; anaput traintrend; get traintrend; plot line data1 data1_T dataTC; //data1 is original wave; //data1_T is the spline curve fitting orignal wave; //data1TC is different value meaning data1 - data_T.

//using fourie transform for steady long priod fitting with cuting higher frequency. fourie data1TC/ method=fft kind=trans predict=21 ; anaput freqData; plot line data1TC/ color=blue ;

//Cuting 30 higher frequency to get long period curve get freqdata; if(# >= 30) data1TC=0; put cutData; //Reverse fourie transform to get long period curve. get cutData; fourie data1TC/ kind=rev ; anaput cutWave; get cutWave; //rename logn frequency curve. attr name rename/ data1TC data1FR ; plot line data1FR;

//ploting long period curve to difference value of data1 and trend. merge trainTrend by #; plot line data1 data1_T data1TC data1FR; put data1FRQ; //In the Figuer data1FR curve is long period curve for fitting difference value.

//Get residual value of actual data and trend curve + long period curve. get data1FRQ; if(# > 229) delrec; data1Zan=data1-data1_T-data1FR; put data1Zan; //Usage arma model for residual curve. get data1Zan; arma data1Zan/ ar=5 ma=5 predict=21 ; anaput armaWave; //Rename arma model curve. get armaWave; attr name rename/ data1Zan data1arma ; plot line data1arma; merge data1FRQ by #; //Composing trend curve + long period curve + arma curve data1Comp=data1_T+data1FR+data1arma; put data1Comp; //To compare actual curve, merge acutal cuve. merge stockdata.csv@ by #; //Comparison predict period of actual curve with trend+fourie+arma model plot line data1 data1Comp;

put data1Predict;