google sheets,yahoo finance,price and dividend data - google-sheets

I created my own international portfolio tracker / dividend tracker through google sheets & yahoo finance.
The problem with international stocks is that you often cannot simply use the integrated data from google finance. KO (coca cola) is easy, CCC3.DE (also coca cola) cannot be found on google finance. suddenly some formulas stop working for some of the tickers.
For Example AD.AS does work but ccc3.de does not work.
For price is use; A1 = "CCC3.DE" or "AD.AS"
=IFNA(VALUE(IMPORTXML("https://finance.yahoo.com/quote/" &A1, "//*[#class=""D(ib) Mend(20px)""]/span[1]")))
For dividend amount I use;
=split(IMPORTXML(concatenate("http://finance.yahoo.com/quote/",index(split((E9&F9&G9),":"),0,2)),$F$22),"()"))/K9)))

It seems that Yahoo changed some things in their website and it resulted to the import formula not to work anymore for some of the webpage in Yahoo Finance as well as for some tickers. This is the result of the IMPORTXML command for the CCC3.DE ticker.
For now, I suggest finding another website/data source that will give you the same information that you need for those unavailable/unscrapeable tickers. Another option would be to wait for yahoo to fix this issue.

Related

Importing table values from yahoo finance using the IMPORTHTML function in Google Sheets

The following function in Google Sheets worked until last Friday:
=index(IMPORTHTML("https://finance.yahoo.com/quote/"&B1&"/key-statistics?p="&B1&"","table",
2),5,2)
This function would go to the statistics section in Yahoo Finance and extract the Market Cap from a stock. It stopped working today and I'm not sure why.
I tried using the following command in the Chrome console to get the table number and played with the table indices for the IMPORTHTML function but no luck:
var i = 1; [].forEach.call(document.getElementsByTagName("table"),
function(x) { console.log(i++, x); });
Did Yahoo do something to make this no longer work? OR are my indices just wrong now?
I tried using every IMPORT formula of Google Sheets and unfortunately, it is returning the same error every single time.
It seems that Yahoo changed some things in their website and it resulted to the import formula not to work anymore.
I suggest finding another website/data source that will give you the same information that you need. Or if you want to stay with Yahoo Finance, you can explore and try to use their API if you want (link-here).
EDIT: Upon further checking, it seems that this issue is only happening on some of the tickers and some webpage in Yahoo Finance. Another option would be waiting for Yahoo to fix the issue.

Why does Google Finance display the wrong price for IOC (Indian Oil Corporation) in Google Sheets?

I am using Google Sheets for fetching EOD prices of Indian stocks, using the function
=GOOGLEFINANCE("IOC","price")
Google is returning 19.51 but the closing price for IOC on 11-11-2019 is INR 135.40.
price shows real-time of a particular stock. To get closing price use close.
Use complete ticker symbol from Google Finance. "NSE:IOC" for Indian Oil.
For example:
=GOOGLEFINANCE("NSE:IOC","close",DATE(2019,11,11))
For more information you can visit the documentation.
See this image as a working example:
I found a workaround:
=ROUND(IF(MIN(GOOGLEFINANCE(A1,"marketcap")/GOOGLEFINANCE(A1,"shares"),GOOGLEFINANCE(A1,"price"))=0,GOOGLEFINANCE(A1,"marketcap")/GOOGLEFINANCE(A1,"shares"),MIN(GOOGLEFINANCE(A1,"marketcap")/GOOGLEFINANCE(A1,"shares"),GOOGLEFINANCE(A1,"price"))),3)
Haven't fully tested it yet but works so far.
First of All Google Finance function is not designed to be used for only Indian Markets hence this problem is occuring. When you search for the live prices of IOC (Indian Oil Corporation as is yours case) its showing the prices of a scrip named IOC (Itochu Corp a Japanese Company listed on Frankfurt Stock exchange)Price of IOC as FRA stock
So to Get the Price of Indian Oil Corporation you have to use the script name as NSE:IOC instead of just IOC

Get BTC prices on Google Sheets from Google Finance

I'm trying to get data from Google Finance in Google Sheets with this formula:
=GoogleFinance("CURRENCY:BTC")
But I'm getting this error:
GOOGLEFINANCE, the query for the symbol: 'CURRENCY:BTC' returned no data.
Although on Google Finance itself, I can get BTC prices:
https://www.google.com/finance?q=CURRENCY:BTC
with the same query strings.
How can I can fix this?
You need to have a from and to currency like this:
=GoogleFinance("CURRENCY:USDBTC")
For historic close price use:
=GoogleFinance("CURRENCY:USDBTC","close","07/07/2017")
If you want only the price returned use:
=iferror(index(GoogleFinance("CURRENCY:USDBTC","close","07/07/2017"),2,2))
As of 2020-08-15 the following formula works well (without any add-ons):
=GOOGLEFINANCE("BTCUSD")
Seems like it works only for BTC and ETH though.
2022-05-04, the following works on Google Sheets:
=googlefinance("CURRENCY:USDBTC") as well as most combinations of currency and BTC (and ETH, LTC, BNB, XRP, XLM, and ADA), for example GBPBTC and JPYBTC.
=googlefinance("CURRENCY:BTCUSD") works too, in the same combinations of coin and currency.
Although finance.google.com has DOGE and LINK pricing, they don't seem to work the same way in the Sheet's googlefinance function.
Another way to work with crypto currency is to use the add-on where you can extract data from other sources.
=CRYPTOFINANCE("BTCUSD")
Link below:
https://jbuty.com/how-to-get-crypto-currencies-rates-and-more-in-google-sheet-1a57e571bc14

