Predicting the market with a little help from the POTUS

We used a Jupyter notebook to analyze and format the data, and loaded the data into a pandas DataFrame, which made manipulating and pulling specific data straightforward.Analyzing the DataWe wanted to use the overall opinion of the tweet, whether is is positive, negative, or neutral, along with other factors like the state of the market, to try and predict a rise or fall in the S&P 500 immediately after Trump tweets..We used a combination of the Natural Language Toolkit and Afinn libraries to come up with a sentiment score for each tweet..A positive score if the overall tweet has a positive connotation and a negative score for a tweet with a negative connotation..A sentiment score at or around zero is considered to be neutral.After running our analysis over all 35000+ tweets, we can see that the majority of tweets had an average sentiment score at or around zero..We do see plenty of tweets that have positive sentiment and plenty of tweets that have negative sentiment, which is good for training our model.Two other features we wanted to look at were the time of the tweet and the day of the week the tweet was sent on..As we can see there is a sizable chunk of tweets that fall in this range, which means we’ll have enough data points to train our models.Now that we had our sentiment score for each tweet, we could move on to analyzing them in a market environment..We gathered minute by minute spot prices on the SPY ETF which actively mimics the holdings and price movements of the S&P 500 market index, and went off to work.ModelingTo test our hypothesis that Trump’s tweets do affect the market and we can predict a change in the SPY ETF, we trained three models..Not to fear, Emojis are here!EMOJISIn class we looked at DeepMoji, a neural network that takes in tweets as its input, tries to understand the meaning and opinion of the tweet, and matches certain emojis to that tweet..An angry or negative tweet might have the angry face emoji, and a happy or positive tweet might have the ear-to-ear smile emoji..Here’s a picture of the network with all the layers:We wanted to use this pre-trained network and apply it to Trump’s tweets and see if this would give a better sentiment understand than just a simple sentiment analysis algorithm..The neural network produces a list of 64 emojis and a confidence level for each emoji on how well it fits the tone of the tweet.We went through all of the tweets and found the top five emojis before and after Trump became president.These are the top five emojis before Trump was president..There is not much difference between before and after, but we believe the emojis show that Trump is very expressive.After passing every tweet into the neural network, we took the top five emoji values, which were 0 through 63, the probability for each emoji, and the overall confidence of the emojis, which was the sum of the individual emojis confidence level, and passed those into our models..Too few data points and you won’t have an accurate model.But do Trump’s tweets affect the market?. More details

Leave a Reply