Revisiting stock price forecasting with LSTM
Recall in Chapter 6, Predicting Stock Prices with Artificial Neural Networks, we derived features from past prices and performance within a specific time step and then trained a standard neural network. In this instance, we will utilize RNNs as the sequential model and harness features from five consecutive time steps rather than just one. Let’s examine the process in the following steps:
- Initially, we load the stock data, create the features and labels, and then split it into training and test sets, mirroring our approach in Chapter 6:
>>> data_raw = pd.read_csv('19900101_20230630.csv', index_col='Date') >>> data = generate_features(data_raw) >>> start_train = '1990-01-01' >>> end_train = '2022-12-31' >>> start_test = '2023-01-01' >>> end_test = '2023-06-30' >>> data_train = data.loc[start_train...