@woodward woodward
Hey Everyone,
I need to add another condition with same logic as for if i == 0 :
if "i" is multiple of 15+1 "16, 31, 46, 61.....286(max))
npv[index] <- -costs[index]i_rate[index]
}else{
npv[index] <- i_rate[index] * (npv[index-1] + price(growth[index] -growth[index-1]))
Do you have some brilliant idea to integrate this to my calculations?
thank you

More explanations____________
Time from 0 to 300 : for each start of rotations or loops (15 years) i need to start with npv[index],
then for next 14 years npv[index] <- i_rate[index] * (npv[index-1] + price*(growth[index] -growth[index-1]))
time<-c(0:300)
growth<-c(0,0,0,0,20,37,58,83,116,151,182,203,215,224,231,236,0,0,0,20,37,58,83,116,151,182,203,215,224,231,236,0,0,0,20,37,58,83,116,151,182,203,215,224,231,236,0,0,0,20,37,58,83,116,151,182,203,215,224,231,236,0,0,0,20,37,58,83,116,151,182,203,215,224,231,236,0,0,0,20,37,58,83,116,151,182,203,215,224,231,236,0,0,0,20,37,58,83,116,151,182,203,215,224,231,236,0,0,0,20,37,58,83,116,151,182,203,215,224,231,236,0,0,0,20,37,58,83,116,151,182,203,215,224,231,236,0,0,0,20,37,58,83,116,151,182,203,215,224,231,236,0,0,0,20,37,58,83,116,151,182,203,215,224,231,236,0,0,0,20,37,58,83,116,151,182,203,215,224,231,236,0,0,0,20,37,58,83,116,151,182,203,215,224,231,236,0,0,0,20,37,58,83,116,151,182,203,215,224,231,236,0,0,0,20,37,58,83,116,151,182,203,215,224,231,236,0,0,0,20,37,58,83,116,151,182,203,215,224,231,236,0,0,0,20,37,58,83,116,151,182,203,215,224,231,236,0,0,0,20,37,58,83,116,151,182,203,215,224,231,236,0,0,0,20,37,58,83,116,151,182,203,215,224,231,236,0,0,0,20,37,58,83,116,151,182,203,215,224,231,236)
price<-c(66)
i<-c(0.02)
costs <- vector("integer", 300)
costs[time %% 45 ==0] <- 1800
i_rate<-1/(1+i)^time
i_coeff<-1/(1+i)^time
npv <- vector("double", length(time))
for(i in time){
index = i + 1
if(i == 0){
npv[index] <- -costs[index]i_rate[index]
}else{
npv[index] <- i_rate[index] * (npv[index-1] + price(growth[index] -growth[index-1]))
}
}
View(npv)