NOTE: This website is hosted on Render using Free Web Services.
Web Services on the free instance type are automatically spun down after 15 minutes of inactivity. When a new request for a free service comes in, Render spins it up again so it can process the request.
This will cause a delay in the response of the first request after a period of inactivity while the instance spins up.
Market Sentiment is a web app created with Flask and Bootstrap. It uses Yahooquery to fetch the latest stock data and Marketaux to fetch the latest news on said stock. The data is then stored in Firebase Realtime Database and relevant information is displayed on the web app.
- Realtime stock data
- Realtime stock news
- Realtime stock sentiment
Marketaux's API actually provides the sentiment score for each news, ranging from -1
to 1
. However, the free version of the API only allows 100 requests per day. To get around this, Market Sentiment sends 6 requests per stock, each request targetting a sentiment range and fetching the news count in that range.
The ranges are as follows:
0.15
to0.39
- Weak Positive0.4
to0.69
- Moderate Positive0.7
to1
- Strong Positive-0.15
to-0.39
- Weak Negative-0.4
to-0.69
- Moderate Negative-0.7
to-1
- Strong Negative
The sentiment score is then calculated using the following formula:
raw_sentiment_score =
(weak_positive_news_count) * 1 + (moderate_positive_news_count) * 2 + (strong_positive_news_count) * 3 +
(weak_negative_news_count) * -1 + (moderate_negative_news_count) * -2 + (strong_negative_news_count) * -3
adjusted_sentiment_score =
raw_sentiment_score /
(
(weak_positive_news_count + weak_negative_news_count) * 1 +
(moderate_positive_news_count + moderate_negative_news_count) * 2 +
(strong_positive_news_count + strong_negative_news_count) * 3 +
100 (bayesian extra value)
)
The bayesian extra values are added to ensure that stocks with less news are not ranked higher than stocks with more news if they have the same sentiment score.
To run this project, you will need to add the following environment variables to your .env
file.
MARKETAUX_API_TOKEN
- This is your Marketaux API token.
FIREBASE_DB_URL
- This is your Firebase Realtime Database URL.
In addition, you will need to add serviceAccountKey.json
to the root directory of this project.
To get serviceAccountKey.json
:
- Create your Firebase project
- Click on the project
- Click on the gear icon and select Project Settings
- Click on the Service Accounts tab
- Click on the Generate new private key button
- Rename the downloaded JSON file to
serviceAccountKey.json
- Place the
serviceAccountKey.json
file in the root directory of the project
Clone the project
git clone https://github.com/EricLin-jpg/Market-Sentiment.git
Go to the project directory
cd Market-Sentiment
To run this project with Docker, you will need to install Docker and Docker Compose.
Build the Docker image
docker-compose build
Start the Docker container
docker-compose up
If you do not want to use Docker, you can run this project with Python.
Install dependencies
pip install -r requirements.txt
Start the server
python -m app
Get stock data:
GET /api/stock_data
Get news data:
GET /api/news_data
Frontend: Bootstrap
Charts: Chart.js
Backend: Flask
Database: Firebase Realtime Database
API: Yahooquery, Marketaux