The Trump Effect Dashboard: Tracking the Market Outcomes of All the President's Tweets

Posted on Feb 19, 2017

From the 2016 U.S. presidential campaign to election day, the inauguration, and beyond, media attention and debate have maintained a focus on the Twitter account of Donald Trump. Particularly following the election, there have been many articles contending that CEOs of publicly traded companies fear — or should fear— President Trump's tweets. Others have questioned or critiqued the assertion that the President's tweets have a substantive impact on the stock prices of the corporations he addresses on Twitter.

With no signs that the new phenomenon of Presidential tweeting about companies is coming to an end soon, an opportunity presented itself to create a tool to acquire a collection of Donald Trump's tweets, search them for references to major corporations, and provide charts of stock prices against tweets that refer to the relevant companies. Given the complexity of financial markets, it would be unreasonable to expect to find rigorous proof that Trump's tweets cause stock prices to rise or fall. However, it should be possible to explore the kinds of relationships that his tweets have to stock prices. This may also help us to determine whether a similar pattern emerges in stock prices following Trump's tweets, or whether there does not appear to be any consistent pattern. It is this type of exploration that the Trump Effect Dashboard aims to facilitate.

The examination of stocks referenced in Donald Trump's Twitter feed naturally begins with a collection of his tweets. The Twitter API provides a means to acquire the most recent tweets from a user's timeline, which is limited to 3200 tweets. It also offers a means to search for the ID numbers of all tweets by a given user. After accessing a list of tweet ID numbers, it is then possible to request the text and metadata of the associated tweets. The Trump Effect Dashboard, which is an R Shiny app, uses the timeline method, as implemented in the twitteR package, to obtain recent tweets. It also downloads and uses a collection of Trump's tweets that was assembled and stored on GitHub by Sasha Perigo through a Python script. By joining the archive of tweets, which ends in July 2016, with the recently acquired tweets, the dashboard gains access to a complete collection of Donald Trump's tweets from his very first tweet on May 4, 2009 to the present. The collection of tweets is then stored using the Feather serialization package for fast access to tweets on startup of the app.

The dashboard also needs a way to identify tweets that refer to publicly traded corporations. To do this, it first uses the quantmod package to access the Yahoo Finance API and obtain company names, ticker symbols, and market capitalizations. It then determines the 1000 largest corporations by market cap that are available. This list provides the universe of companies that the dashboard is capable of seeking in Trump's tweets. The app uses R's grepl function to determine which tweets have text that matches patterns related to a company, after cleaning up company names by removing terms such as "Inc." that are unlikely to appear in a tweet. A number of options are available to allow the user to customize the search process.

In the example below, the company selector is set to search Donald Trump's tweets from November 4, 2016 until February 18, 2017 for cases that refer to General Motors by name.


Other options make it possible to search by ticker symbol, turn off case sensitivity, or loosen the search so that it will accept matches on just the first word or first two words of a company name. Adjusting these options can be helpful in finding tweets that refer to companies because different approaches may be needed for different companies. The date range selector can also be adjusted to enable search for tweets over a broader or narrower period of time and to allow for the display of stock prices for the same period.

The following results are provided for the search settings shown above:


Above the listing of tweets found to match the search criteria, in this case referencing General Motors, is a candlestick chart of the company's stock price for the selected period along with its trading volume. The candlesticks are colored green for days when the stock closed up and orange for the days it closed down. The stock price and volume chart shown above was created using the quantmod R package.

A second tab in the company information panel provides an interactive stock price chart that overlays markers for relevant tweets. When the user's mouse hovers over a marker indicating a tweet (TW), the text of the tweet is displayed on the graph. (The markers labelled E and I near the bottom of the graph indicate election day and inauguration day respectively.) The interactive chart makes it easy to see that GM's stock price actually rose following a tweet that was critical of the company on January 3. A tweet thanking General Motors for creating jobs in the U.S. was followed by a negligible rise, then a small decline after the inauguration. Trump's tweet describing a positive meeting with GM's CEO preceded an uptick, then a larger decline in the company's stock price. Overall, these examples do not suggest a clear influence on the company's stock price. The dygraphs R package was used to create the interactive stock price charts.


The dashboard also provides another way to look up companies. A tab featuring a list of companies that Trump has tweeted about in recent years brings up the interactive stock chart for the selected company. In the case of Nordstrom, shown below, the stock price rose in the day following criticism by the President, although the subsequent movement was less decisive.


