Code Monkey home page Code Monkey logo

yahoo_fin's People

Contributors

3den avatar abdullahketeldijk avatar atreadw1492 avatar bala-v avatar caesurus avatar chikin1993 avatar cmeyer avatar daughter-shark avatar ikramersh avatar ildon avatar jmkwins avatar michaelfm1211 avatar mowoe avatar omkolte17 avatar rokdd avatar saswatanand 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

yahoo_fin's Issues

Python 3.8 warning in `tickers_sp500()`

I have Python 3.8 installed on my system and see the following warning when using the tickers_sp500 function:

C:\Python38\lib\site-packages\yahoo_fin\stock_info.py:130: FutureWarning: The default value of regex will change from True to False in a future version. In addition, single character regular expressions will*not* be treated as literal strings when regex=True.

sp500["Symbol"] = sp500["Symbol"].str.replace(".", "-")

which can be traced back to the line of code below:

sp500["Symbol"] = sp500["Symbol"].str.replace(".", "-")

The issue can be reproduced by running the following code:

PS > python
>>> from yahoo_fin import stock_info as si
>>> t = si.tickers_sp500()
C:\Python38\lib\site-packages\yahoo_fin\stock_info.py:130: FutureWarning: The default value of regex will change from True to False in a future version. In addition, single character regular expressions will*not* be treated as literal strings when regex=True.
  
  sp500["Symbol"] = sp500["Symbol"].str.replace(".", "-")

Specs of my system:
OS: Win10-64 bit
Python: 3.8.2
yahoo_fin: 0.8.8

