yu<-0.1 #up move of the market r<-0 #interest rate yd<--0.1 #down move of the market u<-1.2 #upper (sell) threshold l<-0.9 #lower (buy) threshold T<-100 #number of time periods Y<-sample(c(1+yd,1+yu),T,replace=TRUE)# vector of multiplicative coefficients S1<-c(1,cumprod(Y)) # vector of prices (S1_0, S1_1,..., S1_T), T+1 elements. counter<-0 # 0 : k < sigma, 1: sigma <= k = u){ theta[i+1]<-0 phi[i+1]<-phi[i]+S1[i] v[i+1]<-phi[i+1] counter<-counter+1 } else{ theta[i+1]<-0 phi[i+1]<-phi[i] v[i+1]<-v[i] } } if(theta[T+1]==1){ theta[T+1]<-0 phi[T+1]<-phi[T]+S1[T] } print(S1) print(theta) print(phi) t<-0:T plot(t, S1, type = "l", xlim = c(0,T), ylim = c(-1,1.5)) lines(t, theta, type = "l", col = "red") lines(t, phi, type = "l", col = "blue") lines(t, v, type ="l", col = "green")