Market forecasting has always been a notoriously difficult task. Factors such as global macro-economincs, political, public sentiment do not follow strict patterns. Tradionally "technical factors" such as EMA (exponential moving average), RSI (relative strength index), MACD (Moving Average Convergence Divergence) and others are used to predict buys/sells for any specific stock. Recently, machine learning has shown promise in predicting future stock price performance. Machine learning used to forecast stock price coupled with traditional financial analysis could provide a more confident picture of future price movements.
Leverage machine learning to provide a forecast for any given stock (on the NYSE) for any number of days in the future.
Utilize a LSTM (Long Short Term Memory) RNN (Recurrent Neural Network) that can weight previous time sequenced inputs from the economic history and train on these hidden patterns. We will use 8 1/2 years worth of stock and global economic data to train/test the neural network's performance.
Our performance will be measured using MAE, MAPE. However, my main criteria will be how often the trend for the forecasted days matches the actual data.
The data will be gathered from the following sources using mostly yahoo finance throught the yfinance python library.
- target stock: volume, high/low, range, close, adj close
- day of week, day of month, month
- sister stocks: these are stocks that are in a similar industry and standing with the target stock
- composite indices etfs: these are etfs that track major market health from the top 4 stock exchanges (NASDAQ, JPX, SSE, LSE)
- volatility index: etf tracking Chicago Board Options Exchange's CBOE Volatility Index
- currency exchange: US vs Japan, China, Europe
- Inverse fourier transform of discrete fourier tranformed closing prices
- 12 Technical Indicators: ma200, ma50, MACD etc.
- Seasonal ARIMA (AutoRegressive Integrated Moving Average) which is often used in time series prediction. We will predict closing price
- Single LSTM layer
- Recurrent dropout to prevent overfitting
- Activation Function: ReLU (Rectified Linear Unit)
- Loss: MAE (Mean Absolute Error)
- Optimizer: ADAM (Adaptive Moment Estimation)
- Node Size: Found during grid search
- Batch Size: Found during grid search
- Time Step: Found during grid search
- Injest Data - 104 parameters in total
- XGBoost (Gradient Boosting Model) that removes any irrelevant parameters (does have a non-detailed, detailed mode)
- Log return all prices
- Split data into train/test set
- Scale data using standard scaler
- Train models using grid search on node size, batch size, and time step. Target for LSTM RNN is [Y1,Y2,..Yx]
- De-scale data and inverse log to find predicted prices
- Ouptut model performance on test set
- Select best performing model based on matching trends
- Perform horizon prediction for X number of days for selected stock
- Output on macro and micro scale
- yfinance
- pmdarima
- sklearn
- scipy
- pandas
- numpy
- statsmodels
- xgboost
- tensorflow
- keras
- matplotlib
Bank of America test set, 10 day prediction for the past year of trading. Trend match is based on each 10 day segment.