Skip to content

A Python tool for analyzing stock performance over a specified period. It fetches data from Yahoo Finance, calculates key metrics like price growth and volatility, and identifies top and bottom performers. The tool sends email reports with analysis results and attachments using the Gmail API, making it ideal for investors and analysts.

Notifications You must be signed in to change notification settings

MasoudMiM/stock-performance-analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stock Performance Analyzer

A tool for analyzing stock performance over a specified period. This project fetches stock data from Yahoo Finance, calculates performance metrics, and generates visual reports. It can also send email reports with the analysis results.

Features

Thie code

  • Fetches stock data for tickers listed in NASDAQ_sample and NYSE_sample files from Yahoo Finance.
  • Calculates performance metrics including price growth and volatility.
  • Identifies top and bottom performing stocks from the list of stocks provided.
  • Generates visual plots of stock performance.
  • Sends an email report with analysis results and attached plots using the Gmail API.
  • Logs for tracking the execution and debugging.

Requirements

  • Python 3.11
  • Required Python packages:
    • yfinance
    • numpy
    • pandas
    • matplotlib
    • google-auth
    • google-auth-oauthlib
    • google-api-python-client
    • tenacity

You can install the required packages using pip:

pip install yfinance numpy pandas matplotlib google-auth google-auth-oauthlib google-api-python-client tenacity

Setup

  1. Clone the repository:

    git clone https://github.com/MasoudMiM/stock-performance-analyzer.git
    cd stock-performance-analyzer
  2. Prepare input files:

    • Create two text files named NASDAQ_sample.txt and NYSE_sample.txt in the data directory. Each file should contain stock tickers and their names in a tab-delimited format. The first row should be a header.

    Example format:

    Ticker    Name
    AAPL      Apple Inc.
    MSFT      Microsoft Corp.
    
  3. Set up Google API for email:

    • Go to the Google Cloud Console.
    • Create a new project.
    • Enable the Gmail API for your project.
    • Create OAuth 2.0 credentials and download the client_secret.json file.
    • Place the client_secret.json file in the root directory of the project.
  4. Run the script:

    • You can run the script with default parameters or specify your own. The default parameters are set to analyze stocks over the last 90 days and send the report to a specified email.
    python stock_analysis.py

    To customize the parameters, modify the main function call at the bottom of the script:

    if __name__ == '__main__':
        main(days=DAYS, top_n=N_STOCK, recipient_email=MY_EMAIL)

Example Output

You can find a sample output here for the given sample stock names in the text files under data folder.

Usage

  • The script will log its progress and results in a log file located in the logs directory.
  • The analysis results will be saved in the outputs directory, including CSV files for top and bottom performing stocks and plots of their performance.
  • An email report will be sent to the specified recipient email if provided.

About

A Python tool for analyzing stock performance over a specified period. It fetches data from Yahoo Finance, calculates key metrics like price growth and volatility, and identifies top and bottom performers. The tool sends email reports with analysis results and attachments using the Gmail API, making it ideal for investors and analysts.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages