If you want to simulate cointegrated series maybe these paper may help you:

http://www.me.utexas.edu/~orie/morton_proceeding/galenko_etal_09.pdf



2012/12/26 Simone Gogna <singletonthebest@msn.com>

>   Dear R users,
> I am writing my master thesis and I need to simulate equations 12, 13 and
> 14 of the attached paper.
> Pls forgive my ignorance but it is the first time I try something like
> that.
> The code I came up with so far is presented below, but I think that it is
> very incorrect or, at least, doesn’t work.
> If you have any idea on the approach that I’ve to take or on how to
> improve my code pls don’t hesitate to contact me.
> I appreciate your patience.
> Thanks
> Simone Gogna
>
> ##general settings
> c<-0.5
> lambda<-0.3
> a<-c/lambda
> n<-500
>
> ## Eq.12
> V_init_cond<-0
> Et<-ts(rnorm(n+100,mean=0,sd=1))
> Vt<-Et*0
> Vt[1]<-V_init_cond+Et[1]
> for(i in 2:(n+100)) {
>   Vt[i]<-Vt[i-1]+Et[i]
> }
> Vt<-ts(Vt[(length(Vt)-n+1):length(Vt)])
> plot(Vt)
>
>
> #Eq.13
> Xt_init_cond<-0
> Xt<-Xt_init_cond*0
> Xt[2]<-c(Vt[1]-Pt[1])
> for(i in 2:(n)){
>   Xt[i]<-c(Vt[i-1]-Pt[i-1])
> }
> Xt<-ts(Xt[(length(Xt)-n+1):length(Xt)])
> plot(Xt)
>
>
>
>
> ##Eq. 14
> P_init_cond<-0
> Pt<-Rt*0
> Pt[1]<-P_init_cond+Rt[1]
> for(i in 2:(n+100)) {
>   Pt[i]<-Pt[i-1]+Rt[i]
> }
> Pt<-ts(Pt[(length(Pt)-n+1):length(Pt)])
> plot(Pt)
>
>
> epsilon<-ts(rnorm(n,mean=0,sd=1))
> Rt_init_cond<-0
> Rt<-Rt_init_cond*0
> Rt[2]<- -a*Rt[1]+a*Et[1]+epsilon[2]
> for(i in 2:(n)){
>   Rt[i]<- -a*Rt[i-1]+a*Et[i-1]+epsilon[i]
> }
> Rt<-ts(Rt[(length(Rt)-n+1):length(Rt)])
> plot(Rt)
>
>
>
>
> _______________________________________________
> R-SIG-Finance@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>

	[[alternative HTML version deleted]]

