Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 0.9.3 instead.
Reason given by maintainers: Forgot req yf>=1.6.0

yfinance-cache

Persistent caching wrapper for yfinance module. Intelligent caching, not dumb caching of web requests - only update cache where missing/outdated and new data expected. Idea is to minimise fetch frequency and quantity - Yahoo API officially only cares about frequency, but I'm guessing they also care about server load from scrapers.

Persistent cache stored in your user cache folder:

  • Windows = C:/Users/<USER>/AppData/Local/py-yfinance-cache
  • Linux = /home/<USER>/.cache/py-yfinance-cache
  • MacOS = /Users/<USER>/Library/Caches/py-yfinance-cache

Install

Available via PIP: pip install yfinance_cache

Interface

Interaction almost identical to yfinance

import yfinance_cache as yfc
dat = yfc.Ticker("MSFT")
dat.history(period="1wk")
dat.calendar
# etc

Supported properties and functions on Ticker class:

isin                income_stmt                analyst_price_targets      insider_purchases         
history()           balance_sheet              earnings_estimate          insider_roster_holders    
history_metadata    cashflow                   earnings_history           insider_transactions      
info                quarterly_income_stmt      eps_revisions              institutional_holders     
options             quarterly_balance_sheet    eps_trend                  major_holders             
option_chain()      quarterly_cashflow         growth_estimates           mutualfund_holders        
news                calendar                   recommendations                                      
                    get_earnings_dates()       recommendations_summary                              
                    get_release_dates()        revenue_estimate                                     
                                               sustainability                                       
                                               upgrades_downgrades

Price data differences

Other people have implemented price caches, but none adjust cached data for new stock splits or dividends. YFC does. Price can be adjusted for stock splits, dividends, or both:

dat.history(..., adjust_splits=True, adjust_divs=True)

Price repair is force-enabled, to prevent bad Yahoo data corrupting cache. See yfinance Wiki for detail.

Returned table has 2 new columns:

  • FetchDate = when data was fetched
  • Final? = true if don't expect future fetches to change

Aging

Concept of max age controls when cached data is updated. If max age time has passed since last fetch then cache is updated. Value must be Timedelta or equivalent str.

Price data aging

df = dat.history(interval="1d", max_age="1h", trigger_at_market_close=False, ...)

With price data, YFC also considers how long exchange been open since last fetch, using exchange_calendars. Only if market been open long enough since last fetch, or if trigger_at_market_close=True and market since closed, is cache refreshed. max_age defaults to half of interval.

Shares aging

df = dat.shares(..., max_age='60d')

Property aging

For data obtained from Ticker properties not functions, max age set in YFC options. Implemented to behave like pandas.options, except YFC options are persistent.

import yfinance_cache as yfc
print(yfc.options)
{
    "max_ages": {
        "calendar": "7d",
        ...
    }
}
yfc.options.max_ages.calendar = '30d'
print(yfc.options)
{
    "max_ages": {
        "calendar": "30d",
        ...
    }
}

Financials

Financials updates are handled different because they don't age. Instead, YFC analyses earnings dates to determine exactly when next earnings will be, or if Yahoo data is incomplete then YFC will predict. You can inspect this schedule in new function dat.get_release_dates().

Offline mode

Disable all web fetches with this special option at top of first script:

import yfinance_cache as yfc
yfc.options.session.offline = True
...

Options in yfc.options.session reset when Python closes.

Verifying cache

Cached prices can be compared against latest Yahoo Finance data, and correct differences:

# Verify prices of one ticker symbol
dat.verify_cached_prices(
	rtol=0.0001,  # relative tolerance for differences
	vol_rtol=0.005,  # relative tolerance specifically for Volume
	correct=[False|'one'|'all'],  # delete incorrect cached data? 'one' = stop after correcting first incorrect prices table ; 'all' = correct all tickers & intervals
	discard_old=False,  # if cached data too old to check (e.g. 30m), assume incorrect and delete?
	quiet=True,  # enable to print nothing, disable to print summary detail of why cached data wrong
	debug=False,  # enable even more detail for debugging 
	debug_interval=None)  # only verify this interval (note: 1d always verified)

# Verify prices of entire cache, ticker symbols processed alphabetically. Recommend using `requests_cache` session.
yfc.verify_cached_tickers_prices(
	session=None,  # recommend you provide a requests_cache here if debugging
	rtol=0.0001,
	vol_rtol=0.005,
	correct=[False|'one'|'all'],
	halt_on_fail=True,  # stop verifying on first fail
	resume_from_tkr=None,  # in case you aborted verification, can jump ahead to this ticker symbol. Append '+1' to start AFTER the ticker
	debug_tkr=None,  # only verify this ticker symbol
	debug_interval=None)

These return False if difference detected else True, regardless of if difference was corrected.

  • to scan for first data mismatch but not correct: yfc.verify_cached_tickers_prices().

  • to fix all data issues: yfc.verify_cached_tickers_prices(correct='all', halt_on_fail=False)

I hope latest version 0.6.2 fixed the last bugs in applying new dividend-adjustments and splits to cached prices (Adj Close etc). Only genuine differences in not-adjusted prices are Volume differences (~0.5%) - Yahoo sometimes changes Volume over 24 hours after that day ended e.g. updating Monday Volume on Wednesday, sometimes weeks later!

If you see big differences in the OHLC price of recent intervals (last few days), probably Yahoo is wrong. Since fetching that price data on day / day after, Yahoo has messed up their data - at least this is my experience. Cross-check against TradingView or stock exchange website.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yfinance_cache-0.9.0.tar.gz (173.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yfinance_cache-0.9.0-py3-none-any.whl (195.2 kB view details)

Uploaded Python 3

File details

Details for the file yfinance_cache-0.9.0.tar.gz.

File metadata

  • Download URL: yfinance_cache-0.9.0.tar.gz
  • Upload date:
  • Size: 173.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.7

File hashes

Hashes for yfinance_cache-0.9.0.tar.gz
Algorithm Hash digest
SHA256 e42b0d4bc33056b74c560dd1eccf37b6083a641c408e52547a98df96fb35fae3
MD5 fd4daa7481affaa3b1980a0366ff2207
BLAKE2b-256 a9e0a29dc1e5ab7cc25dccee4f5f4b136c3ee2fa2d15f8ea882bca2163c86f02

See more details on using hashes here.

File details

Details for the file yfinance_cache-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: yfinance_cache-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 195.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.7

File hashes

Hashes for yfinance_cache-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f19fc651ce1565a80f285c35607f6a4d10bde3810cbaf47ecf03ec7ba00c31b4
MD5 d17a914c19dcc82d95e425dd187dab50
BLAKE2b-256 cf9c6f5a0e3f71c484f5267059b006946ae1501da4d7ff60573ad86563491ec7

See more details on using hashes here.

Release history Release notifications | RSS feed

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

This release

0.9.0 This release

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.15

2 files

0.7.14

2 files

0.7.13

2 files

0.7.12

2 files

0.7.11

2 files

0.7.10

2 files

0.7.9

2 files

0.7.8

2 files

0.7.7

2 files

0.7.6

2 files

0.7.5

2 files

0.7.4

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.9

2 files

0.6.8

2 files

0.6.7

2 files

0.6.6

2 files

0.6.5

2 files

0.6.4

2 files

0.6.3

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.5

2 files

0.5.4

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.9

2 files

0.4.8

2 files

0.4.7

2 files

0.4.6

2 files

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page