Niral J Shah

Writing / FinTech / From the archive

Stock Price Analyzer using sentiment analysis on news articles and tweets

News and current affairs affect the stocks when it comes to trading. It also affects the way people think & the way they make a decision. We have a seen that the sentiment behind the news affect more than it should be. But how can we escape it and predict the change before it happens?

Bloomberg is already using the technique of using sentiment analysis on current news to estimate the change on related stocks. And making millions out of it.

You can find this project and its code on Github here (opens in a new tab)

Here is an example of how it works...

I used the Business Times to search for news articles on Facebook. Ideally, we can use tweets from powerful celebrities, media houses and companies to reach to the news faster. So I ran it for the last six months and averaged the sentiments of each news article for a given day. Here it goes...

DateSentiment rate
26 Jul 20190.796
25 Jul 20190.981
24 Jul 2019−0.086
18 Jul 20190.883
17 Jul 20190.962
16 Jul 20190.986
15 Jul 2019−0.548
13 Jul 20190.38
12 Jul 2019−0.176
11 Jul 20190.684
10 Jul 2019−0.428
09 Jul 20190.246
04 Jul 2019−0.264
03 Jul 20190.094
02 Jul 20190.055
01 Jul 2019−0.243
28 Jun 2019−0.006
27 Jun 20190.842
26 Jun 2019−0.194
25 Jun 2019−0.27
21 Jun 2019−0.357
20 Jun 20190.997
19 Jun 20190.814
18 Jun 20190.978

Here, every sentiment score for the day shows the sentiment average for the day. 1 means a very positive news for the company while -1 tends to show the negativity or a setback for the company. This gives an idea about how the stock of facebook is going to be in the near term. Let us see how effective it is:

Facebook’s daily share price from 18 June to 26 July 2019, with trading volume and a 15-day moving average, above a line of the daily news sentiment. Annotations mark the rise in early July and the dip around 15–19 July against the sentiment readings for the same days.
Facebook’s share price, volume and daily news sentiment, June–July 2019.

In the above image we can see that the dip in the second week of July 2019 on Facebook stock could have predicted. The bull run for 26th June till 10th July 2019 could be predicted as the last point on Facebook news was positive on 25th June 2019 Thereafter, the sentiments are fairly stable near zero value which indicated there will be a stable change all the way till next non-zero sentiment value.

Further steps of improvement here would be to devise an relatability algorithm as sometimes the news article does not always affect the stock. The other main step would be to figure out the accuracy of this method and how to improve it.

Share on LinkedIn (opens in a new tab) Share on X (opens in a new tab)

Something to add?

A question, a correction or a thought: send me a message. I read and answer every one.

Signal over Noise

A build. A number. A good read.

Occasional notes on FinTech, data and plain writing: one thing I built, one number worth knowing with its source, and one thing worth reading. Sent when there is something worth sending.

Free and occasional. Email confirmation first, one click to unsubscribe, and no tracking pixels. Privacy