SSRN-id1523045

2
Electronic copy available at: http://ssrn.com/abstract=1523045 '=================================================================== 'This code select the best ARMA(p,q) model based on Schwarz criterion and Akaike criterion 'Copy your data in drive "c:\", data must have a "data" name and "xls" format and contain one 'column, the first cell of that column must have a name "x1" 'You can choose max lag of AR terms and MA terms by changing the right hand side of ' equations "!maxp=3" and "!maxq=3" 'Table "results_sc" contain Schwarz criterion for each ARMA(p,q) and "results_aic" contain ' Akaike criterion, the best model is determined automatically 'Good lock '=================================================================== 'Adapted by Moslem Peymany 'PHD of Finance, Allameh Tabatabai Uneversity, Faculty of Accounting and Management 'Tehran, Iran '[email protected] '=================================================================== 'Reading data wfopen "c:\data.xls" series data=x1 '-------------------------------------------------------------------------------------------------------------------------------------- 'Determining max lag of AR terms (p) and MA terms (q) !maxp=3 !maxq=3 '-------------------------------------------------------------------------------------------------------------------------------------- 'Preparing a matrix for necessary calculations, this matrix will be deleted at the end of code matrix(!maxp+1,!maxq+1) m_sc matrix(!maxp+1,!maxq+1) m_aic '-------------------------------------------------------------------------------------------------------------------------------------- 'Preparing tables to show results table (!maxp+5,!maxq+2) results_sc setline(results_sc,2) setline(results_sc,!maxp+4) results_sc(1,1)="SBC" results_sc(3,2)="---" table (!maxp+5,!maxq+2) results_aic setline(results_aic,2) setline(results_aic,!maxp+4) results_aic(1,1)="AIC" results_aic(3,2)="---" for !i=0 to !maxp results_sc(!i+3,1)="AR("+@str(!i)+")" results_aic(!i+3,1)="AR("+@str(!i)+")" next for !i=0 to !maxq results_sc(1,!i+2)="MA("+@str(!i)+")" results_aic(1,!i+2)="MA("+@str(!i)+")" next '-------------------------------------------------------------------------------------------------------------------------------------- 'Filling first row of tables %1="" for !j=1 to !maxq %1=%1+"ma("+@str(!j)+")" equation eq1.ls data c {%1} results_sc(3,!j+2)=eq1.@sc results_aic(3,!j+2)=eq1.@aic m_sc(1,!j+1)=eq1.@sc m_aic(1,!j+1)=eq1.@aic next '-------------------------------------------------------------------------------------------------------------------------------------- 'Filling first column of tables PDF created with pdfFactory Pro trial version www.pdffactory.com

description

leanlo

Transcript of SSRN-id1523045

Page 1: SSRN-id1523045

Electronic copy available at: http://ssrn.com/abstract=1523045

'=================================================================== 'This code select the best ARMA(p,q) model based on Schwarz criterion and Akaike criterion 'Copy your data in drive "c:\", data must have a "data" name and "xls" format and contain one 'column, the first cell of that column must have a name "x1" 'You can choose max lag of AR terms and MA terms by changing the right hand side of ' equations "!maxp=3" and "!maxq=3" 'Table "results_sc" contain Schwarz criterion for each ARMA(p,q) and "results_aic" contain ' Akaike criterion, the best model is determined automatically 'Good lock '=================================================================== 'Adapted by Moslem Peymany 'PHD of Finance, Allameh Tabatabai Uneversity, Faculty of Accounting and Management 'Tehran, Iran '[email protected] '=================================================================== 'Reading data wfopen "c:\data.xls" series data=x1 '-------------------------------------------------------------------------------------------------------------------------------------- 'Determining max lag of AR terms (p) and MA terms (q) !maxp=3 !maxq=3 '-------------------------------------------------------------------------------------------------------------------------------------- 'Preparing a matrix for necessary calculations, this matrix will be deleted at the end of code matrix(!maxp+1,!maxq+1) m_sc matrix(!maxp+1,!maxq+1) m_aic '-------------------------------------------------------------------------------------------------------------------------------------- 'Preparing tables to show results table (!maxp+5,!maxq+2) results_sc setline(results_sc,2) setline(results_sc,!maxp+4) results_sc(1,1)="SBC" results_sc(3,2)="---" table (!maxp+5,!maxq+2) results_aic setline(results_aic,2) setline(results_aic,!maxp+4) results_aic(1,1)="AIC" results_aic(3,2)="---" for !i=0 to !maxp results_sc(!i+3,1)="AR("+@str(!i)+")" results_aic(!i+3,1)="AR("+@str(!i)+")" next for !i=0 to !maxq results_sc(1,!i+2)="MA("+@str(!i)+")" results_aic(1,!i+2)="MA("+@str(!i)+")" next '-------------------------------------------------------------------------------------------------------------------------------------- 'Filling first row of tables %1="" for !j=1 to !maxq %1=%1+"ma("+@str(!j)+")" equation eq1.ls data c {%1} results_sc(3,!j+2)=eq1.@sc results_aic(3,!j+2)=eq1.@aic m_sc(1,!j+1)=eq1.@sc m_aic(1,!j+1)=eq1.@aic next '-------------------------------------------------------------------------------------------------------------------------------------- 'Filling first column of tables

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 2: SSRN-id1523045

Electronic copy available at: http://ssrn.com/abstract=1523045

%2="" for !k=1 to !maxp %2=%2+"ar("+@str(!k)+")" equation eq2.ls data c {%2} results_sc(!k+3,2)=eq2.@sc results_aic(!k+3,2)=eq2.@aic m_sc(!k+1,1)=eq2.@sc m_aic(!k+1,1)=eq2.@aic next '-------------------------------------------------------------------------------------------------------------------------------------- 'Filling other parts of tables %3="" for !p=1 to !maxp %3=%3+"ar("+@str(!p)+")" %4="" for !q=1 to !maxq %4=%4+"ma("+@str(!q)+")" %5=%3+%4 equation eq.ls data c {%5} results_sc(!p+3,!q+2)=eq.@sc results_aic(!p+3,!q+2)=eq.@aic m_sc(!p+1,!q+1)=eq.@sc m_aic(!p+1,!q+1)=eq.@aic next next '-------------------------------------------------------------------------------------------------------------------------------------- 'Determining the best model !pq=@max(m_sc) m_sc(1,1)=!pq !pq=@max(m_aic) m_aic(1,1)=!pq !maxpp=!maxp+1 !maxqq=!maxq+1 !pq=@min(m_sc) for !pp=1 to !maxpp for !qq=1 to !maxqq if m_sc(!pp,!qq)=!pq then !finalp=!pp-1 !finalq=!qq-1 endif next next results_sc(!maxp+5,1)="Best Model Is ARMA("+@str(!finalp)+","+@str(!finalq)+")" !pq=@min(m_aic) for !pp=1 to !maxpp for !qq=1 to !maxqq if m_aic(!pp,!qq)=!pq then !finalp=!pp-1 !finalq=!qq-1 endif next next results_aic(!maxp+5,1)="Best Model Is ARMA("+@str(!finalp)+","+@str(!finalq)+")" '-------------------------------------------------------------------------------------------------------------------------------------- 'Deleting excess data delete eq eq1 eq2 m_sc m_aic '-------------------------------------------------------------------------------------------------------------------------------------- 'Showing results show results_sc show results_aic

PDF created with pdfFactory Pro trial version www.pdffactory.com