Git Product home page Git Product logo

yfinance's Introduction

Download market data from Yahoo! Finance's API

*** IMPORTANT LEGAL DISCLAIMER ***


Yahoo!, Y!Finance, and Yahoo! finance are registered trademarks of Yahoo, Inc.

yfinance is not affiliated, endorsed, or vetted by Yahoo, Inc. It's an open-source tool that uses Yahoo's publicly available APIs, and is intended for research and educational purposes.

You should refer to Yahoo!'s terms of use (here, here, and here) for details on your rights to use the actual data downloaded. Remember - the Yahoo! finance API is intended for personal use only.


Python version PyPi version PyPi status PyPi downloads Travis-CI build status CodeFactor Star this repo Follow me on twitter

yfinance offers a threaded and Pythonic way to download market data from Yahoo!Ⓡ finance.

→ Check out this Blog post for a detailed tutorial with code examples.

Changelog »


Installation

Install yfinance using pip:

$ pip install yfinance --upgrade --no-cache-dir

With Conda.

To install with optional dependencies, replace optional with: nospam for caching-requests, repair for price repair, or nospam,repair for both:

$ pip install "yfinance[optional]"

Required dependencies , all dependencies.


Quick Start

The Ticker module

The Ticker module, which allows you to access ticker data in a more Pythonic way:

import yfinance as yf

msft = yf.Ticker("MSFT")

# get all stock info
msft.info

# get historical market data
hist = msft.history(period="1mo")

# show meta information about the history (requires history() to be called first)
msft.history_metadata

# show actions (dividends, splits, capital gains)
msft.actions
msft.dividends
msft.splits
msft.capital_gains  # only for mutual funds & etfs

# show share count
msft.get_shares_full(start="2022-01-01", end=None)

# show financials:
# - income statement
msft.income_stmt
msft.quarterly_income_stmt
# - balance sheet
msft.balance_sheet
msft.quarterly_balance_sheet
# - cash flow statement
msft.cashflow
msft.quarterly_cashflow
# see `Ticker.get_income_stmt()` for more options

# show holders
msft.major_holders
msft.institutional_holders
msft.mutualfund_holders
msft.insider_transactions
msft.insider_purchases
msft.insider_roster_holders

# show recommendations
msft.recommendations
msft.recommendations_summary
msft.upgrades_downgrades

# Show future and historic earnings dates, returns at most next 4 quarters and last 8 quarters by default. 
# Note: If more are needed use msft.get_earnings_dates(limit=XX) with increased limit argument.
msft.earnings_dates

# show ISIN code - *experimental*
# ISIN = International Securities Identification Number
msft.isin

# show options expirations
msft.options

# show news
msft.news

# get option chain for specific expiration
opt = msft.option_chain('YYYY-MM-DD')
# data available via: opt.calls, opt.puts

If you want to use a proxy server for downloading data, use:

import yfinance as yf

msft = yf.Ticker("MSFT")

msft.history(..., proxy="PROXY_SERVER")
msft.get_actions(proxy="PROXY_SERVER")
msft.get_dividends(proxy="PROXY_SERVER")
msft.get_splits(proxy="PROXY_SERVER")
msft.get_capital_gains(proxy="PROXY_SERVER")
msft.get_balance_sheet(proxy="PROXY_SERVER")
msft.get_cashflow(proxy="PROXY_SERVER")
msft.option_chain(..., proxy="PROXY_SERVER")
...

Multiple tickers

To initialize multiple Ticker objects, use

import yfinance as yf

tickers = yf.Tickers('msft aapl goog')

# access each ticker using (example)
tickers.tickers['MSFT'].info
tickers.tickers['AAPL'].history(period="1mo")
tickers.tickers['GOOG'].actions

To download price history into one table:

import yfinance as yf
data = yf.download("SPY AAPL", period="1mo")

yf.download() and Ticker.history() have many options for configuring fetching and processing. Review the Wiki for more options and detail.

Logging

yfinance now uses the logging module to handle messages, default behaviour is only print errors. If debugging, use yf.enable_debug_mode() to switch logging to debug with custom formatting.

Smarter scraping

Install the nospam packages for smarter scraping using pip (see Installation). These packages help cache calls such that Yahoo is not spammed with requests.

To use a custom requests session, pass a session= argument to the Ticker constructor. This allows for caching calls to the API as well as a custom way to modify requests via the User-agent header.

