Hey everyone,
I need help to calculate #Cashflows
#Cashflows
cashflows=(growth_Rsk*price)+ (cc+rc i need to code this part)
The idea is that I have three tickets of cc to use every rotation and just one ticket of rc to use every 3 rotations (when cc are sold out):
I want to code :
if growth risk interuppted by frost and restarted from 0 : use cc (-1800) for three rotations (repeat 3 times)
when cc tickets sold out :
use cc use rc (-11 000) for the fourth rotation
Thank you, I appreciate your help
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)
Myfunction <-runif(n=length(time), min=0,max=1)
#Frost_Risk
frost = rep(0, length(time))
p=1/10
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<-66
#Cashflows
cashflows<- vector("numeric",300)
.
.
.
.
#Discounted Cashflows
discounted_cashflows<-cashflows*a_rate
#Net Present Value
npv<-cumsum(discounted_cashflows)
print(npv)