plt.plot(data.Close.pct_change().cumsum(), label='Buy and Hold')
My problem is if I pick 1 specific date, then I have a looking ahead bias for the overnight returns as I am waiting for next day Open. Should we not use instead ?
To evaluate the strategy, should not we pick a date and then use the ranked stocks found the day before to evaluate the strategy. So backtest would be :
Here is a conversation with chatGPT which recommends to use shift(1) on the selection instead of shift(-1) on returns if one wants to have the date as point of reference :
For the first query, you can either shift the position of the open price or the close price. I understand your concern and we will update the notebook.
For the second query, we are taking the data (Close) as the percentage change of prices, i.e. this is the daily returns calculated and not the price values. You can see this in the line "stk = pd.read_csv('…/data_modules/tech_stocks_2000_2022.csv', index_col=0, header=[0, 1]).pct_change()" when we import the data.
You’re using today’s closing momentum ranking to select the stock with the highest momentum without knowing the next day’s return in advance.
stk.Close.shift(-1) represents the next day’s percentage change, which your strategy would capture by theoretically holding overnight (from today’s close to tomorrow’s close). This was the approach taken by the author.
I understand this was the reason for your confusion and I hope it makes sense now.
Thanks for your answer. Regarding, the second question, I still feel unconfortable to use shift(-1). For me, if I pick a date, I expect to see the returns for that specific date either the returns of the backtested strategy or the return of the benchmark.
I feel that by using shift(-1) to foresee the future returns of the stocks we create an unalignment with the dates which makes it difficult to compare the strategy returns with any other strategy. Maybe I should not use the date as the reference to compare but if I change that I might not be able to compare the backtest with other strategies' returns.
But it is a detailas that course is my all time favorite. Thanks Quantra and Dr Starke for this great content !