* GGKCOEF.SRC (dernière version novembre 2000)
*
* 	Calcule les coefficients MA d'un GG à k facteurs en évitant les boucles imbriquées
* 
*
*	Utilisation : 	@ggkcoef nobs nsingular
*						# d
*						# nu

* 	En sortie :
*					piggkserie		la série des coefficients MA
*
*****************************************************************

procedure ggkcoef nobs nsingular

type integer			nobs nsingular

option switch print 		1
option switch graph		1

local integer			i j k l m p q ns nobs startl endl
local real 				cpt1 cpt2 cpt3 cpt4 cpt5 cpt6 compt
local vec[real]		pi pi2 pi3 pi4 pi5 pi6 d nu
local series 			tempseries fortempserie
local rec[real]		ggcoef ggcoeffplus

dec series 				piggkserie

dim d(nsingular)
dim nu(nsingular)

enter d
enter nu

dim ggcoef(nobs,nsingular)
do ns=1,nsingular
com ggcoef(1,ns) =  1
com ggcoef(2,ns) = 2*(d(ns))*nu(ns)
	do j=2,nobs-1
		com ggcoef(j+1,ns) = 2*nu(ns)*((d(ns)-1)/j+1)*ggcoef(j,ns)-(2*(d(ns)-1)/j+1)*ggcoef(j-1,ns)
	enddo j
enddo ns

*write ggcoef


******************** Calcul des poids *********************

dim pi(nobs)

if nsingular==1
{
com pi = %xcol(ggcoef,1)
}

if nsingular==2
{
infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 2-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+ggcoef(i,1)*ggcoef(j-i+1,2)		
	enddo i
	com pi(j) = cpt1
enddo j
infobox(action=remove)
}

if nsingular==3
{
dim pi2(nobs)
infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 2-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+ggcoef(i,1)*ggcoef(j-i+1,2)		
	enddo i
	com pi2(j) = cpt1
enddo j
infobox(action=remove)

infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 3-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+pi2(i)*ggcoef(j-i+1,3)		
	enddo i
	com pi(j) = cpt1
enddo j
infobox(action=remove)
}


if nsingular==4
{
dim pi2(nobs) pi3(nobs)
infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 2-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+ggcoef(i,1)*ggcoef(j-i+1,2)		
	enddo i
	com pi2(j) = cpt1
enddo j
infobox(action=remove)

infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 3-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+pi2(i)*ggcoef(j-i+1,3)		
	enddo i
	com pi3(j) = cpt1
enddo j
infobox(action=remove)

infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 4-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+pi3(i)*ggcoef(j-i+1,4)		
	enddo i
	com pi(j) = cpt1
enddo j
infobox(action=remove)
}


if nsingular==5
{
dim pi2(nobs) pi3(nobs) pi4(nobs)
infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 2-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+ggcoef(i,1)*ggcoef(j-i+1,2)		
	enddo i
	com pi2(j) = cpt1
enddo j
infobox(action=remove)

infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 3-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+pi2(i)*ggcoef(j-i+1,3)		
	enddo i
	com pi3(j) = cpt1
enddo j
infobox(action=remove)

infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 4-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+pi3(i)*ggcoef(j-i+1,4)		
	enddo i
	com pi4(j) = cpt1
enddo j
infobox(action=remove)

infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 5-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+pi4(i)*ggcoef(j-i+1,5)		
	enddo i
	com pi(j) = cpt1
enddo j
infobox(action=remove)

}


if nsingular==6
{
dim pi2(nobs) pi3(nobs) pi4(nobs) pi5(nobs)
infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 2-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+ggcoef(i,1)*ggcoef(j-i+1,2)		
	enddo i
	com pi2(j) = cpt1
enddo j
infobox(action=remove)

infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 3-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+pi2(i)*ggcoef(j-i+1,3)		
	enddo i
	com pi3(j) = cpt1
enddo j
infobox(action=remove)

infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 4-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+pi3(i)*ggcoef(j-i+1,4)		
	enddo i
	com pi4(j) = cpt1
enddo j
infobox(action=remove)

infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 5-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+pi4(i)*ggcoef(j-i+1,5)		
	enddo i
	com pi5(j) = cpt1
enddo j
infobox(action=remove)

infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 6-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+pi5(i)*ggcoef(j-i+1,6)		
	enddo i
	com pi(j) = cpt1
enddo j
infobox(action=remove)
}


if nsingular==7
{
dim pi2(nobs) pi3(nobs) pi4(nobs) pi5(nobs) pi6(nobs)
infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 2-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+ggcoef(i,1)*ggcoef(j-i+1,2)		
	enddo i
	com pi2(j) = cpt1
enddo j
infobox(action=remove)

infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 3-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+pi2(i)*ggcoef(j-i+1,3)		
	enddo i
	com pi3(j) = cpt1
enddo j
infobox(action=remove)

infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 4-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+pi3(i)*ggcoef(j-i+1,4)		
	enddo i
	com pi4(j) = cpt1
enddo j
infobox(action=remove)

infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 5-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+pi4(i)*ggcoef(j-i+1,5)		
	enddo i
	com pi5(j) = cpt1
enddo j
infobox(action=remove)

infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 6-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+pi5(i)*ggcoef(j-i+1,6)		
	enddo i
	com pi6(j) = cpt1
enddo j
infobox(action=remove)

infobox(action=define,progress,lower=1,upper=nobs) "Coefficients 7-factor GG"
do j=1,nobs
infobox(action=modify,current=j)
	com cpt1 = 0
	do i=1,j
		com cpt1 = cpt1+pi6(i)*ggcoef(j-i+1,7)		
	enddo i
	com pi(j) = cpt1
enddo j
infobox(action=remove)
}


set piggkserie = pi(t)

if print
{
print / piggkserie
}


if graph
{
graph 1
# piggkserie
}



end procedure