Production-grade Python application for downloading, analyzing, and exporting historical stock price data with advanced financial metrics and comprehensive data validation
Stock Price Downloader is a robust, professional-grade application designed for quantitative analysts, financial engineers, and traders who need reliable, validated historical stock market data. Built with production-grade standards including type hints, comprehensive error handling, and extensive test coverage.
Perfect for:
- Quantitative finance research
- Algorithmic trading strategy backtesting
- Portfolio analysis and optimization
- Financial data engineering
- Academic financial research
Simultaneously download historical data for 50+ stock tickers without blocking. Optimized fetching with rate-limiting and error recovery.
Support for 2-10 year historical analysis. Custom date range selection. Holiday and market closure handling.
Automatically calculated metrics:
- Sharpe Ratio: Risk-adjusted returns
- Volatility (Annualized): Standard deviation of returns
- Maximum Drawdown: Peak-to-trough decline
- Annualized Returns: Total return over time period
- Cumulative Return: Total percentage gain/loss
- Sortino Ratio: Downside risk metric
- Automatic handling of stock splits
- Dividend adjustment detection
- Missing value imputation with forward/backward fill
- Data consistency checks
- Outlier detection and flagging
- Formatted spreadsheets with charts
- Summary statistics sheet
- Detailed metrics per security
- Custom styling and conditional formatting
- Support for multiple sheets
- Comprehensive exception handling
- Detailed logging at multiple levels
- Graceful degradation with fallbacks
- API rate limit handling
- Network retry logic with exponential backoff
- Full type hints across all modules
- MyPy strict mode compatible
- IDE autocomplete support
- Type-checked error messages
- Unit test coverage >85%
- Integration tests included
- Unittest and pytest compatible
- Test fixtures for reproducibility
- Continuous integration ready
- Python 3.8+
- pip or conda
# Clone the repository
git clone https://github.com/DarkenSoul-oo1/bitchyList.git
cd bitchyList/stock-price-downloader
# Install dependencies
pip install -r requirements.txtfrom src.data_fetcher import StockDataFetcher
from src.data_processor import DataProcessor
from src.excel_exporter import ExcelExporter
from datetime import datetime, timedelta
# Initialize components
fetcher = StockDataFetcher()
processor = DataProcessor()
exporter = ExcelExporter()
# Download data for multiple stocks
tickers = ['AAPL', 'MSFT', 'GOOGL', 'TSLA', 'AMZN']
end_date = datetime.now()
start_date = end_date - timedelta(days=365*5) # 5 years
data = fetcher.fetch_stocks(
tickers=tickers,
start_date=start_date,
end_date=end_date,
validate=True
)
# Calculate metrics and validate
processed_data = processor.process(
data=data,
calculate_returns=True,
calculate_volatility=True
)
# Export results
exporter.export(
filename='stock_analysis.xlsx',
data=processed_data,
include_charts=True
)
print("β
Analysis complete! Check 'stock_analysis.xlsx'")stock-price-downloader/
βββ src/
β βββ __init__.py
β βββ data_fetcher.py # Yahoo Finance API integration
β βββ data_processor.py # Metrics calculation & validation
β βββ excel_exporter.py # Excel output formatting
β βββ utils.py # Helper functions
β βββ config.py # Configuration constants
βββ tests/
β βββ __init__.py
β βββ test_data_fetcher.py # Fetcher unit tests
β βββ test_data_processor.py # Processor unit tests
β βββ test_excel_exporter.py # Exporter unit tests
β βββ fixtures.py # Test data fixtures
βββ docs/
β βββ API_REFERENCE.md # Detailed API documentation
β βββ EXAMPLES.md # Usage examples
β βββ TROUBLESHOOTING.md # Common issues & solutions
βββ main.py # CLI entry point
βββ requirements.txt # Python dependencies
βββ .gitignore # Git ignore rules
βββ README.md # This file
Edit src/config.py to customize:
# API Settings
YAHOO_FINANCE_TIMEOUT = 30 # seconds
MAX_RETRIES = 3
RETRY_BACKOFF = 2 # exponential multiplier
# Data Validation
MIN_DATA_POINTS = 100
MAX_MISSING_PERCENT = 5 # %
# Output
EXCEL_DECIMAL_PLACES = 4
EXCEL_INCLUDE_CHARTS = True- yfinance (>=0.2.0): Yahoo Finance data fetching
- pandas (>=1.3.0): Data manipulation and analysis
- openpyxl (>=3.6.0): Excel file handling
- numpy (>=1.21.0): Numerical computations
- python-dateutil (>=2.8.0): Date utilities
See requirements.txt for complete list with pinned versions.
# Run all tests
python -m pytest tests/
# Run with coverage
python -m pytest --cov=src tests/
# Run specific test file
python -m pytest tests/test_data_fetcher.py -v
# Run tests using unittest
python -m unittest discover -s tests -p "test_*.py"{
'AAPL': {
'prices': pd.DataFrame(...),
'metrics': {
'sharpe_ratio': 1.45,
'volatility': 0.28,
'max_drawdown': -0.35,
'annual_return': 0.22,
'cumulative_return': 2.8
},
'validation': {
'missing_values': 0,
'outliers': 2,
'data_quality': 'EXCELLENT'
}
},
# ... more securities
}# Increase timeout and retry attempts
fetcher = StockDataFetcher(
timeout=60,
max_retries=5
)# Use different imputation method
processor = DataProcessor(
missing_value_method='interpolate'
)See docs/TROUBLESHOOTING.md for more solutions.
Typical performance on standard hardware:
- Data fetching: ~100 tickers in 5-10 seconds
- Processing: ~1000 data points in <100ms
- Excel export: ~50 sheets in <2 seconds
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Add tests for new functionality
- Ensure all tests pass (
pytest tests/) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow PEP 8 guidelines
- Use type hints
- Write docstrings for all functions
- Maintain >85% test coverage
DarkenSoul-oo1 - Quantitative Finance Engineer
- GitHub: @DarkenSoul-oo1
- Portfolio: bitchyList
If this project was helpful, please consider:
- β Starring the repository
- π Reporting bugs and issues
- π‘ Suggesting new features
- π’ Sharing with others
This tool is provided for educational and research purposes. Past performance does not guarantee future results. Always validate data independently and conduct thorough due diligence before making investment decisions.
Last Updated: January 2026 | Status: Active Development β