Inspiration

We had a hypothesis that public sentiment for Elon Musk has a strong influence on Tesla stock prices due to Elon Musk's unique Twitter persona and reputation and Tesla's revered status.

What it does

Our tool scrapes Twitter for tweets with the keywords "musk", "elon musk", or "tesla", cleans the tweets of any links and special characters, then runs a sentiment analyzer to give each tweet a sentiment score. The sentiment scores are averaged to determine the overall sentiment towards Elon Musk and Tesla on Twitter. The date and time of tweets that the scraper pulls can be easily adjusted within the code and defaults to real-time. Currently, by subtracting the previous day's average sentiment from the current day's sentiment, we provide a prediction on whether or not Tesla stock will rise, fall, or stay neutral.

How we built it

For our project, we used two Python libraries: twint, a Twitter scraper that does not require use of Twitter's API, and VADER, a lexicon and rule-based sentiment analysis tool designed for application in social media.

Challenges we ran into

Before settling on VADER, we tried other natural language processing tools with our program, but faced several issues with them. For example, many could not accurately process the slang and informal style of social media. Emotional outburst in all caps didn't make a difference with the first couple tools we tried. Luckily, in our search for improvement, we found VADER, which was designed to handle social media and it's more unpredictable text.

Accomplishments that we're proud of

We're pretty excited about completing a prototype of this project because it's not only our first Hackathon, but our first foray into the field of NLP. We're also proud of the fact that we were able to scrape data from the past three weeks of open market days and found that there really was a general trend in Twitter sentiment and Tesla stock fluctuations.

What we learned

Pretty much everything we did along the way was a great learning experience. We learned a lot about NLP and its intricacies, file encoding, web scraping, and that Elon Musk is mentioned on Twitter WAY more than we imagined.

What's next for Twitter Sentiment Analysis for Tesla Stock Prediction

We plan on creating another iteration of our tool after Hacklahoma is over, with the goals of finding stronger relationships between Twitter sentiment and Tesla stock price (for example seeing how much influence the sentiment of the evening before affects stock price on market opening), creating a script to run the tool periodically, and integrating Yahoo Finance API to get real-time comparisons of sentiment and stock prices. We also reserved a domain: http://tsla2.space/. $TSLA to the moon! With this domain, we want to keep a real-time plot of our measured Twitter sentiment as well as our prediction on stock price changes. Thanks for reading!

Built With

Share this project:

Updates