liveBook · Manning

Yfinance

As explained in Investing for Programmers

yfinance is a Python library that retrieves financial market data from Yahoo Finance and exposes it through a programmatic interface.

yfinance is a free, open-source Python library for retrieving financial data from Yahoo Finance. It loads market information into Python data structures, making it a practical starting point for experimenting with fundamental and technical analysis. section 3.0 section 3.4

Use yfinance to collect and inspect several kinds of investment data:

  • Create a Ticker object with a stock symbol such as MSFT, AAPL, RR.L, or ALV.DE. section 3.4
  • Retrieve income statements, balance sheets, cash-flow statements, quarterly statements, and company information. section 3.4.1
  • Read financial ratios and corporate attributes such as current price, sector, industry, current ratio, and quick ratio. section 3.4.1
  • Combine collected statements to calculate measures such as return on assets, return on equity, profit margin, asset turnover, and debt-to-equity. section 3.4.1
import yfinance as yf
microsoft = yf.Ticker('MSFT')
microsoft.income_stmt
microsoft.balance_sheet
microsoft.cash_flow

The basic workflow creates a Ticker object and exposes accounting statements as DataFrames, which can then be indexed by reporting date and metric. section 3.4.1

Comparing company ratios

A helper function can loop over tickers such as WMT, MO, NVDA, and CRM, collect selected attributes from each Ticker.info dictionary, and return one Pandas DataFrame with a row per company. section 3.4.1

Treat yfinance as an exploratory tool rather than a guaranteed production data service. It wraps Yahoo’s internal API and uses web-scraping frameworks; Yahoo does not maintain the library, so platform changes or anti-scraping measures could break it without warning. Check ticker conventions across exchanges, monitor library updates, and consider paid providers when reliability, quotas, or service guarantees matter. section 3.4.3 section 3.5 section 3.6

How Investing for Programmers covers it

How deep it goes
Exposes ticker objects, statement DataFrames, company attributes, and derived ratios, but stops short of production-grade data guarantees.
Examples
Demonstrates Microsoft statements, selected reporting dates, ratio calculations, and multi-company comparisons.
What it assumes
Assumes basic Python and Pandas familiarity while introducing ticker symbols, financial statements, and statement-derived ratios.
What you can do after
Apply it via Python to retrieve company statements, inspect ratios, and assemble exploratory comparison DataFrames.
How it connects
Connects fundamental analysis, technical analysis, financial ratios, Pandas DataFrames, web scraping, and commercial financial-data APIs.

Also explained in

Compare how 2 books explain yfinance →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Investing for Programmers. The section links point to the parts of the book it draws on.