Confused about Shift Method

Course Name: Quantitative Trading Strategies and Models, Section No: 2, Unit No: 4, Unit type: Notebook

When calculating 5 day returns, why do we subtract data['Close'].shift(1) - data['Close'].shift(6) instead of just doing data['Close'] - data['Close'].shift(5)

Hi Ronak, 



To calculate the last five days' price change, we are taking a difference between yesterday's close and close price six days earlier. 



We are not considering the difference between today's close price and close price five days earlier since using today's close price would introduce look-ahead bias to the trading strategy. This would overstate the strategy returns in the backtest results.



And also, the close price of a contract changes throughout the day. So, if you want to perform backtest considering today's close price, you must wait till the end of today to capture the right closing price. So, using prices till yesterday would also solve this problem.



Hope this helps.