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
Now available on PIP. You will need my fork of yfinance
on branch 'integrate' - this has various essential fixes (eventually will merge upstream): https://github.com/ValueRaider/yfinance/tree/integrate
To override PIP install of yfinance
:
import sys
sys.path.insert(0, "path/to/my/fork/of/yfinance")
import yfinance as yf
import yfinance_cache as yfc
print(yf) # verify loading my fork of version yfinance
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 anddownload()
not available - useTicker.history()
- pre/post price data not available
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for yfinance_cache-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e31bb98260b4c2f14557de7f7f5f9a9686fa2ee0d2aae6f6d8c3fc3e880b8d3a |
|
MD5 | 9de68737b03a3591d672be947dff09bd |
|
BLAKE2b-256 | 5985dda3ee5d99f5f47f14249c512e1c4990b1867dc911c3357a5668606975b5 |