Skip to content

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:

  • date Date - Date of the valuation.
  • period_type PeriodType - Annual, Quarterly, or Monthly.
  • market_cap_intraday int - Calculated using shares_outstanding from the most recently filed report.
  • enterprise_value int - Measure of a company's total value.
  • trailing_pe float - Relative valuation multiple that is based on the last 12 months of actual earnings
  • forward_pe float - 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_expected float - 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_ttm float - Trailing Twelve Months price to sales ratio.
  • price_book_mrq float - todo
  • enterprise_revenue float - todo
  • enterprise_ebitda float - todo

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.

Config

Pydantic config.

ValuationMeasuresTable

Representing the entire Valuation Measures Table on a yahoo finance Statistics Page.

Attributes:

  • valuations List[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_ends Date - todo
  • most_recent_quarter_mrq Date - todo

  • profit_margin float - todo

  • operating_margin_ttm float - todo

  • return_on_assets_ttm float - todo

  • return_on_equity_ttm float - todo

  • revenue_ttm int - todo

  • revenue_per_share_ttm float - todo
  • quarterly_revenue_growth_yoy float - todo
  • gross_profit_ttm int - todo
  • ebitda int - todo
  • net_income_avi_to_common_ttm int - todo
  • diluted_eps_ttm float - todo
  • quarterly_earnings_growth_yoy float - todo

  • total_cash_mrq int - todo

  • total_cash_per_share_mrq float - todo
  • total_debt_mrq int - todo
  • total_debt_equity_mrq float - todo
  • current_ratio_mrq float - todo
  • book_value_per_share_mrq float - todo

  • levered_free_cash_flow_ttm int - todo

  • operating_cash_flow_ttm int - todo

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.

TradingInformation

Trading information section of a yahoo finance statistics page.

Attributes:

  • beta_five_year_monthly float - todo

  • fifty_two_week_change float - todo

  • sp500_fifty_two_week_change float - todo
  • fifty_two_week_high float - todo
  • fifty_two_week_low float - todo
  • fifty_day_moving_average float - todo
  • two_hundred_day_moving_average float - todo

  • average_three_month_volume int - todo

  • average_ten_day_volume int - todo
  • shares_outstanding int - todo
  • float int - todo
  • percent_held_by_insiders float - todo
  • percent_held_by_institutions float - todo

  • shares_short int - todo

  • shares_short_date Date - todo
  • short_ratio float - todo
  • short_ratio_date Date - todo
  • short_percent_of_float float - todo
  • short_percent_of_float_date Date - todo
  • short_percent_of_shares_outstanding float - todo
  • short_percent_of_shares_outstanding_date Date - todo
  • shares_short_prior_month int - todo
  • shares_short_prior_month_date Date - todo

  • forward_annual_dividend_rate float - todo

  • forward_annual_dividend_yield float - todo
  • trailing_annual_dividend_rate float - todo
  • trailing_annual_dividend_yield float - todo

  • five_year_average_dividend_yield float - todo

  • payout_ratio float - todo

  • dividend_date Date - todo
  • exdividend_date Date - todo
  • last_split_factor str - todo
  • last_split_date Date - todo

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.

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_type PeriodType - 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:

  • symbol st - Ticker Symbol.
  • quote Quote - Quote data from the quote header section.
  • valuation_measures ValuationMeasuresTable - Valuation Measures Table section.
  • financial_highlights FinancialHighlights - Financial Highlights section.
  • trading_information TradingInformation - Trading Information section

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.

__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:

  • page StatisticsPage - 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:

  • symbol str - Ticker symbol.
  • use_fuzzy_search bool - If True validates symbol prior to requesting options page data.
  • page_not_found_ok bool - 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:

  • symbols List[str] - Ticker symbols or company names.
  • use_fuzzy_search bool - If True does a symbol lookup validation prior to requesting data.
  • page_not_found_ok bool - If True Returns None when page is not found.
  • with_threads bool - If True uses threading.
  • thread_count int - Number of threads to use if with_threads is set to True.
  • **kwargs - Pass (session, proxies, and timeout) to the requestor function.
  • progress_bar bool - 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.