The way how to get daily stock data from Yahoo finance by only one line Matlab code

The way how to get daily stock data from Yahoo finance by only one line Matlab code

Hello I’m data scientist Hiroki.
Have you ever thinking if you can download daily stock data so that you can analyze it for your investment haven’t you?
And you have no idea where you can get the data don’t you?

This blog is for you who may have below trouble

  • ・You can’t find where you can download the stock data from.
  • ・You found some web service but it not’t for free.
  • ・You found some web service but you cannot stand it that input the stock name and mouse operation for each stock.
  • ・You want to create the graph of stock and economic indicator on the same graph but impossible on the web service.

I can explain how to get the stock data from yahoo finance with only one matlab code.

If your PC didn’t install matlab yet, don’t worry. They have 30 day’s free trial for you.
If you are not good at programming, don’t worry. You can just copy and paste of this blog code.
I’ll explain how to do it step by step from now. Let’s get started!

  1. Start Matlab software
  2. Down load program file
  3. Run one line code

1. Start Matlab software

At first, you need start Matlab software.
If you didn’t install matlab on your PC yet, you can access this page for download 30 day’s free trial Matlab.😉

2. Down load program file

Please download the program file from this web page that you can access Yahoo finance and save the file in the work directory.
(it’s lovely that you can download this kind of useful program file for free isn’t it? ❤️)

3. Run

Please create new matlab file on the directory and click new script button.

Copy below code and paste it on the file.

Data = hist_stock_data('24101950','24102021',append('^GSPC'));

Pls push the run button as shown below.

You can get S&P500 daily data from Oct 24th 1950 to Oct 24th 2021(just as an example)😀

You can get any stock data which is available on YahooFinance.com by just changing ticker symbol from ^GSPC to what ever you want👍


Example

As an example I can show you the code which give you gold ETF and gold mine stock ETF comparison graph.

%Getting two ETF data from Oct 20th 2011 to Oct 30th 2021  from YahooFinance
GLD = hist_stock_data('20102011','30102021',append('GLD')); %gold ETF(GLD)
GDX = hist_stock_data('20102011','30102021',append('GDX')); %gold mine stock ETF(GDX)

% Createing graph
yyaxis left
plot(GLD.Date,GLD.Close)
ylabel('Gold ETF [USD]')
hold on
yyaxis right
plot(GDX.Date,GDX.Close)
legend('Gold ETF(GLD)','Gold mine stock ETF(GDX)')
title('graph of gold ETF and Gold mine stock ETF')
xlabel('Year')
ylabel('Gold ETF[USD]')
ylabel('Gold mine stock ETF [USD]')

You’ll be able to get below graph.




Thank you for reading.
Hiroki🐶