2016-11-25 1 views
0

위해 나는 R 루프 "를"다음과 같은 것을 가정? 이미 이전 게시물에 대한 답변 (링크 : Loop for ARMA model estimation 참조)을 기반으로 명령을 작성하려고했지만 위의 루프에 대한 예상 결과를 얻을 수 없습니다.건물 계수 매트릭스는 순환적인 GARCH/ARMA + GARCH 모델

EDIT :

다음 "의사 코드"는 계수 매트릭스의 제 3, 제 4, 제 5 열 오메가 알파 1 및 베타 계수를 저장하지 않는다는 점에서 틀리다.

누구든지 오류를 찾아서 수정할 수 있습니까?

의사 코드 :

armagarchcoefmat=matrix(NA, 4, 6) 
a=0 
for(p in 0:1) for(q in 0:1){ 
a=a+1 
model<-ugarchspec(variance.model = list(model="fGARCH", submodel = "GARCH", garchOrder = c(1, 1)),mean.model = list(armaOrder = c(p, q), include.mean = TRUE), distribution.model = "norm") 
modelfit<-ugarchfit(spec=model, data=USDlogreturns, solver="hybrid") 
if(p>0) armagarchcoefmat[a, c(1: p) ]=coef(modelfit)[2:6][c( 1 : p)] 
if(q>0) armagarchcoefmat[a, c(2:(1+q))]=coef(modelfit)[2:6][c((p+1):(p+q))] 
armagarchcoefmat[a,  6 ]=head(coef(modelfit),1) 
} 
+0

당신은 [재현 예]를 설정해야합니다 (http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), 모든'라이브러리를 포함하여()'는 함수 코드, 입력 데이터,'modelfit'의 결과와 같은 현재 결과, 그리고 예상 결과를 호출합니다. – Parfait

답변

0

결국, 나는 내 문제를 해결하기 위해 관리. 아래는 "armagarchcoefmat"행렬에서 모델 계수를 반환하는 코드와 그 결과 행렬 자체가 어떻게 보이는지에 대한 코드입니다. 행은 각각 (0,0), (0,1), (1,0) 및 (1,1) (p, q) 쌍을 나타냅니다. 열은 phi, theta, mu, omega, alpha1 및 beta1 계수 추정을 각각 포함합니다.

library(rugarch) 

    USDlogreturns=diff(log(prices)) 


    armagarchcoefmat=matrix(NA, 4, 6) 
    a<-0 
    for(p in 0:1) for(q in 0:1){ 
    a<-a+1 
    model<-ugarchspec(variance.model = list(model="fGARCH", submodel = "GARCH", garchOrder = c(1, 1)),mean.model = list(armaOrder = c(p, q), include.mean = TRUE), distribution.model = "norm") 
    modelfit<-ugarchfit(spec=model, data=USDlogreturns, solver="hybrid") 
    if(p>0) armagarchcoefmat[a, c(1: p) ]<-coef(modelfit)[2:3][c( 1 : p)] 
    if(q>0) armagarchcoefmat[a, c(2:(1+q))]<-coef(modelfit)[2:3][c((p+1):(p+q))] 
    armagarchcoefmat[a, 3 ]<-head(coef(modelfit),1) 
    armagarchcoefmat[a, c(4:6) ]<-tail(coef(modelfit),3) 

    } 

    > armagarchcoefmat 
      [,1]  [,2]  [,3]   [,4]  [,5]  [,6] 
[1,]   NA  NA 0.002168063 9.086569e-06 0.03919058 0.9598094 
[2,]   NA 0.1301537 0.002158361 9.643089e-06 0.04207555 0.9569244 
[3,] 0.1166279  NA 0.002172631 9.517783e-06 0.04160620 0.9573938 
[4,] -0.3500512 0.4745337 0.002110809 9.745079e-06 0.04236628 0.9566337