Google Sheet: IMPORTXML from Yahoo Finance [duplicate]

This question already has answers here:
Scraping data to Google Sheets from a website that uses JavaScript
(2 answers)
Closed last month.
I'm trying to import current stock price from yahoo finance. I used a formula from some website and it partially work. I only know how to tell it to look for a specific query and it worked fine for some other data point I need but the price change query changes from
"Fw(500) Pstart(10px) Fz(24px) C($dataRed)"
to
"Fw(500) Pstart(10px) Fz(24px) C($dataGreen)"
depending if the price is up or down for the day.
How do I modify the formula I'm using below to use the "or" operator in this case? so that it will pull the price down whether the stock is up or down for the day. Thanks!
Formula I'm using:
=IMPORTXML("https://finance.yahoo.com/quote/IBM","//span[#class='Fw(500) Pstart(10px) Fz(24px) C($dataRed)']")
I noticed the other answers did not work for me (they may have worked in the past), so I decided to post this solution. Just put the ticker in cell A1 and one or both of the below formulas somewhere else.
Price:
=IFNA(VALUE(IMPORTXML("https://finance.yahoo.com/quote/" & A1, "//*[#class=""D(ib) Mend(20px)""]/span[1]")))
Change:
=IFNA(VALUE(REGEXEXTRACT(IMPORTXML("https://finance.yahoo.com/quote/" & A1,"//*[#class=""D(ib) Mend(20px)""]/span[2]"), "^.*?\s")))
Currently using googlefinance but find it does not update often enough even when updates set to every minute so currently testing if below will allow updates at least with an F5 press within the sheet
This brings in the price and other information (dated 2022/09/27)
=IMPORTXML("https://finance.yahoo.com/quote/SAVA/", "//*[#id=""quote-header-info""]/div[3]/div[1]/div[1]")
If you just want the price: =IFNA(VALUE(IMPORTXML("https://finance.yahoo.com/quote/" & $A1, "//*[#class=""D(ib) Mend(20px)""]/span[1]")))
You could use a more dynamic/generic xpath that doesnt require such specific paths such as this:
This one pulls in both the price and the change:
=ARRAY_CONSTRAIN(transpose(IMPORTXML("https://finance.yahoo.com/quote/IBM:,"//*[#class='Mt(6px)']//span")),1,2)
If you just want the price:
=trim(IMPORTXML("https://finance.yahoo.com/quote/IBM","//*[#class='Mt(6px)']//span"))
If you just want the change:
=IMPORTXML("https://finance.yahoo.com/quote/IBM","//*[#class='Mt(6px)']//span[2]")
Sadly Yahoo Finance changes the XML/HTML structure of its website quite often. The one that works for now is:
=IMPORTXML("https://finance.yahoo.com/quote/IBM/", "//*[#id=""quote-header-info""]/div[3]/div[1]/div/span[1]")
You may always open the HTML structure and use the developer tools to find and copy the X-path.
P.S.1. Though there seem to be a bug and the function can't retrieve data from URLs where there is a dot/point/period "." in the name.
P.S.2. The IMPORTHTML() function can't also fetch the latest price from Yahoo Finance because the information is neither in a table nor a list. You can try the scripts from this page and this page to list all the tables and lists.

How to get a ticker symbol from a company name with the Google Finance API?

This matter (getting a symbol form a company name) has already been solved in the following thread with Yahoo's API and I found the first and third answers quite useful.
I also noticed that the second answer dealt with Google Finance but it uses ticker symbols and not the company name ...
Unfortunately, I learnt that Yahoo sometimes uses different ticker symbols from the stock exchanges.
So I would like to do the same thing — that is, I give a company name and I get its symbol — but with the Google Finance API, instead of Yahoo's.
Is that possible ? Thanks
Back when Google Finance first provided a Google Sheets formula, it was this:
=GoogleLookup(A1, "ticker")
But this no longer works, and Google has been dropping the ball on Finance for quite some time now. The REVERSE lookup is possible tho; ie, given the TICKER SYMBOL you can look up the official corporate name (according to GoogleFinance)...
=GOOGLEFINANCE(B1, "name")
Where A1 is the cell in Google Sheets with the corporate name,
and B1 is the cell in GS w the ticker symbol.
Basically, you now need the ticker symbol to do anything with 'GOOGLEFINANCE'.
'LOOKUP' is still around but has been changed.
If you want ticker symbols, you have to write some API calls, and those solutions can be found elsewhere.

Resources