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

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.

Related

google sheets,yahoo finance,price and dividend data

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.

Find sector by share symbol in google sheets

Is there a way to print out the GICS sector name for a specific share/ETF symbol in google sheets using the GOOGLEFINANCE commands or any other way?
Many thanks
I used this site to find several scraping methods to get data from finviz.
https://decodingmarkets.com/scrape-stock-data-from-finviz/
Extending their logic, I was able to get the company name, and the combined sector/subsector codes
(I originally used the website's scraping techniques to get Dividend data that GoogleFinance formula lacks...)
This formula gets the company name using US ticker symbol in cell C3:
=SUBSTITUTE(INDEX(IMPORTHTML("http://finviz.com/quote.ashx?t="&C3,"table",6),2,1),"*","")
Through trial and error, I found that table 6 has name and sectors. I then referenced the 2nd row and 1st column to get the name.
I found that row 3, column 1 has the sector, subsector and country combined as one value. They use a pipe | delimiter for each break.
Using the split function, I was able to split segment.
=SPLIT(SUBSTITUTE(INDEX(IMPORTHTML("http://finviz.com/quote.ashx?t="&C3,"table",6),3,1),"*",""),"|",true,true)
Its not available from Sheets
Check out the official docs:
https://support.google.com/docs/answer/3093281?hl=en
It has a lot of options but unfortunately, not that one.
If you think it would be useful, then make sure you file a feature request #
https://developers.google.com/issue-tracker
As for any other way
#GSee said it best here: https://stackoverflow.com/a/16525782/10445017

How do I get the cid of a stock for Google Finance?

While this question was asked beforehand in the following post:
How to get cid from market and symbol from google finance
The answer didn't actually answer the question. Since google finance no longer allows for historical prices beyond a year unless one inputs the appropriate cid into the URL, how does one get the corresponding cid's in order to directly input into the URL the historical prices of specific times? Is there a table available or something along those lines?

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.

Resources