How to lookup an index in Yahoo's stock API - yahoo-finance

I'm using Yahoo's stock API to get stock quotes, as described here.
Basically, I just assemble a link like this:
http://finance.yahoo.com/d/quotes.csv?s=DOW+MSFT+AAPL+GOOG&f=snl1
which'll give me a list of the current price for those stocks (DOW, MSFT, AAPL, GOOG).
All's nice and dandy, but I'd also like to get the info for the NASDAQ and S&P 500 Indices, but I have no idea what to use as the symbol for those.
I tried all of these:
NASDAQ
INDEXNASDAQ
INDEXNASDAQ:.IXIC
INDEXNASDAQ.IXIC
IXIC
to no avail.
It seems like I have the whole idea flawed (I don't really know much about finance).
Can anyone help me with this?

Use the same symbols you see on the corresponding Yahoo finance page.
Nasdaq = ^IXIC
S&P = ^GSPC
Dow = ^DJI

Related

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

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

How to extract website data into Google Sheets

I wanna extract the rating of a hotel room from Expedia in Google sheet. Unfortunatley, my code doesn't work. Can you take a look?
=IMPORTXML(https://www.expedia.co.in/Manila-Hotels-ZEN-Rooms-Pioneer-Street.h17368867.Hotel-Information,"//span[#class='rating-number']")
importXml() can import simple HTML, but it does not work with the most of modern sites. In this case too, importXml() was not able to retrieve div, span, etc. Nevertheless, you can get the whole html and then parse it.
Just change your XPath query to //html. And seen from the source, you know where and how to find the rating. So just get it by =mid(A2, find("out of 5.0", A2)-4, 3).
Sample sheet is here. I tested it with a few other hotels and it worked fine.

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 commodity data from yahoo finance?

I am working on a small widget for my projects which basically looks like this. Futures for Yahoo Finance
How can I get the data for Natural Gas, Gasoline, Crude Oil, Heating Oil and their Change?. I want to retrieve those data via json maybe and create a box widget or a ticker. The Image attached is what I am trying to make. Thank you.
PS: I tried CLJ15.NYM Symbol for Crude Oil using yahoo.finance.quotes table in the YQL Console, but it did not work.
You can type the symbol in the same way you would type in a stock. Getting data from Yahoo Finance provides you with a good example of how to use stock symbols with yql.
For those exact 4, it would look like this:
select * from yahoo.finance.quote where symbol in ("CLK15.NYM", "HOK15.NYM", "NGK15.NYM", "RBK15.NYM")
Note: you can use yahoo.finance.quote or yahoo.finance.quotes

Getting adjusted price information from Yahoo! Finance API for multiple symbols in one call

I would like to get the adjusted price (adjusting for splits and dividends) for a group of stock symbols using Yahoo! Finance. It looks like the historical prices call is limited to one symbol at a time. Could please let me know if there is a way to get multiple symbols in one call?
I would like to get this data so I can do some back testing on that data. Since I may require quite a few symbols (say 500-1000), it will be easier if I can make just a few batch calls to Yahoo!'s servers instead of making one call per symbol everyday.
Another way of getting the adjusted price is to use their daily stock price api and adjust it manually using dividend and splits information (they allow multiple symbols for their daily stock quotes). Unfortunately I cannot find any way to get splits information from the http call (guessing based on 50% or 200% is one option but if you deal with penny stocks, this can be dangerous and cannot figure out uneven splits). Also, the dividend information returned by it is not easy to decode. They seem to be returning the total over 4 quarters and the dividend date doesn't really correspond with the actual dividend date based on the historical price. The various options for the call can be found here: http://www.gummy-stuff.org/Yahoo-data.htm
Any suggestions on getting adjusted price for multiple symbols? Or Am I unnecessarily worrying about making 100s of calls to Yahoo! everyday? Ideally I would like to download all the required data within a couple of hours each day - that would be 10-20 calls per minute. Is that too much? I couldn't find any documentation on the permissible number of requests per second.
I am open to other places where I can get similar data. However, since I am just trying to learn the basics of quant trading and not trade, I would prefer free downloads.
Thanks
-e
This is an old question, but I did find a source where split data is available. Not sure how comprehensive these announcements are though:
http://biz.yahoo.com/c/09/s1.html
In the url, the "09" part is the year (2009), and the "s1" part is the month (s1 = Jan, s2 = Feb., s3 = Mar., etc.)
It isn't a nice clean CSV, but the format of the page is consistent and should be parseable. Just make a query each day for the current month, parse the page, and process any splits that you didn't see the day before.
ETA: And another source (probably less reliable than Yahoo, but can be queried by ticker):
http://getsplithistory.com/
I am not sure which language you are using but I have a sample in C#. I think it will give you the idea at least or may be help some one else
private string BASE_URL = "http://query.yahooapis.com/v1/public/yql?q=" + "select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20({0})" + "&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
Collection<Quote> quotes;
string symbolList = String.Join("%2C", quotes.Select(w => "%22" + w.Symbol + "%22").ToArray());
string url = string.Format(BASE_URL,symbolList);
XDocument doc = XDocument.Load(url);
Parse(quotes,doc);
What we are doing here is appending "," to each array item then passing that symbol list to yahoo. I have successfully fetched prices for 700 symbols in each call. Hitting yahoo servers for each ticker is a pain. I fetch stock prices for all of 6500+ tickers everyday. Earlier it use to take 3 hours now it is less than 2 mins.....sweet
Source link for that code is here - http://www.jarloo.com/get-yahoo-finance-api-data-via-yql/
P.S. Please get a api key to work smoothly. The above url is a public link where tables are timed out most of the time. Once you get an api key then your url will be (minus "public")
http://query.yahooapis.com/v1/yql

Resources