Hi,
in the course "AI for portfolio management: LSTM networks" section 11, notebook "Implementing LSTM For Portfolio Weights Optimisation" you shift backward by one period assets' returns with ".shift(-1)":
# Calculate the daily returns of assets in 'tech'
asset_returns = tech.pct_change().fillna(0).shift(-1)
# Plot the returns
plt.figure(figsize=[15, 7])
plot_returns_optimised(asset_returns.mul(asset_weights), tech, c='b', aclass='', plot_title= 'Strategy Vs Benchmark Returns')
This looks wrong to me, because this way you are introducing look-ahead bias. In fact, if you're using close prices of stocks, you woud know each daily return exclusively at the end of every trading day. By introducing shift(-1), it's like knowing a day before the closing price of the following day.
An example can demonstrate why I am asking a clarification on this point:
Let's suppose that we are on 2022-02-01, and the price of a stock is 100 at the close. The following day (2022-02-02), the price of the same asset closes at 101, for a return of 1%. If I had invested 5% in this asset on 2022-02-01, I would have relalized my return of 0.05% only at the close of 2022-02-02. If I apply shift(-1) to the backtest, it is like I have realized this return on 2022-02-01, when we did not know the closing price of 2022-02-02. It's like if I am attributing returns one period earlier, than what would have been in reality.
Can you please clarify this?
Thanks in advance!
Luca