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.3.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.3-py3-none-any.whl (101.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: yfinance-cache-0.3.3.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.3.tar.gz
Algorithm Hash digest
SHA256 c19e40db0f7d42136185ad2841b0aa670e369d71e2eeb6e1c9cabcac70e81a54
MD5 5e96b3addbe7618cc2f2951da3de563b
BLAKE2b-256 4e1a264c6ff5bc8b4cf414e826705047d9e8dfcde318dffb55264c0bc70982b0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: yfinance_cache-0.3.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c5000ee2c2de474068033f1b89c63527784291a9bc7cfa49560f0793bd05c4fb
MD5 12f5d965f47552a1876d80ff70e963b4
BLAKE2b-256 4a094475f0bc0072e05b5385d58bf1de615d30cf0089955cca8e21e05fd39eb7

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