How to Retrieve Stock Market Quotations into Excel

DRSteele

Well-known Member
Joined
Mar 31, 2015
Messages
2,640
Office Version
  1. 365
Platform
  1. Windows
One can get a huge variety of quotations from Yahoo! and download them into Excel by using Excel’s slick function WEBSERVICE combined with some text concatenation.

Here is a brief example of how to do this. You need to know the symbol that Yahoo assigns to each specific instrument and its market code. You can use the search features within the yahoo website to ascertain what you need; sometimes it takes some digging to find the correct symbols for obscure instruments, mutual funds and emerging markets. You also need to know the code for each piece of info you seek, like the LastTradeDate or LastClose. This website summarises the syntax, codes and references: Usingthe Yahoo Finance API for CSV « Jarloo

I chose to retrieve from yahoo the Name, LastTradeDate and LastTradePrice by using the codes n, d1 and l1. Simply extend right-wards for as many codes as you wish to retrieve for as many instruments as you wish, extended down-wards.


N.B. Update is not automatic, but pressing Ctrl+Alt+F9 is not much of a burden. Most quotes are delayed by at least 15 minutes; mutual funds are generally delayed by a day or two. Function WEBSERVICE often reports what look like numbers but are in fact some form of text; use of function NUMBERVALUE will convert to proper format. A worksheet full of hundreds of market symbols will indeed function, but sluggishly.

I hope this helps you.

ABCD
1STOCK DATA FROM WEB FUNCTION
2press together CTRL + ALT + f9 to refresh
3NameLast Trade DateLast Trade
(Price Only)
4code:nd1l1
5EURMAD=X"EUR/MAD"
"1/9/2017"
10.67
6USDCAD=x"USD/CAD"
"1/9/2017"
1.32
7CNQ.to"CDN NATURAL RES"
"1/9/2017"
41.89
8BBU-UN.to"BROOKFIELD BUSINESS PARTNERS LP"
"1/9/2017"
32.28
9MSFT"Microsoft Corporation"
"1/9/2017"
62.73
10XOM"Exxon Mobil Corporation Common "
"1/9/2017"
87.18
11CL=F"Light Sweet Crude Oil Futures,M"
"1/9/2017"
52.78
12NG=F"Natural Gas Mar 17"
"1/9/2017"
3.12
13RBCGLOBALENE.to"RBC Global Energy Sr A"
"1/6/2017"
44.88

<colgroup><col style="width: 25pxpx"><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet9

Worksheet Formulas
CellFormula
B5=WEBSERVICE("http://finance.yahoo.com/d/quotes.csv?s="&$A5&"&f="&B$4)
C5=WEBSERVICE("http://finance.yahoo.com/d/quotes.csv?s="&$A5&"&f="&C$4)
D5=NUMBERVALUE(WEBSERVICE("http://finance.yahoo.com/d/quotes.csv?s="&$A5&"&f="&D$4))

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

<strike>
</strike>
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi,
Is there a limit? I built a SS with my portfolio, but it seems after a certain # of stocks it stopped returning results for any additional entries. Thank you in advance!
 
Upvote 0
Hi. I don't know whether there is a limit or not. I was able to create a worksheet with symbols for the entirety of the TMX, which is a large list.
 
Upvote 0
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,680
Members
449,116
Latest member
HypnoFant

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top