import requests_cache
session = requests_cache.CachedSession('yfinance.cache')
session.headers['User-agent'] = 'my-program/1.0'
ticker = yf.Ticker('msft', session=session)
# The scraped response will be stored in the cache
ticker.actions

Combine requests_cache with rate-limiting to avoid triggering Yahoo's rate-limiter/blocker that can corrupt data.

from requests import Session
from requests_cache import CacheMixin, SQLiteCache
from requests_ratelimiter import LimiterMixin, MemoryQueueBucket
from pyrate_limiter import Duration, RequestRate, Limiter
class CachedLimiterSession(CacheMixin, LimiterMixin, Session):
    pass

session = CachedLimiterSession(
    limiter=Limiter(RequestRate(2, Duration.SECOND*5)),  # max 2 requests per 5 seconds
    bucket_class=MemoryQueueBucket,
    backend=SQLiteCache("yfinance.cache"),
)

Managing Multi-Level Columns

The following answer on Stack Overflow is for How to deal with multi-level column names downloaded with yfinance?

  • yfinance returns a pandas.DataFrame with multi-level column names, with a level for the ticker and a level for the stock price data
    • The answer discusses:
      • How to correctly read the the multi-level columns after saving the dataframe to a csv with pandas.DataFrame.to_csv
      • How to download single or multiple tickers into a single dataframe with single level column names and a ticker column

pandas_datareader override

If your code uses pandas_datareader and you want to download data faster, you can "hijack" pandas_datareader.data.get_data_yahoo() method to use yfinance while making sure the returned data is in the same format as pandas_datareader's get_data_yahoo().

from pandas_datareader import data as pdr

import yfinance as yf
yf.pdr_override() # <== that's all it takes :-)

# download dataframe
data = pdr.get_data_yahoo("SPY", start="2017-01-01", end="2017-04-30")

Persistent cache store

To reduce Yahoo, yfinance store some data locally: timezones to localize dates, and cookie. Cache location is:

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

You can direct cache to use a different location with set_tz_cache_location():

import yfinance as yf
yf.set_tz_cache_location("custom/cache/location")
...

Developers: want to contribute?

yfinance relies on community to investigate bugs and contribute code. Developer guide: #1084


Legal Stuff

yfinance is distributed under the Apache Software License. See the LICENSE.txt file in the release for details.

AGAIN - yfinance is not affiliated, endorsed, or vetted by Yahoo, Inc. It's an open-source tool that uses Yahoo's publicly available APIs, and is intended for research and educational purposes. You should refer to Yahoo!'s terms of use (here, here, and here) for detailes on your rights to use the actual data downloaded.


P.S.

Please drop me an note with any feedback you have.

Ran Aroussi

yfinance's People

Contributors

arcxyz avatar asafravid avatar aspenforest avatar beglitis avatar bradmetz avatar coskos-ops avatar flaviovs avatar fredrik-corneliusson avatar ghofi-dev avatar giorgossideris avatar git-shogg avatar gregorymorse avatar hmellor avatar jonathanng avatar julialwang8 avatar lucas03 avatar marco-carvalho avatar matthiasschinzel avatar nikolauspschuetz avatar oliverlewis avatar ranaroussi avatar ricardoprins avatar rickturner2001 avatar rogach avatar signifer-geo avatar silvavn avatar thirumalairajr avatar trenton3983 avatar valueraider avatar ymyke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yfinance's Issues

Installing issue using pip

Hi there,

I was trying to install using 'pip install fix_yahoo_finance --upgrade --no-cache-dir'

However it seems not to work as I still get No module named 'fix_yahoo_finance' errors.

Doing pip I get lots of permission errors? Would you know why?

Many thanks!
Carl

Can't disable the progress bar

When setting progress=False, I get this:

    data = pdr.get_data_yahoo(symbol, start, end, progress=False, actions=None)                                                                                                                                                             
   File "/home/user/.virtualenvs/p35/lib/python3.5/site-packages/fix_yahoo_finance/__init__.py", line 194, in download                                                                                                                
     _PROGRESS_BAR_.completed()                                                                                                                                                                                                              
 AttributeError: 'bool' object has no attribute 'completed' 

reason: cannot reindex from a duplicate axis

