Why to Shift Predicted price

Course: Financial Time Series Analysis for Trading

Section 14: Implement Autoregressive model



Code:

Predict the price using predict_price_AR function

data['predicted_price'] = data['Adj Close'].rolling(rolling_window).apply(predict_price_AR)

Shift the predicted price by 1 period

data['predicted_price'] = data['predicted_price'].shift(1)



What is the purpose of shifting predicted price by 1 period here?

Hello Pratima,



The idea is that we are using the adjusted close price of today to predict the close price of tomorrow. 

For example, today is 22 September. 

Assume the asset price is $100. Now, we will use this price and input it into our trained model and try to predict tomorrow's operation. But when you check the code, the predicted price gets stored in the same row as today. i.e. 22 September. This is why we shift it to tomorrow's row, i.e. 23 September.



Hope this helps.



Thanks.

Hello Rekhit,



Thank you for explaining this. Understood now.