Predicting stock prices with neural networks
We will build the stock predictor with PyTorch in this section. We will start with feature generation and data preparation, followed by network building and training. After that, we will fine-tune the network to boost the stock predictor.
Training a simple neural network
We prepare data and train a simple neural work with the following steps:
- We load the stock data, generate features, and label the
generate_features
function we developed in Chapter 5, Predicting Stock Prices with Regression Algorithms:>>> data_raw = pd.read_csv('19900101_20230630.csv', index_col='Date') >>> data = generate_features(data_raw)
- We construct the training set using data from 1990 to 2022 and the testing set using data from the first half of 2023:
>>> start_train = '1990-01-01' >>> end_train = '2022-12-31' >>> start_test = &apos...