# How to assign n day target variables in machine learning

I am trying to forecast future price using supervised machine learning. My logic is to take open and close price from t, t-1, t-2 and t-3 period to predict future close price in the period t+1,t+3 and t+5

library(quantmod)
symbol= getSymbols("AAPL",from="2010-03-01", auto.assign=F)
close<-Cl(symbol)
open<-Op(symbol)
lc1<-lag(close)
lc2<-lag(close,2)
lc3<-lag(close,3)
lo1<-lag(open)
lo2<-lag(open,2)
lo3<-lag(open,3)
X<-cbind(close,open,lc1,lc2,lc3,lo1,lo2,lo3)
Y<-need to assign close price for t+1,t+3 and t+5


I have created feature vectors using lag function for period 0,1,2 and 3 but my question is how to I assign target variable for t+1, t+3 and t+5 periods.

You need to assign each of the target variables to their own column and then train a model for each of your forecast horizons

library(quantmod)
symbol= getSymbols("AAPL",from="2010-03-01", auto.assign=F)
close<-Cl(symbol)
open<-Op(symbol)
lc1<-lag(close)
lc2<-lag(close,2)
lc3<-lag(close,3)
lo1<-lag(open)
lo2<-lag(open,2)
lo3<-lag(open,3)
X<-cbind(close,open,lc1,lc2,lc3,lo1,lo2,lo3)


X$t1<-lag(close,-1) X$t3<-lag(close,-3)
X$t5<-lag(close,-5)  From this you can nou train 3 models to predict the closing of$t+n, n=1,..,n\$