Predicating Daily Stock Ratings via Artificial Neural Network

Jason Dunleavy
7 min readMar 24, 2021

Investing Strategies

Institutional and individual investors follow two main investing strategies:

  1. The first is an active strategy where the investor believes in a hands-on approach and aims to beat the stock market’s average return by frequently buying and selling to take advantage of short-term price fluctuations.
  2. The second is a passive strategy — a hands-off approach — where the investor believes that market prices are fundamentally in equilibrium, and therefore does not react to short-term price fluctuations.

This project addresses those with an active strategy, specifically the problem of identifying when to buy, sell, or hold a particular stock to take advantage of overvalued and undervalued companies.

Analyst Reports and Recommendations

When deciding whether to buy, sell, or hold equity securities, investors often turn to analyst reports. Research analysts look at various metrics (both quantitative and qualitative in nature) when deciding to make a recommendation. Some metrics include:

Quantitative

  • Market price
  • Financial statements
  • Financial ratios
  • Fair value estimates

Qualitative

  • Economic moat
  • Uncertainty
  • Industry/sector factors

Research firms each have their own individual ranking scales, however, most follow a scale that resembles the following:

  • 5 — Strong Sell
  • 4 — Sell
  • 3 — Hold
  • 2 — Buy
  • 1 — Strong Buy

While these rankings are a quick way to convey “the bottom line” to investors, it should be noted that they are solely that. Investors each have their own individual risk tolerance, portfolio objectives, and time horizons, which should influence their decision-making.

Below is a sample of a MorningStar analyst report for Delta Airlines — the analyst provided a rating of 3 out of 5 stars, which translates to a hold:

Project Motivation

My motivation for this data science project was to predict a stock’s analyst recommendation for a given stock, on a given day. My goal was to create an algorithm that does the manual work analysts do — but with deep learning. While no algorithm can substitute the need for professional judgment in the investment decision-making process, this model can be used as a quick sanity check or temperature gauge.

Target: Mean Analyst Rating

Finding a large, unbiased data set for this project proved difficult. Research analyst reports are not free; I spent hours trying to find a reasonably priced historical dataset. After scouring the internet, I decided to purchase a dataset on quandl.comZack’s Analyst Rating History. The dataset contained two years of daily historical analyst ratings (from over 185 brokerage firms) for over 3,000 publicly traded companies.

The dataset only contains values for days where there was a change in an analyst's rating for a given stock. The dataset contains the following relevant fields:

  • ticker- ticker or trading symbol
  • obs_date- observation date corresponding to the date on which contributed estimates were changed and the consensus was revised
  • rating_cnt_strong_buys- number of Strong Buy recommendations
  • rating_cnt_mod_buys- number of Buy recommendations
  • rating_cnt_holds- number of Hold recommendations
  • rating_cnt_mod_sells- number of Sell recommendations
  • rating_cnt_strong_sells- number of Strong Sell recommendations
  • rating_mean_recom- Consensus analyst rating (arithmetic mean calculation). 1 = Strong Buy, 5 = Strong Sell

The last field, Mean Analyst Rating, was set as the target (continuous variable — one through five) in this project.

Features

When contemplating data sources and features to include in the model, I considered the sources that a research analyst would use to perform their own independent analysis for a given stock:

  • Market Data — including daily closing price and volume
  • Financial Statement Line ItemsTrailing Twelve Month figures, from the most recent 10-Q/10-K SEC filing. Line items from the income statement, balance sheet, and statement of cash flows were included.
  • Sector/Industry/Exchange — One-hot encoded these categorical features
  • Earnings Surprises — Included this feature to capture if the company is underperforming or outperforming previous analyst earnings estimates
  • Daily Discounted Cash Flow Valuations — A forward-looking metric, unlike the other abovementioned features, which are retrospective in nature.

Over 170 features were included in the data frame before feature engineering.

Data Sources

The following databases and APIs were used to source and streamline the abovementioned features:

Feature Engineering

