Statistics Module
Contains the classes and functions for scraping a yahoo finance statistics page.
PeriodType
Enum which describes the period the data represents.
Valuation
Data representing the intrinsic value of an asset for a single date.
This is for one column of an entire valuation table.
Attributes:
dateDate - Date of the valuation.period_typePeriodType - Annual, Quarterly, or Monthly.market_cap_intradayint - Calculated using shares_outstanding from the most recently filed report.enterprise_valueint - Measure of a company's total value.trailing_pefloat - Relative valuation multiple that is based on the last 12 months of actual earningsforward_pefloat - Forward price-to-earnings (forward P/E) is a version of the ratio of price-to-earnings (P/E) that uses forecasted earnings for the P/E calculation.peg_ratio_five_year_expectedfloat - A valuation metric for determining the relative trade-off between the price of a stock, the EPS, and the company's expected growth.price_sales_ttmfloat - Trailing Twelve Months price to sales ratio.price_book_mrqfloat - todoenterprise_revenuefloat - todoenterprise_ebitdafloat - todoNotes:
This class inherits from the pydantic BaseModel which allows for the use of .json() and .dict() for serialization to json strings and dictionaries.
.json()- Serialize to a JSON object..dict()- Serialize to a dictionary.
Config
Pydantic config.
ValuationMeasuresTable
Representing the entire Valuation Measures Table on a yahoo finance Statistics Page.
Attributes:
valuationsList[Valuation] - A list of valuation objects.Notes:
This class inherits from the pydantic BaseModel which allows for the use of .json() and .dict() for serialization to json strings and dictionaries.
.json()- Serialize to a JSON object..dict()- Serialize to a dictionary.
dataframe
| def dataframe() -> DataFrame
Return the Valuation Measures Table as a dataframe.
FinancialHighlights
Financial highlights section of a yahoo finance statistics page.
Attributes:
fiscal_year_endsDate - todo
most_recent_quarter_mrqDate - todo
profit_marginfloat - todo
operating_margin_ttmfloat - todo
return_on_assets_ttmfloat - todo
return_on_equity_ttmfloat - todo
revenue_ttmint - todorevenue_per_share_ttmfloat - todoquarterly_revenue_growth_yoyfloat - todogross_profit_ttmint - todoebitdaint - todonet_income_avi_to_common_ttmint - tododiluted_eps_ttmfloat - todo
quarterly_earnings_growth_yoyfloat - todo
total_cash_mrqint - todototal_cash_per_share_mrqfloat - todototal_debt_mrqint - todototal_debt_equity_mrqfloat - todocurrent_ratio_mrqfloat - todo
book_value_per_share_mrqfloat - todo
levered_free_cash_flow_ttmint - todooperating_cash_flow_ttmint - todoNotes:
This class inherits from the pydantic BaseModel which allows for the use of .json() and .dict() for serialization to json strings and dictionaries.
.json()- Serialize to a JSON object..dict()- Serialize to a dictionary.
TradingInformation
Trading information section of a yahoo finance statistics page.
Attributes:
beta_five_year_monthlyfloat - todo
fifty_two_week_changefloat - todosp500_fifty_two_week_changefloat - todofifty_two_week_highfloat - todofifty_two_week_lowfloat - todofifty_day_moving_averagefloat - todo
two_hundred_day_moving_averagefloat - todo
average_three_month_volumeint - todoaverage_ten_day_volumeint - todoshares_outstandingint - todofloatint - todopercent_held_by_insidersfloat - todo
percent_held_by_institutionsfloat - todo
shares_shortint - todoshares_short_dateDate - todoshort_ratiofloat - todoshort_ratio_dateDate - todoshort_percent_of_floatfloat - todoshort_percent_of_float_dateDate - todoshort_percent_of_shares_outstandingfloat - todoshort_percent_of_shares_outstanding_dateDate - todoshares_short_prior_monthint - todo
shares_short_prior_month_dateDate - todo
forward_annual_dividend_ratefloat - todoforward_annual_dividend_yieldfloat - todotrailing_annual_dividend_ratefloat - todo
trailing_annual_dividend_yieldfloat - todo
five_year_average_dividend_yieldfloat - todo
payout_ratiofloat - tododividend_dateDate - todoexdividend_dateDate - todolast_split_factorstr - todolast_split_dateDate - todoNotes:
This class inherits from the pydantic BaseModel which allows for the use of .json() and .dict() for serialization to json strings and dictionaries.
.json()- Serialize to a JSON object..dict()- Serialize to a dictionary.
parse_valuation_table
def parse_valuation_table(html: HTML, period_type: PeriodType = PeriodType.QUARTERLY) -> Optional[ValuationMeasuresTable]
Parse and clean fields and rows of a valuation measures table HTML element.
Arguments:
html- Html element containing valuation table data.period_typePeriodType - The period to be parsed. Only quarterly is currently supported.Returns:
ValuationMeasuresTable- If data is found.None- No data available.
parse_financial_highlights_table
def parse_financial_highlights_table(html: HTML) -> Optional[FinancialHighlights]
Parse and clean fields and rows of a financial highlights section of an HTML element.
parse_trading_information_table
def parse_trading_information_table(html: HTML) -> Optional[TradingInformation]
Parse and clean fields and rows of a trading information section of an HTML element.
StatisticsPage
Represents all data you can find on a yahoo finance statistics page.
Attributes:
symbolst - Ticker Symbol.quoteQuote - Quote data from the quote header section.valuation_measuresValuationMeasuresTable - Valuation Measures Table section.financial_highlightsFinancialHighlights - Financial Highlights section.trading_informationTradingInformation - Trading Information sectionNotes:
This class inherits from the pydantic BaseModel which allows for the use of .json() and .dict() for serialization to json strings and dictionaries.
.json()- Serialize to a JSON object..dict()- Serialize to a dictionary.
__lt__
| def __lt__(other) -> bool
Compare StatisticsPage objects to allow ordering by symbol.
StatisticsPageGroup
Multiple Statistics Pages Group together.
Attributes:
pages- Multiple StatisticsPage objects. A page for each symbol requested.Notes:
This class inherits from the pydantic BaseModel which allows for the use of .json() and .dict() for serialization to json strings and dictionaries.
.json()- Serialize to a JSON object..dict()- Serialize to a dictionary.
append
| def append(page: StatisticsPage) -> None
Append a StatisticsPage to the StatisticsPageGroup.
Arguments:
pageStatisticsPage - A StatisticsPage object to add to the group.
symbols
| def symbols() -> List[str]
List of symbols in the StatisticsPageGroup.
sort
| def sort() -> None
Sort StatisticsPage objects by symbol.
dataframe
| def dataframe() -> DataFrame
Return a dataframe of multiple statistics pages.
__iter__
| def __iter__() -> Iterable
Iterate over StatisticsPage objects.
__len__
| def __len__() -> int
Length of StatisticsPage objects.
get_statistics_page
def get_statistics_page(symbol: str, use_fuzzy_search: bool = True, page_not_found_ok: bool = False, **kwargs, ,) -> Optional[StatisticsPage]
Get statistics page data.
Arguments:
symbolstr - Ticker symbol.use_fuzzy_searchbool - If True validates symbol prior to requesting options page data.page_not_found_okbool - If True Returns None when page is not found.**kwargs- Pass (session, proxies, and timeout) to the requestor function.Returns:
StatisticsPage- When data is found.None- No data is found and page_not_found_ok is True.Raises:
AttributeError- When a page is not found and the page_not_found_ok arg is false.
get_multiple_statistics_pages
def get_multiple_statistics_pages(symbols: List[str], use_fuzzy_search: bool = True, page_not_found_ok: bool = True, with_threads: bool = False, thread_count: int = 5, progress_bar: bool = True, **kwargs, ,) -> Optional[StatisticsPageGroup]
Get multiple statistics pages.
Arguments:
symbolsList[str] - Ticker symbols or company names.use_fuzzy_searchbool - If True does a symbol lookup validation prior to requesting data.page_not_found_okbool - If True Returns None when page is not found.with_threadsbool - If True uses threading.thread_countint - Number of threads to use if with_threads is set to True.**kwargs- Pass (session, proxies, and timeout) to the requestor function.progress_barbool - If True shows the progress bar else the progress bar is not shown.Returns:
StatisticsPageGroup- When data is found.None- No data is found and page_not_found_ok is True.Raises:
AttributeError- When a page is not found and the page_not_found_ok arg is false.