How to Get a Stock Quote Using Matlab

Note: Please read the disclaimer. The author is not providing professional investing advice.

While a previous article covered how to use Matlab to retrieve certain stock statistics from Yahoo! Finance, I thought I should post a separate script that just retrieves the price at which the stock last traded.

Why go through the trouble to do this from inside Matlab when you can just get the quote yourself right from Yahoo with a browser?

Well as (1) an engineer, I like to use Matlab to automate my stock screening process. And as (2) a value investor, I need Matlab to be able to compare what I believe a stock should be trading at, versus it’s current actual price per share.

That’s an easy way to let the computer find potential bargains. 😉

Here’s a link to the script with the function:

get_last_trade.m

And here’s an example use of it to retrieve the last trade price for Apple Inc. (ticker AAPL):

last_trade = get_last_trade(‘AAPL’);

6 thoughts on “How to Get a Stock Quote Using Matlab”

  1. hi, wow!

    actually these are for a software package called Matlab, which many engineers and engineering students use for modeling. the license is expensive so if you’re wanting to write your own similar computer scripts and aren’t a Saudi prince, try java instead. there are free compilers (e.g. NetBeans).

    good luck!
    lumi

  2. Ooooh! Never knew about that. I’ve already splurged on the license, but for those who haven’t, this sounds intriguing. Does it have the Java interface too (required to retrieve data from the web)?

    Lumi

  3. Thanks for posting this function.

    Yahoo must have made some page changes. In order to get this script to work correctly, I had to modify the MATLAB code on line 44 to:

    last_trade = str2num(line_buff(ptr_gt(5)+1:ptr_lt(6)-1));

Leave a Reply

Your email address will not be published.