Adding new ticker_etf_holders method to quote.py which extracts and returns ETF tickers that hold the given stock as listed on the Finviz page. This allows users to programmatically retrieve ETF holders for analysis or comparison purposes. #141
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.
Type of change
Description
A new method named
ticker_etf_holders()was added to thequote.pymodule. This method allows ETF ticker symbols to be extracted from the Finviz page of a specified stock. It enables programmatic access to the list of ETFs that hold the given ticker for analysis and comparison.The
ticker_etf_holders()method was implemented to locate and parse the "Held by" hyperlink on the Finviz stock page.ETF ticker symbols were extracted from the query string and returned as a cleaned list.
Error handling was added to ensure the method returns an empty list when no ETF holders are available or the structure is invalid.
A descriptive docstring was included to document the method's purpose and return type.
Example:
When called for ticker AAPL, the following ETF holders list is returned:
['VTI', 'VOO', 'IVV', 'SPY', 'VUG', 'QQQ', 'VGT', 'IWF', 'XLK', 'SPLG']Test:
The new
ticker_etf_holders()method was tested usingpytestto ensure reliability and correctness. A test case was written to verify that the method returns a list of ETF ticker symbols for a given stock (e.g., "AAPL"). The test confirmed that the return type is a list, that the list is not empty, and that all elements are strings. The test was executed successfully with no conflicts, and all assertions passed, confirming that the method behaves as expected under normal conditions.