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 will be identical to yfinance:

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

One difference is in fetching price history:

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.

Installation

Not uploading to PIP until I am certain this is stable, so to install you need to pull from GitHub. You also need my fork of yfinance (branch 'integrate') with various fixes (eventually will merge upstream): https://github.com/ValueRaider/yfinance/tree/integrate

To override PIP:

import sys
sys.path.insert(0, "path/to/my/fork/of/yfinance")
import yfinance as yf
print(yf) # verify loading right version
sys.path.insert(0, "path/to/yfinance_cache")
import yfinance_cache as yfc

Known issues / pending tasks

  • If a stock event (dividend or split) has occurred since last fetch, then the cached data needs to be adjusted. But not done currently. Should only be a big issue when split or exceptional dividend occurs - a typical dividend has tiny effect on adjusted price.
  • 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.1.0.tar.gz (46.1 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.1.0-py3-none-any.whl (64.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for yfinance-cache-0.1.0.tar.gz
Algorithm Hash digest
SHA256 be7d62a1e7d48382c173d27a7e04fabb98e76f752af1a2e3998e65582441182e
MD5 d3a08aaf836f20724d1b313539065bd9
BLAKE2b-256 a011426c014848b83250d81c09cb9405fcc8cc14bc394bb932a3771228c874e7

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for yfinance_cache-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 167ed52f3e73627ee902dafb751884c1dc1a5d9106d0d11464a8ea955ea32aea
MD5 e4d9466a36fb141a71577d00ca637caa
BLAKE2b-256 2af850906784df9b9c6fe5e99a66ed54d58430a14fea25711797d008da3fdf7f

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