same issue here: #14
But the reason is that the datasource(yahoo) has the issue, like MBVT, has two values in a day (2017-05-12). u'Date,Open,High,Low,Close,Adj Close,Volume\n2017-05-12,49.650002,49.849998,49.250000,49.799999,49.799999,49300\n2017-05-12,0.000000,49.849998,49.400002,49.799999,49.799999,24398\n' PTAL

KeyError

Thanks a bunch for this fix!
I tested a SP500 download but some tickers were rejected: CAT, DRI, GRMN
Companies are good. I ran your suggested native code as a test and same issue.

The following tickers failed to download:
 DRI
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-7-43f2f0d22457> in <module>()
      1 import fix_yahoo_finance as yf
----> 2 data = yf.download("dri", start="2017-01-01", end="2017-4-30")
      3 print(data)

/home/kent/anaconda3/lib/python3.6/site-packages/fix_yahoo_finance/__init__.py in download(tickers, start, end, as_panel, group_by, auto_adjust, progress, *args, **kwargs)
    207     # return single df if only one ticker
    208     if len(tickers) == 1:
--> 209         data = dfs[tickers[0]]
    210 
    211     return data

KeyError: 'DRI'

Any suggestions? Thank you.

TypeError: Cannot join tz-naive with tz-aware DatetimeIndex

Ran this:

from pandas_datareader import data as pdr
import datetime
import fix_yahoo_finance

df = pdr.get_data_yahoo(
    tickers = '^GSPC',
    start   = datetime.date(2017, 5, 7),
    end     = datetime.date(2017, 6, 21)
)

Got this:

TypeError: Cannot join tz-naive with tz-aware DatetimeIndex

Bug in fix_yahoo_finance.py when using get_data_yahoo(..., progress=False)

On 2018-01-21,
C:> pip install fix_yahoo_finance --upgrade --no-cache-dir

Using the line...
pdr.get_data_yahoo("SPY", start="2017-11-01", end="2018-01-19", progress=False)

Traceback (most recent call last):
File "C:\forrest\workspace\finance\scratchtest.py", line 8, in
data = pdr.get_data_yahoo("SPY", start="2017-11-01", end="2018-01-19", progress=False)
File "C:\forrest\workspace.virtualenvs\finance\Lib\site-packages\fix_yahoo_finance_init_.py", line 194, in download
PROGRESS_BAR.completed()
AttributeError: 'bool' object has no attribute 'completed'

The offending line is [L194]...
PROGRESS_BAR.completed()
should be...

if progress:
	_PROGRESS_BAR_.completed()

Panel is deprecated and will be removed in a future version.

I am seeing following error. Could you please have a look please.

[100%**] 1 of 1 downloaded
C:\stock\stockcharts\graph.py:57: FutureWarning:
Panel is deprecated and will be removed in a future version.
The recommended way to represent these types of 3-dimensional data are with a MultiIndex on a DataFrame, via the Panel.to_frame() method
Alternatively, you can use the xarray package http://xarray.pydata.org/en/stable/.
Pandas provides a .to_xarray() method to help automate this conversion.

data = yf.download('XEG.TO', start=StartDate, end=endDate)
C:\Python27\lib\site-packages\fix_yahoo_finance_init_.py:199: FutureWarning:
Panel is deprecated and will be removed in a future version.
The recommended way to represent these types of 3-dimensional data are with a MultiIndex on a DataFrame, via the Panel.to_frame() method
Alternatively, you can use the xarray package http://xarray.pydata.org/en/stable/.
Pandas provides a .to_xarray() method to help automate this conversion.

ImportError: No module named 'requests.packages.idna.uts46data'

Hello,

Thank you for providing a temp solution to parse the yahoo hist data with API, I have downloaded the fix and I have the requests module installed but when I try to call the download function I receive the message on the title:
" ImportError: No module named 'requests.packages.idna.uts46data' "

My piece of code is:
from pandas_datareader import data as pdr
import fix_yahoo_finance as yf
data = pdr.get_data_yahoo("JPM","2017-01-01","2017-04-30")
yf.download("JPM","2017-01-01","2017-04-30")

I have tried both methods but they do not seem to recognise I have the requests module installed.

Thanks,
Kostas

Negative volume values

Hi Rana,
Thanks for that fix.

When downloading values for S&P 500 (^GSPC), some volume values are negatives. I think that dataframe columns should be created as unsigned int.

Cyril

fix-yahoo-finance error

