Yahoo Finance Data Integration
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The Yahoo Finance data integration in the stolgo ecosystem is primarily facilitated through the bandl library (a dependency mentioned for data feeding). Its purpose is to provide a standardized interface for fetching financial market data—specifically for Indian (NSE/BSE) stocks—to be used for price action analysis, backtesting, and pattern recognition within the stolgo library.
While stolgo contains internal modules for other data providers like Nasdaq and Samco, it leverages the bandl.yfinance module to allow users to retrieve historical stock data by simply calling a get_data API. This integration ensures that the resulting data is formatted as a Pandas DataFrame, compatible with stolgo’s analytic tools such as Candlestick Pattern Recognition and Breakout Detection.
Sources: README.md:27-35, setup.py:22-29
External Dependency: Bandl.io
The stolgo library relies on bandl as its primary data feed engine. This allows the system to remain decoupled from the specifics of the Yahoo Finance API while providing a simple wrapper to access its data.
Yfinance Data Retrieval Flow
The integration uses the Yfinance class to handle requests. The following diagram illustrates the interaction between a user application, the bandl wrapper, and the data consumed by stolgo.
The flow shows how bandl acts as the bridge between raw financial data and the stolgo analysis modules.
Sources: README.md:27-44
Data Requirements and Formatting
For successful integration, the data retrieved from Yahoo Finance (via bandl) must conform to specific structures to be processed by stolgo's internal helpers and analysis classes.
Date Handling
The system utilizes stolgo.helper to manage date ranges and formatting. Even when data is fetched from external sources like Yahoo Finance, stolgo's internal logic often requires standardized date intervals.
| Function | Purpose | Source |
|---|---|---|
get_date_range | Generates start and end timestamps for API queries. | helper.py:53-85 |
get_formated_date | Converts various date formats into a standard %m/%d/%Y %H:%M:%S. | helper.py:17-31 |
get_data_resample | Aggregates data into different timeframes (OHLCV). | helper.py:87-90 |
Column Structure
stolgo expects a Pandas DataFrame with a specific set of columns for its technical analysis modules:
- Open: The opening price of the period.
- High: The highest price reached.
- Low: The lowest price reached.
- Close: The closing price.
- Volume: The total shares/contracts traded.
The get_data_resample function ensures these columns are title-cased and aggregated correctly if the user requests a different interval.
Sources: lib/stolgo/helper.py:87-90, lib/stolgo/samco.py:166-174
Comparison with Internal Data Modules
While Yahoo Finance is a primary suggestion for general use, stolgo maintains similar patterns for its internal Nasdaq and Samco modules, highlighting the architecture's reliance on the RequestUrl utility.
Request Architecture
Internal modules use a common request pattern that the Yahoo Finance integration likely mirrors through bandl:
The RequestUrl class provides a robust session management system with a default timeout of 5 seconds and a MAX_RETRIES of 2, ensuring stable data ingestion from financial APIs.
Sources: lib/stolgo/request.py:65-98, lib/stolgo/nasdaq.py:34-40
Usage Example
To integrate Yahoo Finance data for NSE stock analysis, the following implementation pattern is used:
from bandl.yfinance import Yfinance
from stolgo.candlestick import CandleStick
# 1. Initialize data feed
yf = Yfinance()
# 2. Fetch data (e.g., State Bank of India)
# Sources: [README.md:33-35]
dfs = yf.get_data("SBIN", start="21-Jan-2020")
# 3. Analyze using stolgo patterns
# Sources: [README.md:46-49]
candle_test = CandleStick()
is_bullish = candle_test.is_bullish_engulfing(dfs)
Summary
The Yahoo Finance integration represents the "Data Feed" layer of the stolgo architecture. By utilizing the bandl library, stolgo provides a streamlined path for developers to move from raw market data to actionable price action insights. The integration's success relies on the standardization of data into Pandas DataFrames, which are then processed by the core stolgo modules for trend, breakout, and candlestick analysis.
Sources: README.md:14-25, setup.py:22-29