GithubHelp home page GithubHelp logo

eric-exe / market-sentiment Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 1.0 283 KB

A website showing several companies' stocks and their market sentiments using Yahooquery and Marketaux API.

Home Page: https://market-sentiment.onrender.com/

License: MIT License

Python 68.34% HTML 22.82% JavaScript 7.50% Dockerfile 0.22% CSS 1.12%
bootstrap flask market-sentiment market-news news yahoo-finance

market-sentiment's Introduction

License Codacy Badge Size


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.

Features

  • Realtime stock data
  • Realtime stock news
  • Realtime stock sentiment

Sentiment Analysis

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 to 0.39 - Weak Positive
  • 0.4 to 0.69 - Moderate Positive
  • 0.7 to 1 - 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.

Preview

Preview

Environment Variables

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:

  1. Create your Firebase project
  2. Click on the project
  3. Click on the gear icon and select Project Settings
  4. Click on the Service Accounts tab
  5. Click on the Generate new private key button
  6. Rename the downloaded JSON file to serviceAccountKey.json
  7. Place the serviceAccountKey.json file in the root directory of the project

Run Locally

Clone the project

  git clone https://github.com/EricLin-jpg/Market-Sentiment.git

Go to the project directory

  cd Market-Sentiment

Docker

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

Python

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

API

Get stock data:

GET /api/stock_data

Get news data:

GET /api/news_data

Built With

Frontend: Bootstrap

Charts: Chart.js

Backend: Flask

Database: Firebase Realtime Database

API: Yahooquery, Marketaux

market-sentiment's People

Contributors

dependabot[bot] avatar eric-exe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

jinhwachiu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.