Traceback (most recent call last):
File "analysis.py", line 110, in
file_path = get_csv(c,ticker, pwd)
File "analysis.py", line 37, in get_csv
df_djia = get_djia()
File "analysis.py", line 54, in get_djia
df = data.get_data_yahoo("AAPL", start_date, end_date)
File "/home/ubuntu/projects/liquidnet/venv/lib/python3.5/site-packages/fix_yahoo_finance/init.py", line 217, in download
data = _DFS[tickers[0]]
KeyError: 'AAPL'

Writing to a File,

Thanks for taking time to write Ranaroussi, Appreciate it, Great Job,

import fix_yahoo_finance as yf
data = yf.download("SPY", start="2017-01-01", end="2017-04-30")

I have trouble in writing to a file, how to write the ouput from Data or from yf.download directly into the file.

Also
print data <<<< also shows only 20 lines, not all the 100 lines,

Thanks and much appreciate it

Johnx

OHLC become very small number

Those values are small (shown below) are incorrect. Correct values can be displayed on
https://finance.yahoo.com/quote/%5EHSI/history/

web.get_data_yahoo("^HSI", start="2017-05-01", end="2017-08-24")

                Open          High           Low         Close  \

Date
2017-05-01 0.215000 0.220000 0.210000 0.210000
2017-05-02 24696.099609 24696.099609 24696.099609 24696.099609
2017-05-03 0.225000 0.225000 0.190000 0.200000
2017-05-04 0.200000 0.210000 0.200000 0.200000
2017-05-05 0.210000 0.210000 0.210000 0.210000

           Adj Close  Volume

Date
2017-05-01 0.210000 14000
2017-05-02 24696.099609 0
2017-05-03 0.200000 57500
2017-05-04 0.200000 172367
2017-05-05 0.210000 2500

sys:1: ResourceWarning: unclosed

Whenever I import the module

import fix_yahoo_finance as yf

and without using any of the functions in fix_yahoo_finance, create a SQLAlchemy engine and use Pandas DataFrame's to_sql,

it gives the error

sys:1: ResourceWarning: unclosed <socket.socket fd=456, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('192.168.1.112', 49217), raddr=('192.168.1.115', 3306)>

Is this a bug?

import pandas as pd
from sqlalchemy import create_engine
import fix_yahoo_finance as yf

engine = create_engine("mysql+mysqlconnector://user:password@server")
df = pd.DataFrame()
df.to_sql(
	con=engine,
	name='yahoo',
	if_exists='append',
	index=False)

Use this code to reproduce the error/warning. Removing fix_yahoo_finance will remove the error.

caching?

Hello,

working with long series and making various launchs for analysis, would be possible to have a persistent cache in some way?

how to get data for today?

today is Mar 28 , 2018
how to get data for today?

import fix_yahoo_finance as yf
import datetime as dt
import time
#data = yf.download("SPY", start="2017-01-01", end="2017-04-30")

data = yf.download("SPY", start="2018-03-24", end="2018-03-28")

it is what I get
data
Open High Low Close Adj Close
Date
2018-03-26 262.130005 265.429993 259.410004 265.109985 265.109985
2018-03-27 266.170013 266.769989 258.839996 260.600006 260.600006

           Volume  

Date
2018-03-26 141956100
2018-03-27 126354700

but for today there is now data?

AttributeError: 'list' object has no attribute 'empty'

Running this code throws the above error.

import pandas as pd
import pandas_datareader.data as pdr
import fix_yahoo_finance as yf
yf.pdr_override()
start = dt.datetime(2000, 1, 1)
end = dt.datetime.now()
df = yf.download(  # pdr.get_data_yahoo
	'SPY',
	start=start,
	end=end,
	as_panel=False,
	group_by='ticker',
	auto_adjust=False,
	progress=False,
	threads=16)

It seems to be related to multithreading. Running it without threads=16 works...

