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.
- 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
- 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
- Latest News Integration: Fetch and display relevant stock news
- Real-time Data: Access to current market data via Yahoo Finance API
- 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
- Python 3.7 or higher (Python 3.8+ recommended)
- pip package manager
- Git (for cloning the repository)
- Clone or download the project files
- Install all dependencies at once:
pip install -r requirements.txt- Import the package:
import StockAnalysisPackage as sap# 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()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
Fetches historical stock data from Yahoo Finance.
- Validates stock symbol and date ranges
- Returns DataFrame with OHLCV data
Calculates moving average over specified window.
- window (int): Period for calculation (default: 21)
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)
Calculates Bollinger Bands with standard deviation.
- window (int): Moving average period (default: 20)
- num_std (int): Number of standard deviations (default: 2)
Calculates Relative Strength Index.
- window (int): RSI calculation period (default: 14)
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"
Fetches and displays latest news related to the stock.
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
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
If you encounter import errors, ensure all dependencies are installed:
pip install -r requirements.txt- 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.
- Jupyter Notebook: For Jupyter notebooks, ensure you have the required extensions:
pip install jupyter-dash
jupyter labextension install jupyterlab-dash- Always use 'YYYY-MM-DD' format for dates
- Ensure dates are within valid ranges for the selected stock
See StockPackageCheck.ipynb for comprehensive examples demonstrating:
- Error handling scenarios
- All technical indicators
- Various visualization options
- News fetching functionality
This project is for educational purposes as part of FE520 coursework.
- 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.