Image for post
Image for post
Image from [7]

Twitter and the Future of Data Science on Wall Street

In 1973, financial mathematicians Fischer Black and Myron Scholes published an academic paper titled “The Pricing of Options and Corporate Liabilities”, which contained what would end up becoming one of the most pivotal equations in all of mathematical finance, the Black-Scholes model[1]. The model is a stochastic-partial differential equation used to assign a value to a European style option, a type of asset that allows the holder to buy or sell a stock at its current price regardless of its future behavior. For reference, “puts” and “calls” are the two forms of options which are traded, where a put allows the holder to sell a stock at its current value in the future (useful if the stock price drops) and a call allows the holder to buy stock at its current price in the future (useful if the price rises).

While the Black-Scholes model received a fair amount of criticism over some of the assumptions it was built upon, it was still adopted by academics, professional traders, and amateurs alike who would introduce their own adjustments in an attempt to find some competitive advantage over other investors.

How is Machine Learning used on Wall Street?

While most people tend to imagine a room full of franticly shouting stockbrokers when they think of Wall Street, the truth is these “Wolf of Wall Street”-esque firms run by human traders have become a rarity in recent years. Instead, these firms are filled with quants, data scientists, and computer scientists who together design trading algorithms so that all of the actual buying and selling of can be handled by bots [2]. While financial and economic theory used to dictate how these trades were made, machine learning has allowed more creativity to be introduced into the models that make these choices [2].

Quantitative analyst Marcos Lopez de Prado released a book in 2018 titled Advancements in Financial Machine Learning that would later lead to him being awarded The Journal of Portfolio Management’s 2019 “Quant of the Year” award. Prado’s book is certainly not an exhaustive list of the uses of machine learning in finance, but it has helped many of the “old school” quants and investors transition from using the Black Scholes model and its variants into using more generic ML-based models.

Why Use Twitter for Financial Machine Learning?

One major advantage that machine learning allows for that purely financial models cannot grasp is the ability to include variables that are not based in finance. While economics will always be a driving force in the business world, a company’s stock price is not necessarily dictated by the quality of their work or the profit they make. Factors like competition with other companies or worker strikes can disrupt a business or tarnish their image, especially when written about in the news or exposed on social media. In particular, the social media site Twitter has been proposed as possibly a highly effective way to predict short-term jumps and dips in stock prices[5]. However, these jumps and dips happen so quickly in the age of computerized trading that a human broker would simply not be fast enough to decide whether or not a tweet means good news or bad. This is where machine learning shows its true advantage over both human brokers and computerized financial models: it can reasonably predict long term trends but can also react and adapt quickly to short term trends.

This is especially true amongst tech companies, where the company’s value is more closely tied to the potential future value of its technology than it is to the gains or losses incurred by the company. Many of these tech companies have young, Twitter-active CEOs and presidents that tweet about their company’s future endeavors and investments frequently.

How does Twitter affect stock prices?

Image for post
Image for post
[7] Elon Musk’s 2018 tweet that would later land him in hot water with the SEC [3]. This tweet would lead to the stock jumping 13.3%, and Musk being forced to step down as chairman of Tesla Motors.

In 2018, Tesla Motors founder and CEO Elon Musk tweeted that he was taking the company private, willing to buy out shareholders at 420$ a share, and that he had funding secured to do so [3]. Tesla’s stock was significantly lower than 420$ at a time, so many investors saw this as an opportunity to have an essentially risk free investment and responded by buying more of the stock. The stock price responded with a 13.3% increase almost immediately following the tweet, though the excitement was short lived after it was revealed that the company did not in fact have the necessary funds to go private. Still, if a wise investor were to buy what are known as “call” options for Tesla Motors immediately following this tweet, they would be able to buy the stock at its price from before the tweet was published, which in this case could mean an almost instantaneous 13.3% profit.

Musk’s Twitter use was deemed so disruptive by the SEC that he was banned from tweeting about certain topics related to his businesses [3], yet Tesla still shows noticeable swings in its stock price when Musk does tweet, or even when other pages tweet about Tesla.

Image for post
Image for post
Figure 2: The closing stock price of Pfizer in October and November of 2020 [4]. Notice that there is a very sharp peak on the day of the vaccine announcement. While this peak does decay quickly after, this is possibly just due to the volatility of the stock, which has fluctuated rather heavily over the last few months.

Of course, business executives are not the only people with enough of a public impact to swing stock prices. The Twitter pages of prominent politicians, perhaps most notably President Donald Trump and more recently President Elect Joseph Biden, have also created short-term jumps and dips in stock prices. Trump’s November 2020 twitter announcement of pharmaceutical giant Pfizer’s COVID-19 vaccine achieving 90% accuracy, for instance, preceded a rally for the stock prices of Pfizer, Moderna, and many other large pharmaceutical companies. The announcement was made Monday, November 9th, 2020, and Pfizer’s stock saw a 7.7% jump from its closing price the Friday before [4]. Many investors believe that the news also led to rallies in unrelated industries like oil, air travel, and entertainment as the American people became more optimistic about an end to COVID-19 restrictions on businesses and public spaces[4]. In this case, a wise investor would certainly want to buy stock in pharma, but also perhaps stock in other rallying industries to minimize the risk of the investment and be better prepared for long term gains.

It is worth saying that of course, we cannot prove that the tweets were the actual cause of the stocks jumping. However, simply because so many people follow the President’s Twitter page, it is reasonably likely that people will first learn about the vaccine either through the tweet itself or from a newspaper article discussing it. All that really matters is that the model can react to the news in time, and if more people react to the tweet than the announcement itself then it makes sense to simply watch for the tweet.

How Would This Model Work?

It is worth noting that a purely Twitter-based machine learning model would almost certainly not perform well predicting changes in the stock market. The stock price at the time a tweet is published, the volatility (proportional to the standard deviation of stock price), the historical data of the stock, and the industry of the company all could be useful features to train an ML model on, but tweets cannot really be easily incorporated into such a dataset since there isn’t a tweet for every stock price data point we have. [5] Demonstrates how attempting to blend twitter data and financial data into one model seems to have relatively low predictive power, regardless of the stock studied or the ML/DL algorithm used. However, I believe that this could be improved by rethinking the way the different datatypes are applied to a modified ML pipeline.

Instead, a more reasonable approach might be to create two separate machine learning models which would work in conjunction. One of these models would predict long term behaviors with relatively low resolution and the other would predict short term behaviors and would be deployed on one data point (tweet) at a time to predict the wisest reaction for the investor. The long term model would involve the financial and industry data run through a regression pipeline to approximate the stock’s growth, and the short term analysis would be based on the text in tweets that are relevant to the company and perhaps some data on the twitter pages themselves (ie number of followers, retweets, etc.). The short term model would involve first running some text-analysis on a tweet (to tokenize, stem, and remove stop words and punctuation from the text) and then a classification pipeline with the target variable being a set of choices for the investor. This set of choices could be as simple as buy, sell, and hold, if the investor is not as interested in short-term trading as they are in long term investment. However, if a stock is gaining or losing value only in the short term, trading options may be a more sensible idea, so that we aren't investing based on temporary effects of the market. This would mean our model would have 5 classes altogether: buy stock, buy puts, buy calls, sell stock, or hold.

Since the short term model would have five classes, and since text analysis data is highly dimensional, this classification problem would probably best be handled by a neural network, though this is difficult to guess without having access to such data. The long term pipeline might fair just as well with a simpler ML algorithm, however, and this may be favorable if it requires less computation time. Of course, this model is purely theoretical and has not yet been attempted, so there could be unforeseen issues with its implementation. Its also worth noting that the investing strategy I have described is very high risk, and is probably better suited for a large firm than a lone day trader.

In conclusion, there is little debate that large amounts of social media attention can affect the behavior of the stock market [3,4,5]. And while there has been only limited success in using ML pipelines trained on stock data coupled with text analysis data on tweets so far [5], this should only be seen as a reason to study these models further, not to reject them. Any clever trading strategy is only truly valuable while it is still relatively new, and its best to be the first person to use it. Just like how the Black Scholes model once changed the financial world only to eventually become outdated and obsolete, every good idea will eventually just become common knowledge.

Citations:

1.) Scholes, Myron, and Fischer Black. “The Pricing of Options and Corporate Liabilities.” Cs.princeton.edu, 1973, www.cs.princeton.edu/courses/archive/fall09/cos323/papers/black_scholes73.pdf.

2.) Ahmed, Yacoub. “Getting Rich Quick with Machine Learning and Stock Market Predictions.” Medium, Towards Data Science, 12 Jan. 2020, towardsdatascience.com/getting-rich-quick-with-machine-learning-and-stock-market-predictions-696802da94fe.

3.) “Press Release.” SEC Emblem, 29 Sept. 2018, www.sec.gov/news/press-release/2018-226.

4.) Bharti, Bianca. “Pfizer CEO Albert Bourla Sells 62 per Cent of His Shares on Same Day as Vaccine Announcement.” Nationalpost, National Post, 11 Nov. 2020, nationalpost.com/news/world/pfizer-ceo-albert-bourla-sells-62-per-cent-of-shares-same-day-vaccine-announcement-made.

5.) Mukhtar, Noah. “Can We Beat The Stock Market Using Twitter?” Medium, Towards Data Science, 29 May 2020, towardsdatascience.com/can-we-beat-the-stock-market-using-twitter-ef8465fd12e2.

Images:

6.) Staff, Abmuku.com. “Abmuku.com Staff.” Location-Based Social Media Monitoring Software Platform For Enterprise | GeoFencing | Remarketing Tools, 4 Jan. 2013, www.abmuku.com/2013/01/04/social-media/rumor-twitter-will-ipo-in-2014/attachment/twitter-bird-on-money-logo/.

7.) “Elon-Musk-Funding-Secured.” Flirting with Models, blog.thinknewfound.com/2019/02/no-pain-no-premium/elon-musk-funding-secured-2/.

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store