I believe changing replace(".", "-") to replace(".", "-", regex=True) in the line of code referenced above should take care of the warning (but I haven't tested it yet). See this issue referenced from the Pandas docs.

Data obtained from get_options_chain are turned into object dtype

Hi,
First of all, thanks for this wonderful library.

I try to obtain the call put info via get_options_chain
and the ticker I used was ^NDX.

However I found that the data dtype for Open interest, pct change and volume are all regarded as type object , i.e. string.

I have try to convert it to numeric by
call_df['Open Interest'] = pd.to_numeric(call_df['Open Interest'], errors='coerce')
put_df['Open Interest'] = pd.to_numeric(put_df['Open Interest'], errors='coerce')

and it seemed failed.

if it is possible that the library can first do the data type check and do necessary data type convert first?
Thanks.

get_live_price() Not working

This function was working until 7pm GMT. But now it gives me this Traceback:

Screenshot 2021-07-09 at 19 00 11

I'm using the latest package version: 0.8.9.

Is this related to the yahoo site change? This was using 'AAPL'

get_market_status returns error

Since yesterday I am getting an error getting market_status.

File "/Users/skhan/Library/Python/3.8/lib/python/site-packages/yahoo_fin/stock_info.py", line 965, in get_market_status
quote_data = get_quote_data("^dji")
File "/Users/skhan/Library/Python/3.8/lib/python/site-packages/yahoo_fin/stock_info.py", line 951, in get_quote_data
raise AssertionError("""Invalid response from server. Check if ticker is
AssertionError: Invalid response from server. Check if ticker is
valid.

ConnectionRefusedError: [Errno 61] Connection refused

ConnectionRefusedError: [Errno 61] Connection refused

urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7fe84e2d5220>: Failed to establish a new connection: [Errno 61] Connection refused

urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='query1.finance.yahoo.com', port=443): Max retries exceeded with url: /v8/finance/chart/PLUG?period1=7223400&period2=1616430229&interval=1d&events=div%2Csplits (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fe84e2d5220>: Failed to establish a new connection: [Errno 61] Connection refused'))

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='query1.finance.yahoo.com', port=443): Max retries exceeded with url: /v8/finance/chart/PLUG?period1=7223400&period2=1616430229&interval=1d&events=div%2Csplits (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fe84e2d5220>: Failed to establish a new connection: [Errno 61] Connection refused'))

Why do I keep getting thees four errors when trying to get live price for a stock?

Error with get_data for indicators (ex: ^QMI)

Seems to be an issue with line 89 in stock_info in the get_data function. Result is "KeyError: 'adjclose'" which implies that adjclose is not a feature of that dataset. I tried removing the 'adjclose' element, but a new issue appeared: "KeyError: 'timestamp'" within the temp_time line.

get_balance_sheet() does not return "Invested Capital"

get_balance_sheet() does not return "Invested Capital", even though it is present on Yahoo Finance.

For example, for AAPL:

>>> si.get_balance_sheet("AAPL")
endDate                    2020-09-26    2019-09-28    2018-09-29    2017-09-30
Breakdown                                                                      
totalLiab                258549000000  248028000000  258578000000  241272000000
totalStockholderEquity    65339000000   90488000000  107147000000  134047000000
otherCurrentLiab          47867000000   43242000000   39293000000   38099000000
totalAssets              323888000000  338516000000  365725000000  375319000000
commonStock               50779000000   45174000000   40201000000   35867000000
otherCurrentAssets        11264000000   12352000000   12087000000   13936000000
retainedEarnings          14966000000   45898000000   70400000000   98330000000
otherLiab                 46108000000   50503000000   48914000000   43251000000
treasuryStock              -406000000    -584000000   -3454000000    -150000000
otherAssets               33952000000   32978000000   22283000000   18177000000
cash                      38016000000   48844000000   25913000000   20289000000
totalCurrentLiabilities  105392000000  105718000000  115929000000  100814000000
shortLongTermDebt          8773000000   10260000000    8784000000    6496000000
otherStockholderEquity     -406000000    -584000000   -3454000000    -150000000
propertyPlantEquipment    45336000000   37378000000   41304000000   33783000000
totalCurrentAssets       143713000000  162819000000  131339000000  128645000000
longTermInvestments      100887000000  105341000000  170799000000  194714000000
netTangibleAssets         65339000000   90488000000  107147000000  134047000000
shortTermInvestments      52927000000   51713000000   40388000000   53892000000
netReceivables            37445000000   45804000000   48995000000   35673000000
longTermDebt              98667000000   91807000000   93735000000   97207000000
inventory                  4061000000    4106000000    3956000000    4855000000
accountsPayable           42296000000   46236000000   55888000000   44242000000

But on Yahoo Finance:

Breakdown	9/30/2020 9/30/2019 9/30/2018 9/30/2017
Total Assets	323,888,000	338,516,000	365,725,000	375,319,000
Total Liabilities Net Minority Interest	258,549,000	248,028,000	258,578,000	241,272,000
Total Equity Gross Minority Interest	65,339,000	90,488,000	107,147,000	134,047,000
Total Capitalization	164,006,000	182,295,000	200,882,000	231,254,000
Common Stock Equity	65,339,000	90,488,000	107,147,000	134,047,000
Net Tangible Assets	65,339,000	90,488,000	107,147,000	126,032,000
Working Capital	38,321,000	57,101,000	14,473,000	27,831,000
Invested Capital	177,775,000	198,535,000	221,630,000	249,727,000
Tangible Book Value	65,339,000	90,488,000	107,147,000	126,032,000
Total Debt	112,436,000	108,047,000	114,483,000	115,680,000
Net Debt	74,420,000	59,203,000	88,570,000	95,391,000
Share Issued	16,976,763	17,772,944	19,019,944	20,504,804
Ordinary Shares Number	16,976,763	17,772,944	19,019,944	20,504,804

Gainer/Loser Volume

Is the volume off for anyone else when retrieving gainers or losers?

yahoo_gainers
Symbol Name Price (Intraday) ... Avg Vol (3 month) Market Cap PE Ratio (TTM)
0 AMKR Amkor Technology, Inc. 14.6700 ... 8.646730e+14 3.517000e+09 70.20

yahoo_gainers['Volume'][0]
3618000.0
yahoo_gainers['Avg Vol (3 month)'][0]
864673000000000.0

Here's the actual volume:

yahoo.get_quote_table('AMKR')
{'1y Target Est': 7.73, '52 Week Range': '5.74 - 14.81', 'Ask': '14.66 x 1400', 'Avg. Volume': 864673.0, 'Beta (3Y Monthly)': 1.66, 'Bid': '14.63 x 1100', "Day's Range": '13.15 - 14.81', 'EPS (TTM)': 0.21, 'Earnings Date': 'Oct 28, 2019', 'Ex-Dividend Date': nan, 'Forward Dividend & Yield': 'N/A (N/A)', 'Market Cap': '3.502B', 'Open': 13.46, 'PE Ratio (TTM)': 69.9, 'Previous Close': 11.08, 'Quote Price': 14.614999771118164, 'Volume': 3980124.0}

KeyError: 'timestamp'

Hi All. First time posting so apologies if I do anything wrong! Love the package and I've been using it for a while.

I'm getting key error: 'timestamp' when I run get_data for non-US tickers. E.g. 'AUGM.L'. It does work fine for tickers that dont need the extension e.g. 'msft'. I didnt get this error with previous versions either. Any thoughts?

yahoo_fin 0.8.8

yahoo_fin\stock_info.py, line 100, in get_data
temp_time = data["chart"]["result"][0]["timestamp"]

weekly data is wrong

si.get_data("spy", interval = "1wk").close.tail(10)
2020-07-06 317.589996
2020-07-13 321.720001
2020-07-20 320.880005
2020-07-27 326.519989
2020-08-03 334.570007
2020-08-10 336.839996
2020-08-17 339.480011
2020-08-24 350.579987
2020-08-31 345.390015
2020-09-04 342.570007

si.get_data("spy", interval = "1d").close.tail(40)
2020-07-13 314.839996
2020-07-14 318.920013
2020-07-15 321.850006
2020-07-16 320.790009
2020-07-17 321.720001
2020-07-20 324.320007
2020-07-21 325.010010
2020-07-22 326.859985
2020-07-23 322.959991
2020-07-24 320.880005
2020-07-27 323.220001
2020-07-28 321.170013
2020-07-29 325.119995
2020-07-30 323.959991
2020-07-31 326.519989
2020-08-03 328.790009
2020-08-04 330.059998
2020-08-05 332.109985
2020-08-06 334.329987
2020-08-07 334.570007
2020-08-10 335.570007
2020-08-11 332.799988
2020-08-12 337.440002
2020-08-13 336.829987
2020-08-14 336.839996
2020-08-17 337.910004
2020-08-18 338.640015
2020-08-19 337.230011
2020-08-20 338.279999
2020-08-21 339.480011
2020-08-24 342.920013
2020-08-25 344.119995
2020-08-26 347.570007
2020-08-27 348.329987
2020-08-28 350.579987
2020-08-31 349.309998
2020-09-01 352.600006
2020-09-02 357.700012
2020-09-03 345.390015
2020-09-04 342.570007

in weekly close, 2020-08-31 345.390015, 345.390015 is 2020-09-03 which is thursday, not friday, can you please fix it?

stock_info.get_live_price('VTSAX') returns 'nan'

VTSAX and VTIAX are returning NaN for stock_info.get_live_price and stock_info.get_data today (2020-09-05).

finance.yahoo.com has the latest data for these. I'm not sure if Yahoo has a bug that broke yahoo_fin or whether the bug is in yahoo_fin.

Thanks for this module. I was very happy to find it.

get_earnings_history - multiple monthly data

Hi
When i call get_earnings_history with interval='1mo', for the current month, i get two rows. i feel it should simply be the price up to the current date or maybe a parameter to indicate how to deal with that

2021-02-01 3731.169922 3950.429932 3725.620117 3811.149902 3811.149902 98596960000 ^GSPC
2021-03-01 3842.510010 3994.409912 3723.340088 3972.889893 3972.889893 120863560000 ^GSPC
2021-04-01 3992.780029 4218.779785 3992.780029 4181.169922 4181.169922 82869290000 ^GSPC
2021-05-01 4191.979980 4209.390137 4128.589844 4201.620117 4201.620117 17036160000 ^GSPC
2021-05-07 4210.339844 4236.720215 4201.640137 4228.870117 4228.870117 543666845 ^GSPC

This causes a problem if i want to see monthly performance to date for the last month. The following would yield an incorrect value for the current month - it should use current day's close along with previous months close.

    `df['ret_pct'] = df['close'].pct_change(1) * 100`

get_data(ticker) return dataframe with empty data rows

Hi,
The historical data function return a pandas dataframe containing strange empty cells

I do the following
ticker = '^HSI'
yf_request = get_data(ticker)
and save dataframe as csv

In the csv, I found that some rows have only dates but all other cells are empty
for example, 21/10/2016 and 23/8/2017

get_earnings_history - data discrepancies

I am not sure if this is an issue with code or simply quality of data source. I am pulling historical earnings for AAPL using the get_earnings_history function and noticed a couple of data issues:

  1. There doesn't seem to be an earnings date or eps for Q2 of 2001
  2. for 2003-04-16, both estimate and actual are shown as 0.0 and suprise is 100%

I am guessing it may be an issue at the source - maybe needs some cleaning.

Requirements.txt

Hello,

I've noticed that the library html_requests is required to use get_expiration_dates (at least).
That might be worth adding to your requirements.txt, don't you think?

stock_info stop working even with the recent fix

Just updated to the current version for yahoo_fin. Here is the traceback of the error. Thanks

from yahoo_fin import stock_info as si

%5EGSPC failed
Exception in user code:

Traceback (most recent call last):
File "yahoo.py", line 11, in
data = si.get_data(sym)

\local-packages\Python38\site-packages\yahoo_fin\stock_info.py", line 78, in get_data
raise AssertionError(resp.json())
\local-packages\Python38\site-packages\requests\models.py", line 898, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\json_init_.py", line 357, in loads
return _default_decoder.decode(s)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

get_stats throws ValueError: Length mismatch:

get_stats('arry') throws:

Traceback (most recent call last): File "test.py", line 20, in <module> print(si.get_stats('arry')) File "/home/saswat/.local/lib/python3.6/site-packages/yahoo_fin/stock_info.py", line 242, in get_stats table.columns = ["Attribute" , "Value"] File "/home/saswat/.local/lib/python3.6/site-packages/pandas/core/generic.py", line 5154, in __setattr__ return object.__setattr__(self, name, value) File "pandas/_libs/properties.pyx", line 66, in pandas._libs.properties.AxisProperty.__set__ File "/home/saswat/.local/lib/python3.6/site-packages/pandas/core/generic.py", line 564, in _set_axis self._mgr.set_axis(axis, labels) File "/home/saswat/.local/lib/python3.6/site-packages/pandas/core/internals/managers.py", line 227, in set_axis f"Length mismatch: Expected axis has {old_len} elements, new " ValueError: Length mismatch: Expected axis has 4 elements, new values have 2 elements

It happens for all stocks (e.g., sol.mc, neoen.pa) for which quarterly-report numbers are not available for all quarters.

yahoo_fin retrieved data doesn't reflect finance.yahoo.com data

I'm having a hard time comparing the data gathered via yahoo_fin. It doesn't seem to match what I can see on the finance.yahoo.com page. For example, get_cash_flow('CSCO') returns most recent annual data reports on '2020-07-25' but the https://finance.yahoo.com/quote/csco/cash-flow?p=csco page shows '2020-07-31'.

The data gathered appears to be the same (though the you have to multiple the webpage values by 1000). Why the different dates?

Stale Data after multiple requests

When looping through a large number of symbols to retrieve options data, the data returned is out of date after ~300 requests to options.get_options_chain(ticker)

opts_py.txt

The last trade date no longer shows recent activity and the prices don't match.

This may be yahoo blocking mining attempts.

get_market_status

Can someone tell me how to use this method?

It seems everything I try it wont return anything

I've Problem

Hi
Thank you very much for your work. I have a little problem, I don't understand why when I try to download a lot of ticker from a list and a loop (> 300), the data displays a "nan" at the end of the table (see image) . Whereas when I download individually it works.

Capture

Error while running the example

Running the example in this repo gives the following error:

File "C:\Program Files\Python37\lib\site-packages\yahoo_fin\stock_info.py", line 82, in get_data
result = result.sort_values("date")
File "C:\Program Files\Python37\lib\site-packages\pandas\core\frame.py", line 4719, in sort_values
k = self._get_label_or_level_values(by, axis=axis)
File "C:\Program Files\Python37\lib\site-packages\pandas\core\generic.py", line 1702, in _get_label_or_level_values
self._check_label_or_level_ambiguity(key, axis=axis)
File "C:\Program Files\Python37\lib\site-packages\pandas\core\generic.py", line 1656, in _check_label_or_level_ambiguity
raise ValueError(msg)
ValueError: 'date' is both an index level and a column label, which is ambiguous.

FEATURE: after-hours quote

Is there a method similar to get_live_price("aapl"),
but that would provide the after-hours price after 4pm,
and the premarket price in the morning before 9:30am?

That would be nice to have.

Potential floating point round off error propagation

I've noticed that the stock prices are represented internally as numpy.float64. Representing currency as floating points has known issues and can lead to round off error accumulation over a series of operations. Any plans to address this issue in the future?

stock_info.get_data (interval = '1m') issue

If interval is set to 1m, then the end_dte calculation

2021-05-26 13:32:06,612.612 [MainThread] [connectionpool.py:452 - _make_request() ] https://query1.finance.yahoo.com:443 "GET /v8/finance/chart/PCT?period1=1621603926&period2=1622035926&interval=1m&events=div%2Csplits HTTP/1.1" 200 None

Converting period2 (1622035926) comes out to be
GMT: Wednesday, May 26, 2021 1:32:06 PM
Your time zone: Wednesday, May 26, 2021 9:32:06 AM GMT-04:00 DST
Relative: 4 hours ago

Error after updating to Py 3.7 and reinstalling yahoo_fin

After updating to Py 3.7.10 and reinstalling yahoo_fin 0.8.9, I am getting the following error:

`>>> si.get_live_price(ticker)

Traceback (most recent call last):
File "", line 1, in
File "/Volumes/Backup/Users/......./anaconda3/lib/python3.7/site-packages/yahoo_fin/stock_info.py", line 575, in get_live_price
df = get_data(ticker, end_date = pd.Timestamp.today() + pd.DateOffset(10))
File "/Volumes/Backup/Users/......./anaconda3/lib/python3.7/site-packages/yahoo_fin/stock_info.py", line 88, in get_data
raise AssertionError(resp.json())
File "/Volumes/Backup/Users/......./anaconda3/lib/python3.7/site-packages/requests/models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "/Volumes/Backup/Users/......./anaconda3/lib/python3.7/json/init.py", line 348, in loads
return _default_decoder.decode(s)
File "/Volumes/Backup/Users/......./anaconda3/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Volumes/Backup/Users/......./anaconda3/lib/python3.7/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
`

All the modules seem to be satisfying the dependency requirements of yahoo_fin

"No tables found" suddenly

Today code like

a = si.get_quote_table ( 'AAPL' )

stop worked. When debug, seems, what it suddenly need html5lib. OK, installed.
Then, when try to run this code, get:

Traceback (most recent call last):

File "C:/Users/Shake/PycharmProjects/RoboAd/Collector.py", line 1811, in
a = si.get_quote_table ( 'AAPL' )
File "C:\Users\Shake.conda\envs\RobAd\lib\site-packages\yahoo_fin\stock_info.py", line 293, in get_quote_table
tables = pd.read_html(site)
File "C:\Users\Shake.conda\envs\RobAd\lib\site-packages\pandas\io\html.py", line 1100, in read_html
displayed_only=displayed_only,
File "C:\Users\Shake.conda\envs\RobAd\lib\site-packages\pandas\io\html.py", line 915, in _parse
raise retained
File "C:\Users\Shake.conda\envs\RobAd\lib\site-packages\pandas\io\html.py", line 895, in _parse
tables = p.parse_tables()
File "C:\Users\Shake.conda\envs\RobAd\lib\site-packages\pandas\io\html.py", line 213, in parse_tables
tables = self._parse_tables(self._build_doc(), self.match, self.attrs)
File "C:\Users\Shake.conda\envs\RobAd\lib\site-packages\pandas\io\html.py", line 545, in _parse_tables
raise ValueError("No tables found")
ValueError: No tables found

Error while calling get_earnings(ticker)

File "C:\Users\Acer\Desktop\Ray\test\venv\lib\site-packages\yahoo_fin\stock_info.py", line 765, in get_earnings
result["quarterly_results"] = pd.DataFrame.from_dict(temp["earningsChart"]["quarterly"])
TypeError: 'NoneType' object is not subscriptable

fix str strip for float conversion

Hi,

This is a rare scenario, but just happened today: the stock GRPEF has a change rate of "+249,900.00%" in daily gainers. This throws an ValueError exception in stock_info(491) when converting str to float because of the comma sign. Please change the line from:
df["% Change"] = df["% Change"].map(lambda x: float(x.strip("%+")))
to
df["% Change"] = df["% Change"].map(lambda x: float(x.strip("%+").replace(",", "")))

(Apologies for not forking etc., I am still new to GitHub).

Let me know if the above makes sense.

Best,
Gil

Issue in data retrieval with different intervals.

Retrieving data has issues if extracting data for a long period. Consider the following stocks:
CROMPTON.NS and HDFCBANK.NS.
api used: data = get_data(ticker=stock, start_date=start_date, end_date=end_date,
index_as_date= True, interval = frequency)
start_date = '01/01/2014'
end_date = '01/10/2020'
. Now if frequency variable in above is "1mo" or "1d" there are no issues in output. But, if "1wk" is given we start getting different beginning points of the week and hence, when this is combined back we get alternate rows with nan.
For example data for "HDFCBANK.NS" is present for following two weeks (2016-05-03, and 2016-05-10) whereas for "CROMPTON.NS", data is present for "2016-05-08" and "2016-05-15" and hence despite being present from next week this causes issues. Both should have same week numbers to combine them. This mostly happens when stocks are listed after the "start_date" for one of the 2 stocks under consideration.
Awaiting comments and solution.

options.get_expiration_dates(TICKER) Not Returning Proper Values

I have been running into an error where the "get_expiration_dates()" will return only a couple dates or an entirely empty list. For example when working it will return this:
MOS
['June 25, 2021', 'July 2, 2021', 'July 9, 2021', 'July 16, 2021', 'July 23, 2021', 'July 30, 2021', 'September 17, 2021', 'December 17, 2021', 'January 21, 2022', 'January 20, 2023']

But will occasionally run something like this:
MOS
['January 21, 2022', 'January 20, 2023']
or
FMC
[]
Resulting in an error like below because there is no dates in the list.
Traceback (most recent call last):
File "c:\Users\User\Documents\options.py", line 300, in
bo.topFive(chosen_sector)
File "c:\Users\User\Documents\options.py", line 116, in topFive
call = self.closestCallStrike(sector[i], cur_stock_price, closing_dates[0])
IndexError: list index out of range

Possible typo on website

Possible typo your website:
Page: http://theautomatic.net/2019/04/17/how-to-get-options-data-with-python/
Heading: How to get options data for each expiration date

nflx_dates= options.get_expiration_dates("nflx")
info = {}
for date in nflx_dates:
    info[date] = options.get_options_chain("nflx")

To my understanding should be the following, since options.get_options_chain("nflx") has not idea which "date" you want

nflx_dates= options.get_expiration_dates("nflx")
info = {}
for date in nflx_dates:
    info[date] =options.get_options_data("nflx", expiry=date)

I haven't used your library, perhaps I'm mistaken

SSLerror: HTTPSConnectionPool

Hi,

New to this but I am getting these error messages when using yahoo_fin. Searched online to see what the cure is and haven't found anything. I know this is somehow related to making multiple queries within a given period of time. If I wait for a day or two, the methods work again but this is not a solution. Would appreciate it if someone who has solved it helps me out:

SSLError: HTTPSConnectionPool(host='finance.yahoo.com', port=443): Max retries exceeded with url: /quote/QCOM/options?p=QCOM (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1091)')))

On a get market status I've suddenly started getting an AssertionError

At approx 17:15 GMT I started getting this error when getting the market status.
It had been working constantly throughout the day.
I was on 0.8.8 when I started getting this error and upgraded to 0.8.9 but still getting the issue

Python 3.9.6 (default, Jul 3 2021, 16:40:50)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

from yahoo_fin import stock_info
stock_info.get_market_status()
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.9/dist-packages/yahoo_fin/stock_info.py", line 965, in get_market_status
quote_data = get_quote_data("^dji")
File "/usr/local/lib/python3.9/dist-packages/yahoo_fin/stock_info.py", line 951, in get_quote_data
raise AssertionError("""Invalid response from server. Check if ticker is
AssertionError: Invalid response from server. Check if ticker is
valid.

Getting '403 forbidden' responses

Hi,

All of the sudden, the get_data function became useless due to a bad response from yahoo finance API. I constructed the URL manually and was able to get the data from the browser, but python responses still keep returning 403 unless I add the headers:

headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
result = requests.get(site, params=params, headers=headers)

I don't know if you are planning to release a new version soon, and whether yahoo will eventually block this user agent fix, but in case it is useful, would it be possible to get a handle on the request headers within your code?

Thanks!

Add Event Data

Thanks.

def get_events(ticker, start_date = None, end_date = None, index_as_date = True):
    '''Downloads historical event data into a pandas data frame 
    
       @param: ticker
       @param: start_date = None
       @param: end_date = None
       @param: index_as_date = True
    '''
    site = build_url(ticker , start_date , end_date)
    resp = requests.get(site)
    html = resp.content
    html = html.decode()

    start = html.index("eventsData")
    end = html.index("ThemeStore")

    needed = html[start:end]
    needed = needed.strip('"eventsData":')
    needed = needed.strip("""}]},''""")
    needed = needed + "}]"

    temp = loads(needed)
    result = json_normalize(temp)
    
    # fix date field
    result['date'] = result['date'].map(lambda x: pd.datetime.fromtimestamp(x).date())

    result['ticker'] = ticker.upper()
    
    result = result[['ticker', 'date', 'type', 'data']]
    # Unused: 'amount', 'splitRatio', 'numerator', 'denominator'

    result = result.reset_index(drop = True)
    
    if index_as_date:
        result.index = result.date.copy()
        result = result.sort_values("date")
        del result["date"]
    return result

error with get_quote_table for tickers ( e.g. AMTD )

si.get_quote_table('MYL')

/usr/local/lib/python3.6/dist-packages/yahoo_fin/stock_info.py in get_quote_table(ticker, dict_result)
293 tables = pd.read_html(site)
294
295 data = tables[0].append(tables[1])
296
297 data.columns = ["attribute" , "value"]

IndexError: list index out of range

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.