I am using trees algorithms (decision tree, random forest and XGBoost) to forecast the sign of the returns in the stock market (classification).
I am using this article as a reference:
When splitting the training and the test set, the author uses the following R code:
index <- sample(1:nrow(stock_indicators))
size=0.2*nrow(stock_indicators)
test <- stock_indicators[index, ]
train <- stock_indicators[-index, ]
Is it correct to use a random set of dates to split the test and the training set with time series financial data?
It looks like look-ahead bias to me.
This would be the alternative:
train <-head(stock_indicators,round(0.70 * nrow(stock_indicators)))
test <- tail(stock_indicators,round(0.30 * nrow(stock_indicators)))
But with this split I cannot get significant accuracies even trying with different datasets.
Do you have any suggestions?