Creating Separate Future Price Targets for Multiple Forecast Horizons
Summary
The document explains how to set up supervised learning targets for predicting a stock’s closing price at several future dates. It uses lagged open and close prices as input features, then assigns the close price one, three, and five periods ahead to separate outcome columns. Each forecast horizon is handled by training its own model, so the setup produces distinct predictions rather than a single multi-step output.
The example uses Apple price data and R’s quantmod lag function. It demonstrates the direction of the lag needed to align future closes with current features, but it does not show model training, evaluation, or safeguards against look-ahead leakage. A second answer notes that this feature set resembles an autoregressive model and suggests considering ARIMA implementations. The document gives no comparison of these approaches or evidence that either predicts prices effectively.
Key ideas
- Use lagged market prices as supervised learning features.
- Create a separate target column for each forecast horizon.
- Train a separate model for each future closing-price target.
- Consider autoregressive time-series models such as ARIMA for this kind of setup.
Tags
Full text
# How to assign n day target variables in machine learning
# 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.
## Answer by Hanjo Odendaal (score 1)
https://quant.stackexchange.com/a/26046
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)
```
Add outcome variables (Y)
```
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$
## Answer by K3---rnc (score 0)
https://quant.stackexchange.com/a/26071
What you appear to be doing is actually an auto-regressive (AR) model, so perhaps you can benefit from using existing models like ARIMA R already has great implementations for.Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.