Predicting stock prices with neural networks
We will build the stock predictor with TensorFlow 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 and incorporate early stopping 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 7, Predicting Stock Prices with Regression Algorithms:>>> data_raw = pd.read_csv('19880101_20191231.csv', index_col='Date') >>> data = generate_features(data_raw)
- We construct the training set using data from 1988 to 2018 and the testing set using data from 2019:
>>> start_train = '1988-01-01' >>> end_train = '2018-12-31' >>>...