Predicting stock prices with the three regression algorithms
Here are the steps to predict the stock price:
- Earlier, we generated features based on data from 1990 to the first half of 2023, and we will now continue to construct the training set with data from 1990 to 2022 and the testing set with data from the first half of 2023:
>>> 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:end_train] >>> X_train = data_train.drop('close', axis=1).values >>> y_train = data_train['close'].values >>> print(X_train.shape) (8061, 37) >>> print(y_train.shape) (8061,)
All fields...