feat: add Yahoo Finance OHLCV data provider#470
Merged
Conversation
- Add YahooOHLCVDataProvider class for stocks, ETFs, indices, forex, and crypto - Support market='YAHOO' in DataSource to auto-select Yahoo provider - Implement has_data, get_data, prepare_backtest_data, get_backtest_data, copy - Map framework TimeFrame values to yfinance intervals - Register as default data provider alongside CCXT - Add comprehensive unit tests with mocked yfinance
- Add AlphaVantageOHLCVDataProvider (market='ALPHA_VANTAGE') with API key via MarketCredential - Add PolygonOHLCVDataProvider (market='POLYGON') with API key via MarketCredential - Both follow same pattern as Yahoo/CCXT: auto-selected based on market value - Add alpha_vantage and polygon-api-client dependencies - Register both as default data providers - Add comprehensive unit tests (32 tests with mocked external calls)
Introduce an intermediate base class OHLCVDataProviderBase that handles all shared OHLCV data provider logic: - Constructor, copy(), get_data(), prepare_backtest_data(), get_backtest_data() - CSV storage helpers, date range resolution, number of data points - Fixes bug: create_start_date was missing from Yahoo/AV/Polygon providers Concrete providers now only implement: - market_name, timeframe_map (class attributes) - _download_ohlcv() (API-specific download) - _validate_symbol() (optional, Yahoo only) Reduces Yahoo/AlphaVantage/Polygon from ~1,851 lines to ~1,033 total (44% reduction). CCXT intentionally excluded (different pattern: exchange-based detection, pagination, ticker support).
- Remove unused imports (F401) in alpha_vantage, polygon, yahoo, ohlcv_base - Fix CSVOHLCVDataProvider __init__ docstring placement - Fix PandasOHLCVDataProvider docstring: 'CSV file' -> 'pandas DataFrame' - Add custom data providers documentation - Update data sources docs with market info and links
- Move yfinance, alpha_vantage, polygon-api-client from required to optional deps - Add poetry extras: [yahoo], [alpha_vantage], [polygon], [all] - Use lazy imports with placeholder classes that raise helpful ImportError - Only include available providers in get_default_data_providers() - Update installation docs with extras install commands - Add install hints to each provider section in data-sources docs
The metrics module imported yfinance at module level, which broke the entire framework when yfinance was not installed (now optional). Move import inside get_risk_free_rate_us() with graceful fallback.
Instead of returning None, fall back to a 4% default rate so metrics like Sortino/Sharpe ratios work without yfinance installed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
YahooOHLCVDataProviderthat enables fetching OHLCV data from Yahoo Finance via theyfinancelibrary.Closes #469
Changes
New file:
investing_algorithm_framework/infrastructure/data_providers/yahoo.pyYahooOHLCVDataProviderclass supporting stocks, ETFs, indices, forex, and cryptomarket="YAHOO"inDataSourceto auto-select this provider (same pattern as CCXT)has_data(),get_data(),prepare_backtest_data(),get_backtest_data(),copy()TimeFramevalues to yfinance intervals (1m, 5m, 1h, 1d, 1W, 1M, etc.)Modified:
__init__.pyfiles to export and registerYahooOHLCVDataProvideras a default providerNew tests:
tests/infrastructure/data_providers/test_yahoo_ohlcv_data_provider.pyUsage
Closes #469