The Stonks API provides tools for preprocessing stock market data, training machine learning models, and making predictions on future stock prices.
Abstract:
Purpose – This paper proposes a novel deep neural network model, specifically long short-term memory (LSTM) networks, for predicting stock prices using historical data and financial indicators.
Method – LTSM can handle long sequences while capturing temporal dependencies, making it an excellent choice for NLP or time series. The model is trained and tested on the Ayala Corporation (AYALY) stock dataset from 2016 to 2019, using four financial indicators: earnings per share (EPS), EPS growth, price/earnings ratio, and price/earnings-to-growth ratio.
Results – The results show that the model achieves high accuracy and outperforms other Deep Neural Network variants as confirmed by assessing its performance using suitable metrics like mean squared error and mean absolute error. It effectively explored and selected relevant financial indicators, implemented data preprocessing techniques, and trained the model using historical data.
Conclusion – The project effectively explored and selected relevant financial indicators and trained LSTM models using historical data, and, thus, met its objectives to develop a deep neural network model for stock price prediction.
Recommendations – The authors recommend that future researchers continue to explore the integration of a diverse set of financial indicators, employ rigorous comparative analyses, and experiment with different time frames for future predictions to further enhance prediction accuracy.
Keywords – Deep Neural Network, Long Short-Term Memory (LSTM) Networks, Machine Learning, Stock Price Prediction, Time Series Forecasting
Read the full paper: DOI:10.25147/ijcsr.2017.001.1.209
August 2024, International Journal of Computing Sciences Research 8:3147-3156
import Stonks
import pandas as pddf = pd.read_csv("dataset.csv", parse_dates=['Date'])data, scaler = Stonks.Processing.preprocess_stock_data(df, future_steps=7)model = Stonks.Model.load('lstm')independent = ['Close_future_1', 'Close_future_2', 'Close_future_3',
'Close_future_4', 'Close_future_5', 'Close_future_6', 'Close_future_7']
X = data.drop(['Close', 'Date'] + independent, axis=1).values
y = data[independent].valuesy_pred = model.predict(X)inversed_y_pred = [round((i * (scaler.data_max_[31] - scaler.data_min_[31]) + scaler.data_min_[31]), 2) for i in y_pred[50]]import numpy as np
import matplotlib.pyplot as plt
date = range(1, 38)
plt.plot(date, np.concatenate((plot_x_lookback, inversed[50][31:38])), label='Actual')
plt.plot(date[30:37], np.array(inversed_y_pred), label='Predictions')
plt.title("Bank of the Philippine Islands (BPHLY)")
plt.xlabel("Days")
plt.ylabel("Stock Price ($)")
plt.legend()
plt.grid(True)
plt.show()from sklearn.metrics import mean_squared_error, mean_absolute_error
mse = mean_squared_error(inversed_y_pred, inversed[50][31:38])
mae = mean_absolute_error(inversed_y_pred, inversed[50][31:38])
print(f"MSE: {mse:.4f}, MAE: {mae:.4f}")