yahoofinance.py


Overview

The yahoofinance.py file provides a component for accessing and retrieving financial market data from Yahoo Finance using the yfinance Python library. It is designed as part of the InfiniFlow system, offering a structured interface to fetch real-time and historical stock data, financial statements, company information, and relevant news. This component enables easy integration of Yahoo Finance data into applications or analysis workflows by wrapping the API calls and formatting the results in markdown-friendly tabular forms.

The file defines two main classes:

The component supports a range of data retrieval options, such as company info, historical prices, financial statements (balance sheet, cash flow, income statement), and news articles related to the stock.


Classes and Functions

Class: YahooFinanceParam (inherits from ToolParamBase)

Purpose

Defines and validates the parameters used to configure the YahooFinance component. It also provides metadata describing the component, including the expected input format.

Attributes

Methods

Usage Example

params = YahooFinanceParam()
params.info = True
params.history = True
params.check()  # Validates parameters
input_form = params.get_input_form()

Class: YahooFinance (inherits from ToolBase, ABC)

Purpose

Implements the main functionality to query Yahoo Finance for stock data based on parameters defined in YahooFinanceParam. It handles retries, timeout, error logging, and formatting of the output.

Class Attributes

Methods

Usage Example

component = YahooFinance()
component._param = YahooFinanceParam()
component._param.info = True
component._param.history = True
result = component._invoke(stock_code="AAPL")
print(result)

Important Implementation Details and Algorithms


Interaction with Other Parts of the System


Visual Diagram

classDiagram
    class YahooFinanceParam {
        +meta: ToolMeta
        +info: bool
        +history: bool
        +count: bool
        +financials: bool
        +income_stmt: bool
        +balance_sheet: bool
        +cash_flow_statement: bool
        +news: bool
        +__init__()
        +check()
        +get_input_form() dict
    }

    class YahooFinance {
        +component_name: str = "YahooFinance"
        +_invoke(**kwargs) str
        +thoughts() str
    }

    YahooFinance --> YahooFinanceParam : uses
    YahooFinance ..|> ToolBase
    YahooFinanceParam ..|> ToolParamBase

Summary

The yahoofinance.py file encapsulates a reusable component for querying Yahoo Finance data within the InfiniFlow platform. By abstracting parameter handling, API querying, error management, and output formatting, it simplifies integration of comprehensive financial data into larger applications or automated workflows. The design emphasizes configurability, robustness, and clear, markdown-friendly output suited for user interfaces or reports.