How to Import Stock Statistics into Matlab


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

There is a matlab script that goes with this article:
get_trailing_pe.m

Other posts have dealt with how to download historical stock prices into Matlab and how to adjust for splits and dividends so that you can try your luck optimizing neural networks and other homebrewed trading algorithms that are going to bring dumptrucks, DUMPTRUCKS! full of money. ‘Mon back as Cramer would say…

But perhaps you felt the article about Matlab data mining from Yahoo! Finance was just a special case because they provide special CSV files just for this application. You want more flexibility - you’d like to be able to tell Matlab to go and get any stock statistic you’re after from a web page, not a special file provided by the host.

Well the good news is it can be done (fairly) easily in Matlab. You just have to write a script to parse the source code of the web page.

If you’re like me, you learn best from example rather than theory. So here’s a link to my script that retrieves the trailing P/E for the stock of your choice from Yahoo! Finance. Invoke this function in the following way from the command line in Matlab using the stock’s ticker symbol, for example, for Google:

>>get_trailing_pe(’goog’)

This is the same information you’d get if you entered a stock ticker on the Yahoo! Finance website - then clicked on Key Statistics and read it visually out of the table.

Feel free to modify this scripts to get any other statistic you’re after.

There is a matlab script that goes with this article:
get_trailing_pe.m



Google
 



Technorati Tags: , , , ,


One Response to “How to Import Stock Statistics into Matlab”

  1. AVINASH.V Says:

    Hey man, I have been reading all the posts in your blog.please help me, i have few queries.
    This matlab thing is interesting to me since, i am an engineer myself.
    So can you tell me how to make use of these codes with matlab?
    should i enter the same code in matlab?
    where and how should i use this code?
    your response will be greatly valuable to me, and enhance my learning.

    Thanking you in advance……………

Leave a Reply