File Exchange Pick of the Week

Our best user submissions

Download Stock Data

Jiro‘s pick this week is “Historical Stock Data Download (alternate Method)” by Captain Awesome.

I’m not an expert in stocks, but I stumbled upon this entry when I received a question from a training customer asking about the now removed Datafeed Toolbox function, yahoo. Earlier this year, Yahoo! changed their API, which prevented the function from connecting to the service. As of R2017a, the yahoo function has been removed from the toolbox.

My customer wanted to know alternatives to fetching stock data from Yahoo!. The workaround I heard was to use lower-level functions to read the raw data from the website and scrape for the necessary data. As I was writing some sample code, I decided to see if there were any useful functions on the File Exchange. While there are a number of entries for fetching stock data from the web, this entry by Captain Awesome was the first one that I came across that worked out of the box. Captain Awesome had accounted for the API change.

Here is an example of fetching daily Google stock data from Jan 2010.

stock = get_yahoo_stockdata3('GOOG','2010/1/1')
stock = 
  struct with fields:

           ticker: 'GOOG'
       dataSource: 'Yahoo Finance'
       dataUpdate: '14-Dec-2017 23:42:24'
         errorMsg: ''
         dataFreq: 'd'
        dividends: []
           splits: [1×1 struct]
            range: '04-Jan-2010 to 13-Dec-2017'
         varnotes: {7×4 cell}
         DateTime: [2002×1 double]
        openPrice: [2002×1 double]
        highPrice: [2002×1 double]
         lowPrice: [2002×1 double]
       closePrice: [2002×1 double]
           volume: [2002×1 double]
    adjClosePrice: [2002×1 double]

If you look at the code, you’ll notice that it’s simply reading the website with the appropriate queries, and doing a bunch of text processing to extract data.

Comments

Give it a try and let us know what you think here or leave a comment for Captain Awesome.




Published with MATLAB® R2017b

|
  • print

コメント

コメントを残すには、ここ をクリックして MathWorks アカウントにサインインするか新しい MathWorks アカウントを作成します。