The purpose of this application is to analyze the sentiments for top to 20 S&P 500 stocks (based on market cap). Streaming Twitter APIs are used to capture the corpus for running the sentiment analysis
A python server is responsible for streaming the tweets based on ticker from Twitter. Tweets are cleansed and queued in SQS. From SQS the tweets are read by a a separate process that score them using vaderSentiment
- Docker
- AWS Command Line Interface
- Python 3.8
- nltk punkt and stopwords packages (https://www.nltk.org/)
- pip python package manager
- Tested on Mac OSX, Ubuntu 14.X, CentOS 6.X
Before getting started update the sentiment_analysis/setup/keys.cfg file with the following:
- Twitter Consumer Key & Consumer Key Secret
- Twitter Key and Twitter Secret
Local Development in an IDE
git clone
# Navigate to sentiment_analysis/setup directory
./setup.sh
# Upload keys.cfg to localstack S3
aws --endpoint-url=http://localhost:4566 s3 mb s3://application-keys
aws --endpoint-url=http://localhost:4566 s3 cp keys.cfg s3://application-keys/
Containerized local development/deployment
git clone
# Navigate to sentiment_analysis/setup directory
./setup.sh
# Upload keys.cfg to localstack S3
aws --endpoint-url=http://localhost:4566 s3 mb s3://application-keys
aws --endpoint-url=http://localhost:4566 s3 cp keys.cfg s3://application-keys/
# Build docker images
docker build -t sentiment_analysis_server -f build/server/Dockerfile .
docker build -t sentiment_analysis_web -f build/web/Dockerfile .
# Run
docker run --network sentimental_network -e LocalDevelopment=1 -e LocalStackContainer=localstack -e RedisContainer=redis sentiment_analysis_server:latest
docker run --network sentimental_network -p 5001:5001 -e LocalDevelopment=1 -e LocalStackContainer=localstack -e RedisContainer=redis sentiment_analysis_web:latest
After the steps mentioned above navigate to http://localhost:5001 to analyze the heat map
Refer to the Workflow for build and deployment details. Following workflows are embedded in it:
- Image build and publish to Github package registry
- Image build and publish to Docker public registry
- Refresh of AWS ECS Service. I have hardcoded the ECS Cluster and Deployment Service name for now.
The output of this analysis is a Tree Map representing the trend based on sentiments on the received tweets
Size of the rectangle in TreeMap for stock A = (TPA + TNA) / TP + TN
Overall Sentiment for stock A = TPA/TP - TNA/TN
TPA: Number of tweets with positive sentiment for stock A
TP: Total number of positive tweets across all stocks
TNA: Number of tweets with negative sentiment for stock A
TN: Total number of negative tweets across all stocks

