#### Brownian Motion - Normal increments t<-seq(0,1,0.001); x<-matrix(0,nrow=1001,ncol=3); x[,1]<-t; W<-rnorm(1000,0,1) x[2:1001,2]<-W for (i in 2:1001) { x[i,3]<-x[i-1,3]+x[i,2]} plot(x[,1],x[,3],type="l",lwd=2) #### Brownian Motion - uniform increments t<-seq(0,1,0.001); x<-matrix(0,nrow=1001,ncol=3); x[,1]<-t; W<-runif(1000,-5,5) x[2:1001,2]<-W*sqrt(3/25) for (i in 2:1001) { x[i,3]<-x[i-1,3]+x[i,2]} plot(x[,1],x[,3],type="l",lwd=2) ############# Brownian Motion Many Paths ######################### t<-seq(0,1,0.001); number_of_paths=5 x<-matrix(0,nrow=1001,ncol=number_of_paths+1); x[,1]<-t; for (i in 1:number_of_paths){ W<-rnorm(1000,0,1) for (j in 2:1001){ x[j,i+1]<-x[j-1,i+1]+W[j-1] } } plot(x[,1],x[,2],type="l",lwd=2,col="1",ylim=c(-80,80)) for (i in 1:number_of_paths-1){ lines(x[,1],x[,i+2],type="l",lwd=2,col=i+1)} #### Brownian Bridge - Normal increments t<-seq(0,1,0.001); x<-matrix(0,nrow=1001,ncol=3); x[,1]<-t; W<-rnorm(1000,0,1) x[2:1001,2]<-W for (i in 2:1001) { x[i,3]<-x[i-1,3]+x[i,2]} plot(x[,1],x[,3]-x[,1]*x[1001,3],type="l",lwd=2) abline(0,0, col="red",lwd=2) ###################### Paley - Wiener Series ############################## t<-seq(0,1,0.001); N<-1000 x<-matrix(0,nrow=1001,ncol=3); x[,1]<-t; x[,2]<-sqrt(2*pi)*t*rnorm(1,0,1) plot (x[,1],x[,2],type="l",lwd=1,ylim=c(-5,5)) for (i in 1:N){ y<-2*rnorm(1,0,1)*(sin(pi*i*t))/(i*sqrt(pi)) x[,2]<-x[,2]+y #lines(x[,1],x[,2],type="l",lwd=1) } lines(x[,1],x[,2],type="l",lwd=1)