Python 3\lib\site-packages\fix_yahoo_finance_init_.py
in download(tickers, start, end, as_panel, group_by, auto_adjust, progress, actions, threads, **kwargs)
179 auto_adjust=auto_adjust, progress=progress,
180 actions=actions, **kwargs)
--> 181 if not tickers[-chunks:].empty:
182 download_thread(tickers[-chunks:], start=start, end=end,
183 auto_adjust=auto_adjust, progress=progress,

list of tickers?

Thanks this excellent packages for yahoo finance!!!!!!!!!

It saves my group project for visualization especially my group member is non-active before DDL.

Could anyone help to make me clear where can I find tickers??

i.e. Google company stock, Gold price, foreign exchange info. like U.S.D?

Many thanks in advance!

Best,
Peter

expansion of supported stock markets

sir your work is truly amazing in this hour of hardship when yahoo backstabs us.... i would request if you can add support for Indian stock markets also NSE and BOM, i am a complete noob when it comes to programming so am looking to you with great expectations hope u would have some time to spare.

Is there a way to download the yahoo data from the earliest available date?

Hi there:

See example below. Is there a way to download SPY data from its earliest available date without specifying the start date? The function use default value '1950-1-1', but it creates an error.

Thanks,
D

Code

import pandas_datareader.data as web
import fix_yahoo_finance as yf
yf.pdr_override()
data = web.get_data_yahoo('SPY')

#Error

File "", line 1, in
data = web.get_data_yahoo('SPY')

File "C:\Continuum\Anaconda3\lib\site-packages\fix_yahoo_finance_init_.py", line 147, in download
start = int(time.mktime(time.strptime('1950-01-01', '%Y-%m-%d')))

OverflowError: mktime argument out of range

Incomplete data with 0.0.19

I am trying 0.0.19 here and unfortunately I get sometimes incomplete data.

Just try:

pdr.get_data_yahoo('ALV.F', start='2016-09-27', end='2017-09-27')

Sometimes you'll get just a few rows, other times you get the whole 257 rows. Very annoying. Any suggestions as to why?

Problem finding certificate

Sorry, bit of a noob here.`

Expected Result

Using Python 3.6 from Anaconda, after having installed fix_yahoo_finance package

Actual Result

Traceback (most recent call last):

  File "<ipython-input-15-b609a2c5a366>", line 9, in <module>
    end="2017-06-20")

  File "C:\Users\London\Anaconda3\lib\site-packages\fix_yahoo_finance\__init__.py", line 167, in download
    actions=actions, *args, **kwargs)

  File "C:\Users\London\Anaconda3\lib\site-packages\fix_yahoo_finance\__init__.py", line 317, in download_chunk
    crumb, cookie = get_yahoo_crumb()

  File "C:\Users\London\Anaconda3\lib\site-packages\fix_yahoo_finance\__init__.py", line 54, in get_yahoo_crumb
    res = requests.get('https://finance.yahoo.com/quote/SPY/history')

  File "C:\Users\London\Anaconda3\lib\site-packages\requests\api.py", line 72, in get
    return request('get', url, params=params, **kwargs)

  File "C:\Users\London\Anaconda3\lib\site-packages\requests\api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)

  File "C:\Users\London\Anaconda3\lib\site-packages\requests\sessions.py", line 518, in request
    r"""Sends a OPTIONS request. Returns :class:`Response` object.

  File "C:\Users\London\Anaconda3\lib\site-packages\requests\sessions.py", line 639, in send
    history.insert(0, r)

  File "C:\Users\London\Anaconda3\lib\site-packages\requests\adapters.py", line 405, in send
    conn = self.get_connection(request.url, proxies)

  File "C:\Users\London\Anaconda3\lib\site-packages\requests\adapters.py", line 225, in cert_verify
    raise IOError("Could not find a suitable TLS CA certificate bundle, "

OSError: Could not find a suitable TLS CA certificate bundle, invalid path: C:\Users\London\Anaconda3\lib\site-packages\requests\cacert.pem

I do have a certifi package which contains the file cacert.pem, but the path is C:\Users\London\Anaconda3\Lib\site-packages\certifi

Reproduction Steps

Using this request:

from pandas_datareader import data as pdr

import datetime

import fix_yahoo_finance

aapl = pdr.get_data_yahoo('AAPL',
                          start="2014-01-01",
                          end="2017-06-20")

System Information

$ python -m requests.help
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": "1.8.1"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.6.1"
  },
  "platform": {
    "release": "8.1",
    "system": "Windows"
  },
  "pyOpenSSL": {
    "openssl_version": "100020bf",
    "version": "17.0.0"
  },
  "requests": {
    "version": "2.18.1"
  },
  "system_ssl": {
    "version": "100020bf"
  },
  "urllib3": {
    "version": "1.21.1"
  },
  "using_pyopenssl": true
}

Adj Close - Not Factoring in Dividends

Your work here is much appreciated. I don't know if you've noticed, but Yahoo! appears to have messed with their Adj Close such that it's now the exact same as the Close column for tickers that haven't experienced a stock split in a given time period. In other words, they aren't actually making the adjustments factoring in dividends anymore.

So this isn't an issue per se, but a request - if you could add in the functionality to either pull the dividend data into separate DataFrames via a new function or just pull it and automatically calculate it into the Adj Close column of the DataFrame output by your get_data_yahoo() function that would be awesome. Latter request is more work than the former, but just easily pulling the Dividend data into a DataFrame so I can calculate on my own would be great.

I have been working on hacking this into a copy of your script on my desktop to see if I can't build this functionality on my own, but I'm still very much an amateur so it's slow going.

[Error] Fails to get data intermittently

Recently started noticing these errors when running yf.download. They occur sometimes. Will update issue if I find more info.

Error log:

    get_yahoo_crumb()
  File "/usr/local/lib/python3.6/site-packages/fix_yahoo_finance/__init__.py", line 62, in get_yahoo_crumb
    res = _requests.get('https://finance.yahoo.com/quote/SPY/history')
  File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 658, in send
    r.content
  File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 823, in content
    self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
  File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 750, in generate
    raise ContentDecodingError(e)
requests.exceptions.ContentDecodingError: ('Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect data check',))

module 'fix_yahoo_finance' has no attribute 'pdr_override'

I am trying to suppress the deprecation warnings with yf.pdr_override but am getting this:

yf.pdr_override()

AttributeError: module 'fix_yahoo_finance' has no attribute 'pdr_override'

Also attempted to suppress the warnings myself but without avail.

Needs added support for historical dividends.

Before, the yahoo finance package allowed us to pull historical dividend data with the command

import pandas_datareader.data as web
f = web.DataReader("F", 'yahoo-dividends', start="2017-01-01", end="2017-04-30")

However, there appears to be no way to do this with the yahoo fix package.
I have tried multiple commands with no success:

import fix_yahoo_finance as yf
import pandas_datareader.data as web

# first attempt
yf.download("IBM", actions="only", start="2017-01-01", end="2017-04-30")

# second attempt
yf.pandas_datareader.DataReader("F", 'yahoo-dividends', start="2017-01-01", end="2017-04-30")

Limit to the number of tickers

Hey,

When I call more than 30 tickers at a time, I get this error:

Traceback (most recent call last):
  File "C:/Users/hari0/PycharmProjects/practice/stock.py", line 137, in <module>
    stockRawData = web.get_data_yahoo(tickers1, start, end)
  File "C:\Python27\lib\site-packages\fix_yahoo_finance\__init__.py", line 192, in download
    data = pd.Panel(_DFS_)
  File "C:\Python27\lib\site-packages\pandas\core\panel.py", line 148, in __init__
    minor_axis=minor_axis, copy=copy, dtype=dtype)
  File "C:\Python27\lib\site-packages\pandas\core\panel.py", line 173, in _init_data
    mgr = self._init_dict(data, passed_axes, dtype=dtype)
  File "C:\Python27\lib\site-packages\pandas\core\panel.py", line 228, in _init_dict
    v = v.reindex(**d)
  File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 2733, in reindex
    **kwargs)
  File "C:\Python27\lib\site-packages\pandas\core\generic.py", line 2515, in reindex
    fill_value, copy).__finalize__(self)
  File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 2679, in _reindex_axes
    fill_value, limit, tolerance)
  File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 2690, in _reindex_index
    allow_dups=False)
  File "C:\Python27\lib\site-packages\pandas\core\generic.py", line 2627, in _reindex_with_indexers
    copy=copy)
  File "C:\Python27\lib\site-packages\pandas\core\internals.py", line 3886, in reindex_indexer
    self.axes[axis]._can_reindex(indexer)
  File "C:\Python27\lib\site-packages\pandas\core\indexes\base.py", line 2836, in _can_reindex
    raise ValueError("cannot reindex from a duplicate axis")
ValueError: cannot reindex from a duplicate axis

Is there anyway to call all the available tickers within yahoo finance?

version for 2.7

Do you have a version for 2.7?
I tested it and not working as it support 3.4 above

Looping through downloaded data?

I know this is a noobish question, but I have no idea how to loop or iterate over the downloaded data. I've try to loop as in a python list or like in a numpy array, but I don't achieve it.

Can you provide a basic example?

The line I use to download:

data = yf.download("BBVA.MC", start="2017-01-01", end="2017-04-30")

Thank you

Not able to pull data past Sept 8, 2017

Noticed this Monday (Sept 11th, 2017) that no data was able to be collected using either "yf.download" or "pdr.get_data_yahoo". Works like a charm for any date range up to Friday sept 8th, 2017.

Why 5 seconds wait for new cookie it takes hours to download 1700 tickers

Ran, thank you for creating this. I was about to do the same, but you saved me a lot of time. One question, why wait 5 seconds for the new cookie request? It takes hours to download the 1700 tickers I used to download in 30 minutes... every 2 or 3 tickers, the code lags for 5 seconds... Thank you again

Interval = "m"

the yahoo historical interval options seems to have been wiped out with this fix?
thanks for the yahoo fix.

from pandas_datareader import data as pdr
import fix_yahoo_finance
data = pdr.get_data_yahoo("SPY", start="2015-01-01", end="2017-04-30", interval='m')
data
Empty DataFrame
Columns: []
Index: []

as_panel=False causes dividends to return empty

I'm not sure where this error is coming from, but in order to get actions and prices I have to use as_panel=True. Here is a mwe:

import pandas as pd
from pandas_datareader import data as read_dat
import fix_yahoo_finance    # Scrapes yahoo instead of using their api

tickers = ['CVX', 'VZ']

raw = read_dat.get_data_yahoo(tickers, start, end, actions=True)
raw['Dividends'].head() # This contains data

raw = read_dat.get_data_yahoo(tickers, as_panel=False, start, end, actions=True)
raw['Dividends'].head() # This is empty

('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',)) failed to pull pricing data

First of all, thank you for developing this "temporary" fix.
I'm trying to download historical data (1yr) for 1000 symbols. I'm getting a periodic connection aborted after maybe ~200 symbols. After a (long) delay data download continues.

Here is the error:
('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',)) failed to pull pricing data

How can I eliminate the connection abort...Will you please advise?
TIA
--R

Request: Equity profile

Sorry to open as issue but don't know how to pull a request...

I used to download ticker profile as Name, City, State, Country using the following code:
from pandas_finance import Equity
data = Equity('AAPL')
entityname = data.name
entitycity = data.profile.ix['City']
entitystate = data.profile.ix['State']
entitycountry = data.profile.ix['Country']

May you please deliver an option to retrieve the ticker profile?

Thank you very much for you work!

Empty Dataframe

I'm getting empty dataframes.

from pandas_datareader import data as pdr
import fix_yahoo_finance
import datetime

df = pdr.get_data_yahoo(
    tickers = 'COT',
    start   = datetime.date(2017, 6, 4),
    end     = datetime.date(2017, 6, 21)
)

df

But there is data on Yahoo:

https://finance.yahoo.com/quote/COT/history?p=COT

Zero-size array

Hello,

I am using the following code to download data to Python:

`
import fix_yahoo_finance as yf
from pandas_datareader import data as pdr
yf.pdr_override()

ticker=['^GDAXI']

#ticker=['^GDAXI','EURUSD=X']

data = pdr.get_data_yahoo(ticker, start="2010-12-02", end="2018-01-31", as_panel = False)

data=data[['Open','High', 'Low', 'Adj Close', 'Volume']]
`

And it works perfekt 60% of the time. But often i get the following the error message:

"zero-size array to reduction operation maximum which has no identity"

When this occures, I usually have to restart my console in order to download data again. Is there any solution to this? Much appricirated!

Add Date to dataframe

I submitted this by accident and don't know how to delete or close this. Do you mind closing this? I would really appreciate it.

Close higher than High?

Once more thanks for all the job!

It looks like High and Close are changed, I mean, High is getting Close values and vice versa. Close shouldn't get higher values than close, right? Here follows an example:
data = pdr.get_data_yahoo('RENE.LS', start='2017-05-01', end='2017-05-31')

Date Open High Low Close Adj Close Volume
2017-05-02 2.545275 2.601836 2.542447 2.758 2.599951 1239720
2017-05-03 2.596180 2.645200 2.596180 2.806 2.645200 748173
2017-05-04 2.645200 2.691392 2.630117 2.840 2.677252 1316003
2017-05-05 2.662169 2.699877 2.662169 2.850 2.686679 1660910
2017-05-08 2.692335 2.709304 2.674424 2.868 2.703647 698456
2017-05-09 2.710246 2.727215 2.691392 2.885 2.719673 768257
2017-05-10 2.724387 2.724387 2.690450 2.880 2.714960 657715
...

Bug?
Thank you!

Date value in the Date Index is stored as a string.

The Date column/index of the dataframe is a dtype: object. The dataframe created in the previously functioning pandas_datareader was a dtype: datetime64[ns]. To maintain backward compatilitbity, I added:

df.reset_index(inplace=True)
df['Date'] = pd.to_datetime(df['Date'])

fix-yahoo-finance: pip install not working

Hi Rana,

I am getting an error trying to install this...I am using python 3.6

MacBooks-MacBook-Air:~ svijay$ $ pip install fix_yahoo_finance --upgrade --no-cache-dir
-bash: $: command not found

Please advise!

Threads not working

Hello

I am running your code with 100 symbols (see enclosed), sadly I am getting the following errors when setting threads =10. The code works however with Threads =1
I would be really grateful if you could show me how to fix this as I am new to Python
yahoo_finance.py.txt

Traceback: File "/home/olivier/BNC/DATA_SCRAPER/yahoo_finance.py", line 138, in <module> threads=10 File "/home/olivier/PycharmProjects/Pairs Trading Analysis with Python/venv/lib/python3.6/site-packages/fix_yahoo_finance/__init__.py", line 181, in download if not tickers[-chunks:].empty: AttributeError: 'list' object has no attribute 'empty'

Return date before start date

data = pdr.get_data_yahoo('A', actions='only', start='2017-04-01', end='2017-05-31') #actions only

Result:
[100%**] 1 of 1 downloaded
Date value action
2017-03-31 0.132 DIVIDEND

Why did I get 31 March 2017 if start Date is in April 2017?

Thank you once more! (is never enought :))

Panel fails to init

For actions='only' call, at certain point Panel fails to init from data stored in DFS

Note: This happens after several succesfull calls to the function exactly at the same point. I believe this has something to do with duplicated fields in the cached data

File "C:/Users/Nicolas/Documents/Merval\Scrapper.py", line 103, in correctSplitsAndDividends
actions=pdr.get_data_yahoo(tickers=symbol,start=start,end=end,actions='only',aspanel=False)
File "C:\Users\Nicolas\Anaconda2\lib\site-packages\fix_yahoo_finance_init_.py", line 194, in download
data = pd.Panel(DFS)
File "C:\Users\Nicolas\Anaconda2\lib\site-packages\pandas\core\panel.py", line 148, in init
minor_axis=minor_axis, copy=copy, dtype=dtype)
File "C:\Users\Nicolas\Anaconda2\lib\site-packages\pandas\core\panel.py", line 173, in _init_data
mgr = self._init_dict(data, passed_axes, dtype=dtype)
File "C:\Users\Nicolas\Anaconda2\lib\site-packages\pandas\core\panel.py", line 228, in _init_dict
v = v.reindex(**d)
File "C:\Users\Nicolas\Anaconda2\lib\site-packages\pandas\core\frame.py", line 2733, in reindex
**kwargs)
File "C:\Users\Nicolas\Anaconda2\lib\site-packages\pandas\core\generic.py", line 2515, in reindex
fill_value, copy).finalize(self)
File "C:\Users\Nicolas\Anaconda2\lib\site-packages\pandas\core\frame.py", line 2679, in _reindex_axes
fill_value, limit, tolerance)
File "C:\Users\Nicolas\Anaconda2\lib\site-packages\pandas\core\frame.py", line 2690, in _reindex_index
allow_dups=False)
File "C:\Users\Nicolas\Anaconda2\lib\site-packages\pandas\core\generic.py", line 2627, in _reindex_with_indexers
copy=copy)
File "C:\Users\Nicolas\Anaconda2\lib\site-packages\pandas\core\internals.py", line 3886, in reindex_indexer
self.axes[axis]._can_reindex(indexer)
File "C:\Users\Nicolas\Anaconda2\lib\site-packages\pandas\core\indexes\base.py", line 2836, in _can_reindex
raise ValueError("cannot reindex from a duplicate axis")
ValueError: cannot reindex from a duplicate axis

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.