Skip to main content

Smart caching wrapper for 'yfinance' module

Project description

yfinance-cache

Caching wrapper for yfinance module. Intelligent caching, not dumb caching of web requests:

  • If requested data not in cache, yfinance is called
  • If all requested data is in cache, return that
  • If some in cache but some missing, ask yfinance for the missing data

Additional logic decides if cached data needs refresh.

Interface

Interaction is almost identical to yfinance. Differences are highlighted underneath code:

import yfinance_cache as yf

msft = yf.Ticker("MSFT")

# get stock info
msft.info

# get historical market data
hist = msft.history(period="max")
...
# etc. See yfinance documentation for full API

Refreshing cache

msft = yf.Ticker(interval="1d", max_age=datetime.timedelta(hours=1), ...)

max_age controls when to refresh cached data to avoid spam. If market is still open and max_age time has passed since last fetch, then today's cached price data will be refreshed. Defaults to half of interval. Refresh also triggered if market closed since last fetch.

Adjusting price

Price can be adjusted for stock splits, dividends, or both. yfinance only allows control of dividends adjustment via auto_adjust. How Yahoo adjusts for dividends is slightly mysterious so djusted prices are slightly different to Yahoo (tiny relative error ~1e-7)

msft = yf.Ticker(..., adjust_splits=True, adjust_divs=True)

Installation

Available on PIP: pip install yfinance_cache

Known issues / pending tasks

  • Considering adding a 'verify' function, checking all cached data against Yahoo.
  • Add refresh check to financials data, then to earnings dates.

Limitations

Code is being actively developed so some features missing:

  • only price data is checked if refresh needed
  • Tickers class and download() not available - use Ticker.history()
  • pre/post price data not available

Project details


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.3.5.tar.gz (81.8 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.3.5-py3-none-any.whl (101.9 kB view details)

Uploaded Python 3

File details

Details for the file yfinance-cache-0.3.5.tar.gz.

File metadata

  • Download URL: yfinance-cache-0.3.5.tar.gz
  • Upload date:
  • Size: 81.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for yfinance-cache-0.3.5.tar.gz
Algorithm Hash digest
SHA256 6226e921f86716f7a84b160b847e48a0ea919790b4fa77053c482949fbbde749
MD5 0607e618420d521e149ba5c0bc80b531
BLAKE2b-256 029e78bc1dd96b2196fbad80f3836326d5082a73061eebfb88236837cdb4ed9e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: yfinance_cache-0.3.5-py3-none-any.whl
  • Upload date:
  • Size: 101.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for yfinance_cache-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 77732ea73d587f3eb6bc000706beba3de0180823cb2ae9b2720421559dcc2505
MD5 acf2fde1fdd7ee42efa545819f4857aa
BLAKE2b-256 c5cbde98956ed73482970e244f4680d36e73a51439f88bd72a7f5b255c7bd6ab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page