Feature engineering on key financial statement line items (Revenue, Gross Profit, Operating Income, EBITDA, EPS, Assets, Net Cash Flow, NCF — Operations, and Equity) was performed to capture autoregressive change over one-, two-, and three-year periods (trailing-twelve-month).

Price and volume changes were also captured through autoregressive features (daily, monthly, quarterly, semi-annual, annual, two-year, and three-year periods).

Various financial ratios and metrics were calculated, which are essentially interaction terms between the original features. These include, but are not limited to:

  • Market Capitalization
  • Enterprise Value
  • Dividend Yield
  • Price/Earnings (PE)
  • Price/Earnings/Growth (PEG)
  • Activity Ratios
  • Liquidity Ratios
  • Solvency Ratios
  • Profitability Ratios

I wanted to mute any noise from systematic economic events and isolate company-specific price changes; to do this, I calculated the difference between a stock’s change in price and the change in price of its respective industry (for a given time period).

After feature engineering, the data frame contained 324 features.

Choosing a Performance Metric

The final data frame contained over one million rows of daily stock data. To ensure training, validation, and testing data were independent of one another, each validation and test set contained independent, unseen stock tickers. I wanted to ensure that the model was generalizing, and not using the company ticker as a “hidden” feature.

The metric I choose to assess model performance was Mean Absolute Error (MAE).

Building a Baseline Model — Linear Regression

To assess the complexity of the problem, I ran a linear regression model to obtain a baseline. Using Lasso Regularization, I obtained a model with a testing MAE of 0.83. Recall — this is on a scale of one (Strong Buy) through five (Strong Sell).

Linear regression is a useful model in terms of interpretability. Below are the model’s features with the strongest coefficients:

  • Non-Current Liabilities: +2.48
  • Current Debt: +2.37
  • Net Cash Flow — Common Stock: -2.20
  • Consolidated Income: -1.96
  • Non-Current Assets: -1.80
  • Tax Assets: -1.61
  • Net Cash Flow — Dividends: -1.61
  • Inventory: +1.58
  • Average Equity: +1.47
  • Research & Development Expense: +1.47
  • Deferred Revenue: -1.31
  • Property, Plant, and Equipment — Net: +1.18
  • Net Cash Flow — Inv: -1.09

Building a Neural Network

To tackle this problem through deep learning, I utilized Google Cloud Platform GPUs to train and test various sequential neural network architectures. Training and testing was an iterative process, working through varying numbers of layers, nodes, activation functions, batch sizes, and epochs to obtain an optimal model.

I found the model to overfit on the training set and not generalize enough. To combat this, I included multiple dropout layers. The architecture that performed best is shown as follows:

The final testing MAE for this architecture was 0.73, an improvement of 0.10 from the linear regression model MAE of 0.83.

Web App

To put the model into use, I created a proof of concept web app using Streamlit and deployed it via Heroku.

After the user selects a company of their interest, the app will make a stock rating/recommendation using the pre-trained neural network, and will also display up-to-date stock metrics, company details, and financial information.

The app was deployed publically via Heroku.

Future Work

Recall, I am solely predicting the mean analyst rating for a given stock for a particular day. Analyst recommendations are not always correct. A more direct proxy for making profits would be to predict future price, a problem I would like to tackle in future work.

I’d also like to experiment with time series models such as ARIMA and LSTM models, as this data set can be defined as a time series problem.

My model was based heavily on quantitative inputs, but to capture the qualitative inputs analysts consider in their recommendations (economic moat, uncertainty, etc.), I would consider using Natural Language Processing (NLP) techniques on available text including stock news articles, company press releases, earnings releases, and financial statements. The outputs (sentiment, topics, etc.) of these NLP models could be included as features in a future model, with the goal of obtaining a lower MAE.

GitHub

Code for this project can be found on my GitHub.

Jason Dunleavy is a data science student in the Winter 2021 Metis Data Science Bootcamp. Before joining Metis, Jason worked at PwC in the Assurance practice, where he performed audits and developed digital audit tools for the firm. This blog post outlines his final Metis project, where he designed an Artificial Neural Network to predict a stock’s daily analyst rating.

--

--