How to fetch the ETF's data into a Google Spreadsheet? - google-sheets

Following this post, where I had listed some of the interesting ETF1s I had found on some of the relevant forums, I received some valuable criticism. Now I want to use a Google spreadsheet to get the updated information of those ETFs in one place, and maybe use it for personal portfolio management. What I need:
preferably fetching data using the ISIN2 code, as the tickers/symbols are not really reliable and consistent between different databases and markets
The information I need are:
the current value of the ETF
the 1-year, 3-year, and 5-year performances/returns
current fund size
TER: Total Expense Ratio
TD: Tracking Differences
1-year volatility
For example, consider the "iShares Core MSCI World" ETF which is listed as "IWDA" on "Euronext Amsterdam" and an ISIN code of "IE00B4L5Y983". What I have read so far:
From this page and this post, I have used the GOOGLEFINANCE function to fetch the current price and some other information from Google Finance. However, I don't know how to fetch/calculate the 1/3/5-year performances, the fund size, TER, and the TD. Moreover, according to this comment, Google Finance, like many other Google products seem to be dying. So it would be great to have a more sustainable solution.
This post, suggests some syntax using index and IMPORTXML functions to fetch from etf.com. And this comment uses the same functions to fetch from nasdaq.com. But I couldn't make either to work, mainly because I don't know what symbol should I use.
This and this comments suggest the DGET and IMPORTDATA functions, to fetch data from api.iextrading.com, but I could not make it to work either.
This post and many other posts on the bogleheads.org forum, use all variants of syntax using the importHTML function to import and pars HTML tables from many different websites. There are many reliable websites that if I learn how to use this function I could fetch data from.
I would appreciate it if you could help me know how I can get the above information. Thanks for your kind support in advance.
P.S.1. From here, I was able to use the commands:
=INDEX(SPLIT(INDEX(importHTML(CONCATENATE("http://etfs.morningstar.com/quote-banner?&t=", C5), "table", 1),1,11), " "), 1, 3)
and
=INDEX(SPLIT(INDEX(importHTML(CONCATENATE("http://etfs.morningstar.com/quote-banner?&t=", C5), "table", 1),1,13), " "), 1, 2)
to pull Total fund size and TER consequently. However, they do not deliver data fro most of the ETFs and also I'm not sure how reliable this website is.
Footnotes:
1: Exchange-Traded Fund
2: International Securities Identification Number

Related

Google Sheets: Parsing users who are Program Managers

I have a spreadsheet that is always updating with 50+ rows. I am trying to retrieve users who are Program Managers (PGM) by parsing text but I am having a hard time since the data is not consistent since it's filled out by 20+ users.
I googled "google sheet parse text" but it's giving me functions such as =SEARCH, =LENS, =LEFT which I cannot use since my data is not consistent. Are there any other options or am I out of luck and must parse my info manually? Thanks in advance.
Google Sheet Link Example
in C2 use:
=ARRAYFORMULA(IFERROR(REGEXEXTRACT(B2:B,"PGM:.*")))
You may try:
=byrow(B2:B,lambda(z,if(z="",,ifna(regexextract(z,"(PGM:.*)(?:\n|$)")))))
row 6 outcome is varying a bit

Google Sheets: API To Get Crypto Prices and History?

As GOOGLEFINANCE() seems very limited in the cryptocurrencies it supports, are there any (free?) APIs that I can use to get data from?
Although I use GF() for ETH and BTC, I'm specifically looking for Price and Historical Closing Prices on ADA (Cardano).
I've searched the forum for suggestions, there aren't many and most are old. Binance's API seemed OK, but it gives prices in USDT instead of USD.
If anyone is interested, I found an API that offers a free key, although limited in the number of daily calls you can make: CoinAPI.
It seems very powerful, with quotes available in most currencies. So far, I've managed to get a current price:
Formulas shown in brown.
(1) shows the raw data returned, a two rows delimited by semi-colons.
(2) wraps a QUERY() around IMPORTDATA(), using offset 1 plus param 0, to not return the header row, then wraps all that in SPLIT() to separate the delimited text into columns.
(3) wraps (2) with INDEX() so I can get just the Price in the 4th col.
As this value will not automatically update like GOOGLEFINANCE(), I think I'll need to set a Trigger to do that.
I've also retrieved historical data, but I've yet to figure out how to split multiple rows of delimited text from the IMPORTDATA() function.
[Edit] See the solution to splitting multiple rows by #player0 at https://stackoverflow.com/a/69055990/190925.

Google data studio - Use multiple datasheet with same data keys/headers

So I've been stuck in this for some days, tryed a lot of search terms but all of them seems to bring me the same answers and i really need this:
I have a demand to join two different company's datas from the same owner, all of them have the same data sources (excel data sheets from FB ADS).
So they all share the same (keys/headers), like this:
COMPANY(1)'S ADS DATA
COMPANY(2)'S ADS DATA
So this way I need to put then togheter without having to join both of then on excel every time and also give him some nice data manipulation power.
The results should be something like this
By now I was trying to join data from the two companys but I couldn't really figure out how to properly do this so far I've made some tests and tryed reading a couple of articles and google data studio's help files. The merging data function seems to mess everything.
As a result of this merge, GDS gives me this fields:
Shouldn't I see like only one field labeled as cnt and cmp? I've noticed that GDS creates not one, but two data fields. If I try adding all data I need as key the left sheet turns all "0s". What Am I doing wrong here?
I have read your descriptions. It seems that you are looking for a solution to append both tables instead of merging the tables.
Do note that the data blending in GDS is a left outer join.
Hence, instead of doing the blending in GDS, I'd suggest you to append both datasets in Google Sheet in a separate tab before importing to GDS for visualisation. (assuming you don't mind copy-pasting the data into the Google Sheet).
Here is the formula to append both datasets in Google Sheets:
= {QUERY(A!A1:D1000,"SELECT A,B,C,D WHERE A <> ''",1);QUERY(B!A2:D, "SELECT A,B,C,D WHERE A <> '' ")}
I've created some dummy data in this google sheets and appended the data using the formula provided , you may take a look to understand further.
If you are unclear on the difference between merge and append, you may take a look in the Google Sheet documentation as well.
On a side note, I've screencast the process of answering this question and posted on my youtube channel. You may take a look if needed. (Thanks for the question and inspiration you provided for the video)

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

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