President Donald Trump is widely known for his prolific use of Twitter to publicly call out people and companies he approves of or disagrees with. Over the past several years, news outlets have pointed out that machine learning could be used to capture the stock market value of losses or gains brought on by the President’s tweets. A number of individuals have also created trading bots which work in real time, to varying success. The purpose of this project was to filter and expand the available data on Trump’s tweets in order to better characterize economic impact of Trump’s tweets, with a focus on which tweets actually drove market activity.
The project involved the creation of a data pipeline for retrieving tweets, and their underlying data, for a target set of publicly traded companies the President mentions. The tweets were selected by creating a set of filter terms using natural language processing. Once the set of tweets relevant to the set of terms was selected, the tweets were subjected to sentiment analysis. Sentiment analysis allowed for further filtering of positive and negative tweets. Stock data for these tweets, including trading volume, volatility, and daily return was assessed. Rather than attempt to capture value by day trading on tweets, the resulting project is a platform for conducting research on the economic effect of tweets, both by Trump and other high profile public figures. The methods tested are expandable and could be used to build a trading strategy, or remediate the effects of tweets.
Method: Data Pipeline
The tweets were downloaded from the day he announced his intent to run for presidency, June 16th 2015, to May 4th 2019. In this time period, he tweeted, including deleted tweets, a total of 13,277. The tweet data included the tweet, date and time of tweet, and the number of retweets and favorites each tweet had. Of the 13,277 tweets, the only ones required were those that referenced specific companies. In order to choose which companies to investigate, we looked online to read reports of companies that Trump tweeted about and compiled a list of 45 publicly traded companies, most of which are or were in the S&P index at some point over the last 4 years.
The search terms for each company, to cross reference with the tweets, included the company name, twitter symbol and ticker. We used word vectors to expand this list, looking for the words most similar to the name and twitter symbol of each company. To do this, three pre-trained word vector models were used. The first was based off of the GoogleNews dataset, which has a vocabulary of 3 million words trained on roughly 100 billion words. The second was based off of the Wikipedia 2017 dataset, which has a vocabulary of 1 million words trained on all of Wikipedia’s pages from 2017. The third used GloVe and was based off of the Twitter dataset, which has a vocabulary of 1.2 million words based off of 2 billion tweets. We also looked for the words most similar between each company and certain key words such as “CEO” or “founder”. This yielded promising results; for example, when looking for the words most similar between “Amazon” and “CEO” one of the results was “Jeff Bezos”, which was then split in order to search for phrase “Jeff Bezos” as well as “Bezos” in the tweets. This splitting process was done for the company names as well as the newly found search terms.
In order to remove any words which might give us irrelevant tweets, such as “CEO” — Trump may have used the word CEO in a tweet but not in coordination with a company we were searching for — a list of 243 words was created to check against our search terms. This included financial terms, political terms, common names (e.g. Clinton or Mueller) and a few other terms (e.g. General) which could result in flagging irrelevant tweets. We used the 3 word vector models to expand these lists, resulting in 13,507 words. Each search term associated with the companies was cross referenced against the 13,507 words and then removed if found present. Overall, for the 45 companies, a total of 987 words were found. These were not necessarily unique, as some words may have been found with multiple companies.
Once we had our list of companies with the search terms, we filtered through the 13,277 tweets to find the ones which were relevant. Some tweets mentioned more than one company so they were flagged with the multiple companies they mentioned. A total of 436 unique tweets were found, though of the 45 companies, only 33 were flagged. When visually looking through these tweets, it became apparent that a lot of the tweets involving news companies were irrelevant. For example, Trump would often tweet “FAKE NEWS” with just the name of companies such as NYTimes, or that he would be doing an interview on Fox. These tweets were deemed irrelevant as it was assumed that these would have almost no effect on the stock market. This was confirmed by looking at graphs of the day of these tweets against daily changes in stock price, volume traded or volatility against a 5 or 10 day moving average (these graphs will be explained in detail below). Other companies were also removed if unique tweets could not be identified. For example, Time Warner Company was removed as Trump often tweeted the word Time at the start of a sentence, though this sentence had nothing to do with TWC. After removing these companies, a total of 150 unique tweets were found for 23 different companies. The total number of search terms for these companies was 759.
With the 150 tweets, we performed sentiment analysis and natural language processing to determine whether a tweet was positive or negative and how positive or negative that tweet was. Unfortunately, sentiment analysis is not perfect and does not always pick up on sarcasm, thus sometimes incorrectly scoring a tweet. In order to determine which method of sentiment analysis would best fit our tweet, we looked at 3 different methods. The first used, TextBlob, a python library which returns polarity as a measure of sentiment between -1 and +1, with -1 being negative and +1 being positive.The second also used TextBlob but employed NaiveBayesAnalyzer, an NLTK classifier trained on a movie reviews corpus. The third used VADER (Valence Aware Dictionary and sEntiment Reasoner), a lexicon and rule-based sentiment analysis tool that is specifically attuned to sentiments expressed in social media. This is also a python library. Upon inspecting the results of each method, by visually comparing the tweets with the scores, we determined that VADER yielded the most sentiment scores.
Once there was a csv file containing the tweet, companies mentioned in that tweet and the date it was created, the next step was to download the stock price data. The data was downloaded from yahoo finance and included the open, close, high and low prices for each day, as well as the volume of shares traded in that day. Additional data was pulled using the times and tickers from Bloomberg, however it was not possible to access data for certain times because it is proprietary information. Various moving averages were tested on all stock data to achieve graphs that best expressed how the market reacts over time.
Results and Analysis of Data
Volume: A moving daily average for volume was calculated for every tweet pulled using our data pipeline. In order to study the effects of tweets on trading volume, trading volume correlated with each tweet was broken down into positive, negative, strongly positive, and strongly negative tweets, as well as tweets related to each industry, including automotive, aerospace, pharma, finance, and media/communications. A similar method was used to isolate results for volatility and percent price change.
It was found that announcements specifically were correlated with the most significant increases of trading volume. Announcements can be characterized as Trump tweeting news about a major event at a company, for example laying off workers or opening a new plant. These announcements generally haven’t been released to the public otherwise. Many retail investors would become aware of these tweets as the tweet’s become viral and are reported on or retweeted, resulting in a knock-on effect. With the caveat that institutional investors would largely be aware of these major events, it is still possible that awareness of Trump’s attention further entices trading. Still, this observation on announcements indicates that shifts in volume are not solely driven by the tweet but by other channels of information on the events. These announcement tweets often had strong results in sentiment analysis, especially for negative Tweets. It makes sense that the firm language of such annunciatory tweets specifically relating to real positive or negative events at companies has a high correlation with volume shifts. Another time announcements have an especially strong effect is when Trump is breaking news, meaning nobody is aware of announcements he is about to make. For example, when he announces Rex Tillerson will be Secretary of State or that he secretly met with GM, the markets were not aware of these events. Trading activity was strong in these cases. The lack of clear trends in other aspects of the data was a main reason we isolated out announcements from the rest of the tweets. This proved more useful for investigating volume and volatility than isolating specific industries like pharma or finance. Also, note that announcement tweets where the information had already been released publicly were removed.
It was found that strong negative tweets generated a significantly larger impact on stock prices, volume, and volatility. This is likely due to the President’s history of making surprising or even shocking claims about executive actions, threats, or tariffs. It is clear from this that markets fear Trump’s negative actions more than positive reinforcement. Tariff threats historically have more immediate ability to rattle the market and cause investors to react to potential future losses, rather than act as an indicator of long term economic improvement. Additionally, unusual threats of retaliation for moving factories and other major moves (which would otherwise improve stock prices due to perceptions of lower future costs) generated more impact as compared to positive tweets about creating jobs.
Ripple effects were also observed in terms of how trading activity shifted over the days following major announcements. Over time, we see a shift in the ripple effect of trading volume, though with no consistent trend over time. It was expected that volatility would increase in the day after a tweet about a company, and then subside. The idea behind this is that the tweet would cause hysteria which would fade over the next few days, especially since prices generally reverted to pre-tweet levels over the next few days. Instead, it is often seen that trading volume will pick up in the following days. In only a few occasions does the greatest volatility occur on the day after the tweet; rather it generally occurs over the next several days. This could be due to market correction from follow up news or correction of initial hysteria. It could also be due to a delay in retail traders reaction to the news. Many people only hear about Trump’s tweets from news outlets and could have been delayed as compared to institutional traders. Either the latency of retail traders or follow-up news/corrections could result in the increasingly delayed trading volumes following Trump’s tweets 2015-2019, however data from retail/institutional brokerages on who is placing trades and more in depth news analysis would be needed to confirm.
The most important observation drawn from the volume based data is that when Trump tweets there is generally an increase in volume, but the patterns of the data lead us to believe it is not institutions but regular people trading who lead to the increased volume.
Volatility: An initial prediction we had was that Trump’s tweets regarding industrial companies would have a greater impact than those regarding other industries. By calculating moving average for volatility following Trump’s tweets, the data showed that volatility did generally increase more for auto and aerospace companies more than it did for other industries. During the timespan directly after Trump’s election, the markets paid special attention to Trump’s tweets regarding the movement of factories and the mass hiring and firing of workers. Thus, we see volatility in these industries as perhaps the one area most strongly correlated to Trump’s tweets. While other market forces tended to exert influence on long term price trends, the overhanging uncertainty of how protectionist tariffs and turbulent relationships with major trading partners would affect companies seem to peak after Trump’s tweets. It is clear that the Tweets further stoke these economic uncertainties. Financial markets are generally sensitive to shocks and uncertainty, often the main content of Trump’s tweets. But a more important question is whether the provocation of short term volatilities leads to any long term economic effects, and if so, were the fears rational? How long do these effects even last? News outlets have often reported on stark price drops as a result of volatility following Trump’s tweets, but rarely report on further effects. For example, Tweets regarding Boeing and Lockheed contracts to build planes for the military would often cause large drops, driven by volatility. So did Ford, GM, Toyota, and Fiat Chrysler. It is, however, necessary to look beyond the analysis of volatility to determine whether or not the impact is fleeting. Our analysis did not include tweets specifically about tariffs or trade so we cannot directly isolate out the effects of those tweets, although we would predict that their effect would be substantial on the companies that might be affected by the tariffs even if they are not directly mentioned. It is also seen that markets heeded Trump’s tweets and showed less volatility recently than earlier in his presidency.
Stock Price: Surprisingly, no correlation was found for the whole dataset, negative sentiment or positive, to the percent price change of the stock at close. This indicates that either the sentiment analysis performed extremely poorly or that on average, the effect of Trump’s tweets was wiped out by the end of the day. Even when isolating out particular industries, like automobiles, the R^2 value did not significantly increase for sentiment vs. percent price change after a day. Upon closer inspection of the tweets, it was clear that the sentiment analysis often missed Tweets a human could look at and predict a resulting stock price effect from. Even, however, when isolating out tweets where sentiment was personally labelled, we see exceptionally low correlation at the end of day between positive tweets and price increases, and conversely negative tweets and price decreases. Looking at the data points, for example, the stock decreases about half the time there is a negative tweet, but unpredictably also goes up about half the time. It will be necessary to add more features and minute stock prices to the data.
Relation to Tweet Sentiment: As previously mentioned, other studies have attempted to mine Trump’s tweets for sentiment and see if there is any way to correlate reactions. Our own research was partly inspired by journalist Max Braun who created a bot that traded based on sentiment analysis of Trump’s tweets. If a tweet was strongly positive or negative, the bot would immediately buy and then sell at the close of the market. The bot achieved around 60% annualized return on a couple dozen tweets. Based on our sentiment analysis and tweet selection, we don’t see the possibility to achieve such results with our data. Interestingly, he used Google Cloud Sentiment Analysis, a paid service we did not have access to. Sentiment analysis generally weights words based on their positive and negative connotations both independently and in sentences. The words are assigned values which lead to an overall value of a sentence. In the case of Trump, sentiment analysis has limitations. Sentiment analysis is poor at recognizing sarcasm which is prevalent in Trump’s tweets. Upon scrolling through our analysis of Trump’s tweets, it was often apparent that the sentiment analysis available to us cannot capture the nuances of all his language - although perhaps a specially designed one weighted on Trump’s lexicon would work better. If we created our own system by weighting Trump’s words by hand with a Word2Vec or GloVe model, we may see better results. Unfortunately, sentiment analysis also has difficulty recognizing compound ideas, and conflates the vectors of positivity and negativity within a sentence often resulting in useless results - our sentiment analysis generally performed well on more simple ideas.
In the age of Trump and social media, using natural language processing and sentiment analysis on qualitative data, especially from twitter, has become a field of intense interest. Many in media, business, and politics are concerned about whether Trump’s tweets have had lasting damaging effects on the economy, or whether short term volatility is justified. In either case, the idea that social media could have such impactful real world effects is a cause of deep frustration to some, and disbelief for others. We set out to implement a data pipeline for natural language processing of Trump tweets to better understand what tools and methods are needed to effectively address the aforementioned questions. In terms of trading volume, it was found that tweets generally increased trading volume, with peaks during the early half of the Trump presidency and a recent resurgence. Negative tweets were found the generally have a greater correlation with increased volume than positive tweets. In terms of volatility, it was determined that tweets regarding automotive and aerospace industries resulted in more volatility than in pharma, finance, and media/communications. It was impossible to isolate effects on major media companies because Trump attacks them so frequently to little noticeable effect. Over a five day period following Tweets, there were several interesting observations regarding late reactions and shifting severity of reaction to Trump’s tweets over time. Despite attempts to access intraday stock data through API’s and Bloomberg, it was not possible to attain anything beside daily averages, highs, lows, and closing stock prices. In a 24-hour window, however, there was no correlation between positive tweets and stock price increases or negative tweets and stock price decreases. This was true regardless of the industry observed. The most successful aspect of the project was the implementation of the data pipeline, which we believe with further featurization and access to intraday stock data could be used to robustly mine any influential figure’s tweet data for market effect. Another realization was the need for sentiment analysis specifically weighted to President Trump’s bizarre lexicon; this would significantly aid in improving the accuracy of any trading bot designed to use machine learning on Trump’s tweets. The data analyzed in this report points to evidence that Trump’s tweets do not, in fact, have lasting economic impacts on publicly traded companies despite consistently causing chaos.