I would like to expand the original question posted here First steps learning to predict financial timeseries using machine learning
with another question of my own:
Let's fit an overly basic RF algorithm in R following the example:
getSymbols("GOOG")
fit <- RF(lag(GOOG.Close,1), GOOG.Close, data=GOOG[1:(NROW(GOOG)-20)])
prediction <- predict(fit,GOOG[(NROW(GOOG)-19):NROW(GOOG)])
sig = ifelse(prediction >0, 1,-1)
ret = diff(log(GOOG$GOOG.Close))
pnl = ret * sig
I'm not lagging the signal sig because I already lagged the explanatory variable.
Is that correct or I should lag the signal again such as:
sig1 = lag(sig,1)
pnl = ret * sig1
What is the correct procedure ?
Thank you!