Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Stock Analysis Package πŸ“ˆ

A powerful and user-friendly Python-based stock analysis tool designed to empower investors and financial analysts with comprehensive insights for informed decision-making in the dynamic world of stock markets.

πŸš€ Features

πŸ“Š Technical Analysis Tools

  • Moving Averages: Calculate and visualize moving averages with customizable windows
  • MACD Analysis: Moving Average Convergence/Divergence with signal line and histogram
  • Bollinger Bands: Upper and lower bands with standard deviation analysis
  • RSI (Relative Strength Index): Momentum oscillator for overbought/oversold conditions

πŸ“ˆ Data Visualization

  • Interactive Candlestick Charts: Professional-grade price charts using Plotly
  • Multiple Chart Types: Support for various technical indicators overlay
  • Customizable Date Ranges: Flexible plotting with date range selection

πŸ“° Market Intelligence

  • Latest News Integration: Fetch and display relevant stock news
  • Real-time Data: Access to current market data via Yahoo Finance API

πŸ›‘οΈ Robust Error Handling

  • Input Validation: Comprehensive validation for stock symbols and dates
  • Date Range Checks: Ensures requested dates are within valid ranges
  • Symbol Verification: Validates stock symbols and excludes non-equity instruments

πŸ“¦ Installation

Prerequisites

  • Python 3.7 or higher (Python 3.8+ recommended)
  • pip package manager
  • Git (for cloning the repository)

Quick Setup

  1. Clone or download the project files
  2. Install all dependencies at once:
pip install -r requirements.txt
  1. Import the package:
import StockAnalysisPackage as sap

🎯 Quick Start

Basic Usage

# Import the package
import StockAnalysisPackage as sap

# Create a stock analysis object
stock = sap.StockAnalysis(
    symbol='AAPL',           # Stock symbol
    start_date='2023-01-01', # Start date (YYYY-MM-DD)
    end_date='2023-12-31'    # End date (YYYY-MM-DD)
)

# Fetch stock data
stock.fetch_stock_data()

# Calculate technical indicators
stock.calculate_moving_average(window=20)
stock.calculate_macd()
stock.calculate_bollinger_bands()
stock.calculate_rsi()

# Visualize data
stock.visualize_data(options="ma")  # Moving average overlay
stock.visualize_data(options="macd")  # MACD chart
stock.visualize_data(options="bollinger_bands")  # Bollinger Bands
stock.visualize_data(options="rsi")  # RSI indicator

# Get latest news
stock.get_latest_news()

πŸ“‹ API Reference

StockAnalysis Class

Constructor

StockAnalysis(symbol, start_date, end_date)
  • symbol (str): Stock ticker symbol (e.g., 'AAPL', 'GOOGL')
  • start_date (str): Start date in 'YYYY-MM-DD' format
  • end_date (str): End date in 'YYYY-MM-DD' format

Methods

fetch_stock_data()

Fetches historical stock data from Yahoo Finance.

  • Validates stock symbol and date ranges
  • Returns DataFrame with OHLCV data
calculate_moving_average(window=21)

Calculates moving average over specified window.

  • window (int): Period for calculation (default: 21)
calculate_macd(short_window=13, long_window=33, signal_window=9)

Calculates MACD indicator with customizable parameters.

  • short_window (int): Short-term EMA period (default: 13)
  • long_window (int): Long-term EMA period (default: 33)
  • signal_window (int): Signal line period (default: 9)
calculate_bollinger_bands(window=20, num_std=2)

Calculates Bollinger Bands with standard deviation.

  • window (int): Moving average period (default: 20)
  • num_std (int): Number of standard deviations (default: 2)
calculate_rsi(window=14)

Calculates Relative Strength Index.

  • window (int): RSI calculation period (default: 14)
visualize_data(plot_start=None, plot_end=None, options=None)

Creates interactive charts with various options.

  • plot_start (str): Plot start date (optional)
  • plot_end (str): Plot end date (optional)
  • options (str): Chart type - "ma", "macd", "macd_hist", "bollinger_bands", "rsi"
get_latest_news()

Fetches and displays latest news related to the stock.

πŸ“Š Visualization Options

The visualize_data() method supports multiple chart types:

  • Default: Basic candlestick chart
  • "ma": Candlestick with moving average overlay
  • "macd": MACD line and signal line
  • "macd_hist": MACD histogram
  • "bollinger_bands": Candlestick with Bollinger Bands
  • "rsi": RSI indicator with overbought/oversold levels

πŸ” Error Handling

The package includes comprehensive error handling for:

  • Invalid Stock Symbols: Non-existent or non-equity tickers
  • Date Range Errors: Dates outside valid ranges or future dates
  • Missing Data: Attempts to visualize uncalculated indicators
  • Network Issues: Connection problems with Yahoo Finance API

πŸ› οΈ Troubleshooting

Common Issues

Import Errors

If you encounter import errors, ensure all dependencies are installed:

pip install -r requirements.txt

Yahoo Finance API Issues

  • Rate Limiting: The Yahoo Finance API has rate limits. If you encounter errors, wait a few minutes before retrying.
  • Network Connectivity: Ensure you have a stable internet connection for data fetching.

Plotly Display Issues

  • Jupyter Notebook: For Jupyter notebooks, ensure you have the required extensions:
pip install jupyter-dash
jupyter labextension install jupyterlab-dash

Date Format Issues

  • Always use 'YYYY-MM-DD' format for dates
  • Ensure dates are within valid ranges for the selected stock

πŸ“ Example Usage

See StockPackageCheck.ipynb for comprehensive examples demonstrating:

  • Error handling scenarios
  • All technical indicators
  • Various visualization options
  • News fetching functionality

πŸ“„ License

This project is for educational purposes as part of FE520 coursework.

πŸ™ Acknowledgments

  • Yahoo Finance API: For providing real-time market data
  • Plotly: For interactive charting capabilities
  • Pandas: For data manipulation and analysis

Note: This package is designed for educational and research purposes. Always conduct thorough analysis and consider consulting with financial professionals before making investment decisions.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages