7.5 Remark: More efficient code
In the RSI code above, we have written that:
1:day+1] <- 0
signal [
for (i in (day+1): length(price)){
if (rsi[i] < 30){
1
signal[i] <-else {
} 0
signal[i] <-
} }
A more efficient but less readable code is to avoid counting:
for (i in 1:length(price)){
0
signal[i] <-if (isTRUE(rsi[i] < 30)){
1
signal[i] <-
} }