[R-SIG-Finance] help for a simulation

Simone Gogna singletonthebest at msn.com
Wed Dec 26 12:02:48 CET 2012


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)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20121226/123d4784/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: farmer joshi.pdf
Type: application/pdf
Size: 330634 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20121226/123d4784/attachment.pdf>


More information about the R-SIG-Finance mailing list