Yahoo Finance¶
- class pandas_datareader.yahoo.daily.YahooDailyReader(symbols=None, start=None, end=None, retry_count=3, pause=0.1, session=None, adjust_price=False, ret_index=False, chunksize=1, interval='d', get_actions=False, adjust_dividends=True)¶
Returns DataFrame of with historical over date range, start to end. To avoid being penalized by Yahoo! Finance servers, pauses between downloading ‘chunks’ of symbols can be specified.
- Parameters
symbols (string, array-like object (list, tuple, Series), or DataFrame) – Single stock symbol (ticker), array-like object of symbols or DataFrame with index containing stock symbols.
start (string, int, date, datetime, Timestamp) – Starting date. Parses many different kind of date representations (e.g., ‘JAN-01-2010’, ‘1/1/10’, ‘Jan, 1, 1980’). Defaults to 5 years before current date.
end (string, int, date, datetime, Timestamp) – Ending date
retry_count (int, default 3) – Number of times to retry query request.
pause (int, default 0.1) – Time, in seconds, to pause between consecutive queries of chunks. If single value given for symbol, represents the pause between retries.
session (Session, default None) – requests.sessions.Session instance to be used. Passing a session is an advanced usage and you must set any required headers in the session directly.
adjust_price (bool, default False) – If True, adjusts all prices in hist_data (‘Open’, ‘High’, ‘Low’, ‘Close’) based on ‘Adj Close’ price. Adds ‘Adj_Ratio’ column and drops ‘Adj Close’.
ret_index (bool, default False) – If True, includes a simple return index ‘Ret_Index’ in hist_data.
chunksize (int, default 25) – Number of symbols to download consecutively before intiating pause.
interval (string, default 'd') – Time interval code, valid values are ‘d’ for daily, ‘w’ for weekly, ‘m’ for monthly.
get_actions (bool, default False) – If True, adds Dividend and Split columns to dataframe.
adjust_dividends (bool, default true) – If True, adjusts dividends for splits.
- close()¶
Close network session
- property default_start_date¶
Default start date for reader. Defaults to 5 years before current date
- property params¶
Parameters to use in API calls
- read()¶
Read data
- property url¶
API URL
- class pandas_datareader.yahoo.fx.YahooFXReader(symbols=None, start=None, end=None, retry_count=3, pause=0.1, session=None, adjust_price=False, ret_index=False, chunksize=1, interval='d', get_actions=False, adjust_dividends=True)¶
Returns DataFrame of historical prices for currencies
- Parameters
symbols (string, array-like object (list, tuple, Series), or DataFrame) – Single stock symbol (ticker), array-like object of symbols or DataFrame with index containing stock symbols.
start (string, int, date, datetime, Timestamp) – Starting date, timestamp. Parses many different kind of date representations (e.g., ‘JAN-01-2010’, ‘1/1/10’, ‘Jan, 1, 1980’). Defaults to ‘1/1/2010’.
end (string, int, date, datetime, Timestamp) – Ending date, timestamp. Same format as starting date. Defaults to today.
retry_count (int, default 3) – Number of times to retry query request.
pause (int, default 0.1) – Time, in seconds, to pause between consecutive queries of chunks. If single value given for symbol, represents the pause between retries.
session (Session, default None) – requests.sessions.Session instance to be used
chunksize (int, default 25 (NOT IMPLEMENTED)) – Number of symbols to download consecutively before intiating pause.
interval (string, default '1d') –
- Valid values are ‘1d’, ‘5d’, ‘1mo’, ‘3mo’, ‘6mo’, ‘1y’, ‘2y’, ‘5y’,
’10y’, ‘ytd’, ‘max’
- close()¶
Close network session
- property default_start_date¶
Default start date for reader. Defaults to 5 years before current date
- property params¶
Parameters to use in API calls
- read()¶
Read data
- property url¶
API URL
- class pandas_datareader.yahoo.options.Options(symbol, session=None)¶
*Experimental* This class fetches call/put data for a given stock/expiry month.
It is instantiated with a string representing the ticker symbol.
- The class has the following methods:
get_options_data(month, year, expiry) get_call_data(month, year, expiry) get_put_data(month, year, expiry) get_near_stock_price(opt_frame, above_below) get_all_data(call, put) get_forward_data(months, call, put) (deprecated)
Examples
# Instantiate object with ticker >>> aapl = Options(‘aapl’)
# Fetch next expiry call data >>> calls = aapl.get_call_data()
# Can now access aapl.calls instance variable >>> aapl.calls
# Fetch next expiry put data >>> puts = aapl.get_put_data()
# Can now access aapl.puts instance variable >>> aapl.puts
# cut down the call data to be 3 below and 3 above the stock price. >>> cut_calls = aapl.get_near_stock_price(call=True, above_below=3)
# Fetch call and put data with expiry from now to 8 months out >>> forward_data = aapl.get_forward_data(8, call=True, put=True)
# Fetch all call and put data >>> all_data = aapl.get_all_data()
- close()¶
Close network session
- property default_start_date¶
Default start date for reader. Defaults to 5 years before current date
- property expiry_dates¶
Returns a list of available expiry dates
- get_all_data(call=True, put=True)¶
*Experimental* Gets either call, put, or both data for all available months starting in the current month.
- Parameters
- Returns
pandas.DataFrame – A DataFrame with requested options data.
- Index:
Strike: Option strike, int Expiry: Option expiry, Timestamp Type: Call or Put, string Symbol: Option symbol as reported on Yahoo, string
- Columns:
Last: Last option price, float Chg: Change from prior day, float PctChg: Change from prior day in percent, float Bid: Bid price, float Ask: Ask price, float Vol: Volume traded, int64 Open_Int: Open interest, int64 IsNonstandard: True if the the deliverable is not 100 shares,
otherwise false
Underlying: Ticker of the underlying security, string Underlying_Price: Price of the underlying security, float64 Quote_Time: Time of the quote, Timestamp Last_Trade_Date: Time of the last trade for this expiry
and strike, Timestamp
IV: Implied volatility, float JSON: Parsed json object, json
Useful to extract other returned key/value pairs as needed
Note (Format of returned DataFrame is dependent) – on Yahoo and may change.
- get_call_data(month=None, year=None, expiry=None)¶
*Experimental* Gets call/put data for the stock with the expiration data in the given month and year
- Parameters
month (number, int, optional(default=None)) – The month the options expire. This should be either 1 or 2 digits.
year (number, int, optional(default=None)) – The year the options expire. This should be a 4 digit int.
expiry (date-like or convertible or) – list-like object, optional (default=None) The date (or dates) when options expire (defaults to current month)
- Returns
call_data – A DataFrame with requested options data.
- Index:
Strike: Option strike, int Expiry: Option expiry, Timestamp Type: Call or Put, string Symbol: Option symbol as reported on Yahoo, string
- Columns:
Last: Last option price, float Chg: Change from prior day, float PctChg: Change from prior day in percent, float Bid: Bid price, float Ask: Ask price, float Vol: Volume traded, int64 Open_Int: Open interest, int64 IsNonstandard: True if the the deliverable is not 100 shares,
otherwise false
Underlying: Ticker of the underlying security, string Underlying_Price: Price of the underlying security, float64 Quote_Time: Time of the quote, Timestamp Last_Trade_Date: Time of the last trade for this expiry
and strike, Timestamp
IV: Implied volatility, float JSON: Parsed json object, json
Useful to extract other returned key/value pairs as needed
- Return type
pandas.DataFrame
Notes
- Note: Format of returned DataFrame is dependent
on Yahoo and may change.
When called, this function will add instance variables named calls and puts. See the following example:
>>> aapl = Options('aapl', 'yahoo') # Create object >>> aapl.calls # will give an AttributeError >>> aapl.get_call_data() # Get data and set ivars >>> aapl.calls # Doesn't throw AttributeError
Also note that aapl.calls will always be the calls for the next expiry. If the user calls this method with a different month or year, the ivar will be named callsYYMMDD where YY, MM and DD are, respectively, two digit representations of the year, month and day for the expiry of the options.
- get_forward_data(months, call=True, put=False, near=False, above_below=2)¶
*Experimental* Gets either call, put, or both data for months starting in the current month and going out in the future a specified amount of time.
- Parameters
months (number, int) – How many months to go out in the collection of the data. This is inclusive.
call (bool, optional (default=True)) – Whether or not to collect data for call options
put (bool, optional (default=False)) – Whether or not to collect data for put options.
near (bool, optional (default=False)) – Whether this function should get only the data near the current stock price. Uses Options.get_near_stock_price
above_below (number, int, optional (default=2)) – The number of strike prices above and below the stock price that should be taken if the near option is set to True
- Returns
A DataFrame with requested options data.
- Index:
Strike: Option strike, int Expiry: Option expiry, Timestamp Type: Call or Put, string Symbol: Option symbol as reported on Yahoo, string
- Columns:
Last: Last option price, float Chg: Change from prior day, float PctChg: Change from prior day in percent, float Bid: Bid price, float Ask: Ask price, float Vol: Volume traded, int64 Open_Int: Open interest, int64 IsNonstandard: True if the the deliverable is not 100 shares,
otherwise false
Underlying: Ticker of the underlying security, string Underlying_Price: Price of the underlying security, float64 Quote_Time: Time of the quote, Timestamp Last_Trade_Date: Time of the last trade for this expiry
and strike, Timestamp
IV: Implied volatility, float JSON: Parsed json object, json
Useful to extract other returned key/value pairs as needed
- Note: Format of returned DataFrame is dependent
on Yahoo and may change.
- Return type
pandas.DataFrame
- get_near_stock_price(above_below=2, call=True, put=False, month=None, year=None, expiry=None)¶
*Experimental* Returns a DataFrame of options that are near the current stock price.
- Parameters
above_below (number, int, optional (default=2)) – The number of strike prices above and below the stock price that should be taken
call (bool) – Tells the function whether or not it should be using calls
put (bool) – Tells the function weather or not it should be using puts
month (number, int, optional(default=None)) – The month the options expire. This should be either 1 or 2 digits.
year (number, int, optional(default=None)) – The year the options expire. This should be a 4 digit int.
expiry (date-like or convertible or list-like object,) – optional (default=None) The date (or dates) when options expire (defaults to current month)
- Returns
- chopped – The resultant DataFrame chopped down to be 2 * above_below + 1 rows
desired. If there isn’t data as far out as the user has asked for then
- Index:
Strike: Option strike, int Expiry: Option expiry, Timestamp Type: Call or Put, string Symbol: Option symbol as reported on Yahoo, string
- Columns:
Last: Last option price, float Chg: Change from prior day, float PctChg: Change from prior day in percent, float Bid: Bid price, float Ask: Ask price, float Vol: Volume traded, int64 Open_Int: Open interest, int64 IsNonstandard: True if the the deliverable is not 100 shares,
otherwise false
Underlying: Ticker of the underlying security, string Underlying_Price: Price of the underlying security, float64 Quote_Time: Time of the quote, Timestamp Last_Trade_Date: Time of the last trade for this expiry
and strike, Timestamp
IV: Implied volatility, float JSON: Parsed json object, json
Useful to extract other returned key/value pairs as needed
- Note: Format of returned DataFrame is dependent
on Yahoo and may change.
- Return type
DataFrame
- get_options_data(month=None, year=None, expiry=None)¶
*Experimental* Gets call/put data for the stock with the expiration data in the given month and year
- Parameters
month (number, int, optional(default=None)) – The month the options expire. This should be either 1 or 2 digits.
year (number, int, optional(default=None)) – The year the options expire. This should be a 4 digit int.
expiry (date-like or convertible or) – list-like object, optional (default=None) The date (or dates) when options expire (defaults to current month)
- Returns
A DataFrame with requested options data.
- Index:
Strike: Option strike, int Expiry: Option expiry, Timestamp Type: Call or Put, string Symbol: Option symbol as reported on Yahoo, string
- Columns:
Last: Last option price, float Chg: Change from prior day, float PctChg: Change from prior day in percent, float Bid: Bid price, float Ask: Ask price, float Vol: Volume traded, int64 Open_Int: Open interest, int64 IsNonstandard: True if the the deliverable is not 100 shares,
otherwise False
Underlying: Ticker of the underlying security, string Underlying_Price: Price of the underlying security, float64 Quote_Time: Time of the quote, Timestamp Last_Trade_Date: Time of the last trade for this expiry
and strike, Timestamp
IV: Implied volatility, float JSON: Parsed json object, json
Useful to extract other returned key/value pairs as needed
- Return type
pandas.DataFrame
Notes
- Note: Format of returned DataFrame is dependent
on Yahoo and may change.
When called, this function will add instance variables named calls and puts. See the following example:
>>> aapl = Options('aapl', 'yahoo') # Create object >>> aapl.calls # will give an AttributeError >>> aapl.get_options() # Get data and set ivars >>> aapl.calls # Doesn't throw AttributeError
Also note that aapl.calls and appl.puts will always be the calls and puts for the next expiry. If the user calls this method with a different expiry, the ivar will be named callsYYMMDD or putsYYMMDD, where YY, MM and DD are, respectively, two digit representations of the year, month and day for the expiry of the options.
- get_put_data(month=None, year=None, expiry=None)¶
*Experimental* Gets put data for the stock with the expiration data in the given month and year
- Parameters
month (number, int, optional(default=None)) – The month the options expire. This should be either 1 or 2 digits.
year (number, int, optional(default=None)) – The year the options expire. This should be a 4 digit int.
expiry (date-like or convertible or) – list-like object, optional (default=None) The date (or dates) when options expire (defaults to current month)
- Returns
put_data – A DataFrame with requested options data.
- Index:
Strike: Option strike, int Expiry: Option expiry, Timestamp Type: Call or Put, string Symbol: Option symbol as reported on Yahoo, string
- Columns:
Last: Last option price, float Chg: Change from prior day, float PctChg: Change from prior day in percent, float Bid: Bid price, float Ask: Ask price, float Vol: Volume traded, int64 Open_Int: Open interest, int64 IsNonstandard: True if the the deliverable is not 100 shares,
otherwise false
Underlying: Ticker of the underlying security, string Underlying_Price: Price of the underlying security, float64 Quote_Time: Time of the quote, Timestamp Last_Trade_Date: Time of the last trade for this expiry
and strike, Timestamp
IV: Implied volatility, float JSON: Parsed json object, json
Useful to extract other returned key/value pairs as needed
- Return type
pandas.DataFrame
Notes
- Note: Format of returned DataFrame is dependent
on Yahoo and may change.
When called, this function will add instance variables named puts. See the following example:
>>> aapl = Options('aapl') # Create object >>> aapl.puts # will give an AttributeError >>> aapl.get_put_data() # Get data and set ivars >>> aapl.puts # Doesn't throw AttributeError
return self.__setattr__(self, str(str(x) + str(y)))
Also note that aapl.puts will always be the puts for the next expiry. If the user calls this method with a different month or year, the ivar will be named putsYYMMDD where YY, MM and DD are, respectively, two digit representations of the year, month and day for the expiry of the options.
- property params¶
Parameters to use in API calls
- property quote_time¶
Returns the quote time.
- read()¶
Read data from connector
- property underlying_price¶
Returns the underlying price.
- property url¶
API URL
- class pandas_datareader.yahoo.quotes.YahooQuotesReader(symbols=None, start=None, end=None, retry_count=3, pause=0.1, session=None)¶
Get current yahoo quote
- close()¶
Close network session
- property default_start_date¶
Default start date for reader. Defaults to 5 years before current date
- params(symbol)¶
Parameters to use in API calls
- read()¶
Read data from connector
- property url¶
API URL
- class pandas_datareader.yahoo.components._get_data(idx_sym)¶
Returns DataFrame containing list of component information for index represented in idx_sym from yahoo. Includes component symbol (ticker), exchange, and name.
- Parameters
idx_sym (str) –
Stock index symbol Examples: ‘^DJI’ (Dow Jones Industrial Average) ‘^NYA’ (NYSE Composite) ‘^IXIC’ (NASDAQ Composite)
See: http://finance.yahoo.com/indices for other index symbols
- Returns
idx_df
- Return type
DataFrame
- class pandas_datareader.yahoo.actions.YahooActionReader(symbols=None, start=None, end=None, retry_count=3, pause=0.1, session=None, adjust_price=False, ret_index=False, chunksize=1, interval='d', get_actions=False, adjust_dividends=True)¶
Returns DataFrame of historical corporate actions (dividends and stock splits) from symbols, over date range, start to end. All dates in the resulting DataFrame correspond with dividend and stock split ex-dates.
- close()¶
Close network session
- property default_start_date¶
Default start date for reader. Defaults to 5 years before current date
- property params¶
Parameters to use in API calls
- read()¶
Read data
- property url¶
API URL
- class pandas_datareader.yahoo.actions.YahooDivReader(symbols=None, start=None, end=None, retry_count=3, pause=0.1, session=None, adjust_price=False, ret_index=False, chunksize=1, interval='d', get_actions=False, adjust_dividends=True)¶
- close()¶
Close network session
- property default_start_date¶
Default start date for reader. Defaults to 5 years before current date
- property params¶
Parameters to use in API calls
- read()¶
Read data
- property url¶
API URL
- class pandas_datareader.yahoo.actions.YahooSplitReader(symbols=None, start=None, end=None, retry_count=3, pause=0.1, session=None, adjust_price=False, ret_index=False, chunksize=1, interval='d', get_actions=False, adjust_dividends=True)¶
- close()¶
Close network session
- property default_start_date¶
Default start date for reader. Defaults to 5 years before current date
- property params¶
Parameters to use in API calls
- read()¶
Read data
- property url¶
API URL