mardi 29 octobre 2019

Multiple outputs after if statement

if ((min(which((retail_stocks$ratio > (m + k*s))  == TRUE))) < (min(which((retail_stocks$ratio < (m - k*s)) == TRUE)))) {
  pos$open[i] <-  min(which(retail_stocks$ratio > (m + k*s)));
  pos$close[i] <- min(which(retail_stocks$ratio <= m))
} else {
  pos$open[i] <- min(which(retail_stocks$ratio < (m - k*s)))
}

If the condition is met, i want to fill the pos$open with the first index for which it's true, then I need to know where the closing point is, that's the first time the stockratio price crosses the mean again. That can't be simply be retailstock$ratio <= m; because it should be later/higher index number than the opening point. Then i need to find the next open point which is either the first value in which the ratio > mean + k sd or ratio < mean - ks; after the last opening/closing index point and then i need to find next the closing point; which index needs to be higher than of the last opening point. and i have to repeat this untill the end of the dataset. Im kind of stuck; how to implement this. I probably need to combine for/if and while loops; i dont really know how. hopefully someone can help me.

Aucun commentaire:

Enregistrer un commentaire