Giter VIP home page Giter VIP logo

python_ai_stock_screening_and_sentiment_analysis's Introduction

AI Stock Screening and Sentiment Analysis

Overview This Python script utilizes artificial intelligence (A.I.) and Python to streamline the process of stock screening and sentiment analysis. The goal is to identify potentially undervalued stocks by applying specific financial criteria and analyzing sentiment from news articles. The script integrates various libraries, including finvizfinance, transformers, yfinance, and goose3, to fetch financial data, perform sentiment analysis, and extract relevant information from news articles.

Installation

Before running the script, ensure that the required libraries are installed. You can install them using the following command:

bash Copy code pip install finvizfinance pandas datetime requests bs4 lxml beautifulsoup4 zope.interface pytz numpy charset-normalizer idna urllib3 yfinance goose3 transformers Usage

1. Undervalued Stock Screening

To identify undervalued stocks, use the get_undervalued_stocks function. It applies filters such as positive operating margin, low debt-to-equity ratio, low P/B and P/E ratios, positive insider transactions, and a specified market capitalization range.

python Copy code undervalued_stocks = get_undervalued_stocks() print(undervalued_stocks)

2. Sentiment Analysis on News Articles

For each undervalued stock, sentiment analysis is performed on related news articles. The get_ticker_news_sentiment function retrieves news articles using Yahoo Finance, applies sentiment analysis using the FinBERT model, and constructs a DataFrame with the results.

python Copy code ticker_sentiment_df = get_ticker_news_sentiment(undervalued_stocks) print(ticker_sentiment_df) 3. Generate CSV Files To save sentiment analysis results for each undervalued stock as a CSV file, use the generate_csv function.

python Copy code for ticker in undervalued_stocks: generate_csv(ticker)

3. generate_csv Function

This function generates CSV files for sentiment analysis results related to each stock ticker.

Components

  1. get_undervalued_stocks Function This function fetches undervalued stocks based on specific financial criteria, including positive operating margin, low debt-to-equity ratio, and more. It utilizes the finvizfinance library for data retrieval.

  2. get_ticker_news_sentiment Function This function performs sentiment analysis on news articles related to a list of stock tickers. It uses Yahoo Finance for news retrieval, the FinBERT model for sentiment analysis, and the goose3 library for web scraping.

Notes Adjust parameters in the script to suit specific needs, such as industry-specific filtering. Ensure proper authentication for the Hugging Face Hub if using private models. The script creates an 'out' directory to store CSV files. Disclaimer This script is for educational purposes only and does not constitute financial advice. Use it responsibly and consult with financial professionals before making investment decisions.

python_ai_stock_screening_and_sentiment_analysis's People

Contributors

segzee avatar

Watchers

 avatar

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.