A third company information tab attempts to compare the frequency of tweets for the selected company with that of other companies that Donald Trump tweeted about in the same period. With Boeing selected in the example below, the tweet frequency tab shows that two tweets were found that referred to Boeing for the specified period, compared with three for GM and one for Nordstrom. The tweet frequency bar chart was created using the rbokeh package, which makes it possible for the user to view the exact number of tweets by hovering over a bar with the mouse.


However, the bar chart also illustrates limitations in the search method with respect to company names that are also common words or abbreviations. Tweets referring to the news media, for example, are counted as if they were tweets about News Corp, while those that use the abbreviation CA for California are incorrectly associated with the company CA, formerly Computer Associates. The preponderance of such common names and abbreviations, which are shared by the names of corporations, may be difficult to exclude from any search of tweets. The unstructured nature of tweets, their brevity, and the frequent use of abbreviations mean that distinguishing Intel the company from intel the abbreviation for intelligence is likely to remain a challenge.

One opportunity for future development work may be to facilitate search for companies by their subsidiaries, products, or other relevant keywords. Following the election, Donald Trump tweeted about Carrier, the air conditioner manufacturer, which had been in the news for its plans to reduce employment in Indiana and expand production in Mexico. The tweet below is not detected in the app as a reference to a company, even though the app downloaded it, because Carrier is not a publicly traded company in its own right. Instead, it is a subsidiary of United Technologies, a conglomerate that is among the largest publicly traded corporations. While United Technologies is in the universe of companies for which the app can search, additional information would need to be stored in order to detect references to its subsidiaries, such as Carrier.


Overall, a preliminary exploration of Donald Trump's tweets that refer to publicly traded companies using the Trump Effect Dashboard does not find much evidence for the contention that tweets that are critical of a company precede a decline in its stock price or that tweets that praise a company precede a rise, let alone evidence that they cause such results. At times, Trump has seemed to imply that a company's stock price was affected by his remarks on Twitter, such as his retweets promoting a boycott of Macy's following that company's decision to stop selling his clothing line and fragrance. (See the chart at the top of this blog post.) However, the cause of the decline of stock in Macy's, a company Trump promoted repeatedly on Twitter while it was selling his products, not necessarily related to his tweets and that decline is not matched by other companies Trump has criticized on Twitter. While the Trump Effect Dashboard provides a means to continue to examine this emerging phenomenon, it does not appear so far that his tweets lead to any consistent pattern of stock price results.

About Author

Evan Frisch

Evan Frisch has more than a decade and a half of experience using technology and data to achieve results for organizations in the private, public, and non-profit sectors. Evan received his undergraduate degree with honors from Yale University,...
View all posts by Evan Frisch >

Related Articles

Leave a Comment

No comments found.

View Posts by Categories

Our Recent Popular Posts

View Posts by Tags

#python #trainwithnycdsa 2019 2020 Revenue 3-points agriculture air quality airbnb airline alcohol Alex Baransky algorithm alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus ames dataset ames housing dataset apartment rent API Application artist aws bank loans beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep boston safety Bundles cake recipe California Cancer Research capstone car price Career Career Day citibike classic cars classpass clustering Coding Course Demo Course Report covid 19 credit credit card crime frequency crops D3.js data data analysis Data Analyst data analytics data for tripadvisor reviews data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization database Deep Learning Demo Day Discount disney dplyr drug data e-commerce economy employee employee burnout employer networking environment feature engineering Finance Financial Data Science fitness studio Flask flight delay gbm Get Hired ggplot2 googleVis H20 Hadoop hallmark holiday movie happiness healthcare frauds higgs boson Hiring hiring partner events Hiring Partners hotels housing housing data housing predictions housing price hy-vee Income Industry Experts Injuries Instructor Blog Instructor Interview insurance italki Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter las vegas airport lasso regression Lead Data Scienctist Lead Data Scientist leaflet league linear regression Logistic Regression machine learning Maps market matplotlib Medical Research Meet the team meetup methal health miami beach movie music Napoli NBA netflix Networking neural network Neural networks New Courses NHL nlp NYC NYC Data Science nyc data science academy NYC Open Data nyc property NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time performance phoenix pollutants Portfolio Development precision measurement prediction Prework Programming public safety PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R Data Analysis R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn seafood type Selenium sentiment analysis sentiment classification Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau teachers team team performance TensorFlow Testimonial tf-idf Top Data Science Bootcamp Top manufacturing companies Transfers tweets twitter videos visualization wallstreet wallstreetbets web scraping Weekend Course What to expect whiskey whiskeyadvocate wildfire word cloud word2vec XGBoost yelp youtube trending ZORI