Hello everyone,
I need to calculate cashoutflows as below :
1st rotation : if frost risk = 1 cashoutflows [i+1] = cc (-1 800)
2nd rotation : if frost risk =1 cashoutflows [i+1] = cc (-1 800)
3rd rotation : if frost risk =1 cashoutflows [i+1] = cc (-1 800)
4th rotation : if frost risk =1 cashoutflows [i+1] = rc (-11 000)
The idea is like i have 3 tickets of "cc", when it is sold out i need to use "rc"
I appreciate your help
Thank you
time<-c(1:300)
growth<-c(0,0,0,20,17,21,25,33,35,31,21,12,9,7,5,0,0,0,20,17,21,25,33,35,31,21,12,9,7,5,0,0,0,20,17,21,25,33,35,31,21,12,9,7,5,0,0,0,20,17,21,25,33,35,31,21,12,9,7,5,0,0,0,20,17,21,25,33,35,31,21,12,9,7,5,0,0,0,20,17,21,25,33,35,31,21,12,9,7,5,0,0,0,20,17,21,25,33,35,31,21,12,9,7,5,0,0,0,20,17,21,25,33,35,31,21,12,9,7,5,0,0,0,20,17,21,25,33,35,31,21,12,9,7,5,0,0,0,20,17,21,25,33,35,31,21,12,9,7,5,0,0,0,20,17,21,25,33,35,31,21,12,9,7,5,0,0,0,20,17,21,25,33,35,31,21,12,9,7,5,0,0,0,20,17,21,25,33,35,31,21,12,9,7,5,0,0,0,20,17,21,25,33,35,31,21,12,9,7,5,0,0,0,20,17,21,25,33,35,31,21,12,9,7,5,0,0,0,20,17,21,25,33,35,31,21,12,9,7,5,0,0,0,20,17,21,25,33,35,31,21,12,9,7,5,0,0,0,20,17,21,25,33,35,31,21,12,9,7,5,0,0,0,20,17,21,25,33,35,31,21,12,9,7,5,0,0,0,20,17,21,25,33,35,31,21,12,9,7,5)
set.seed(1)
Myfunction <-runif(n=length(time), min=0,max=1)
#Frost_Risk
frost = rep(0, length(time))
p=1/15
for (i in 1:length(Myfunction)){
if (Myfunction[i]<=p) {frost[i] = 1}
else{frost[i] = 0}
}
print(frost)
#Growth under frost risk
growth_Rsk<- vector("numeric",300)
index<-0
for(i in seq_along(frost)){
if( frost[i]==0 ){index<-index+1}
else {index<-1}
growth_Rsk[i+1]<-growth[index]
}
#Coppicing costs
cc<-(-1800)
#Replanting costs
rc<-(-11000)
#Discount rate/coeff
a<-c(0.02)
a_rate<-1/(1+a)^time
#Price
price<-c(66)
#Cash inflows
cashinflows<- vector("numeric",300)
cashinflows<-growth_Rsk[1:300]*price
#Cash outflows
cashoutflows<- vector("numeric",300)
for(i in seq_along(frost)){
if( frost[i]==1 ){
i =i+1
cashoutflows[i]<-cc
}else{cashoutflows[i]==0
}
}