Matlab Stock Market Scripts

Below are links to various stock market related Matlab scripts.

Note: Please read the disclaimer. The author is not providing professional investing advice or recommendations. You are responsible for any investment decisions you make using the scripts and I do not guarantee that the scripts are free of errors.

as_goes_january.m
A script used to gain further insight into the reliability of the so-called January Rule (as goes January, so goes the year). See the accompanying article about this here.

examine_indices.m
A starter Matlab script for building your own market barometer. Retrieves recent price and volume action of the Dow, NASDAQ, and S&P 500 to help you identify high volume buying, selling, or stalling to help predict where the market is headed. See the accompanying article about this here.

get_hist_stock_data.m
A Matlab function that retrieves historical stock data (high, low, open, close, volume) from Yahoo! Finance and also normalizes the raw prices for splits & dividends. See the accompanying article about this here.

get_hist_google_stock_data.m
A Matlab function that retrieves historical stock data (high, low, open, close, volume) from Google Finance. See the accompanying article about this here.

get_index_pes.m
A Matlab function that estimates the current P/E’s of major US stock market indices. See the accompanying article about this here.

get_last_trade.m
A Matlab function that retrieves the “Last Trade” price per share from Yahoo! Finance. See the accompanying article about this here.

get_last_trade_google.m
Same as above except this script retrieves from Google Finance, which has real-time quotes. Accompanying article here.

get_trailing_pe.m
The main purpose of this script is just to demonstrate how to use Matlab’s java interface to retrieve any bit of data from a web page. In this case we go and read a P/E statistic from the Yahoo! Finance site. See the accompanying article about this here.

get_fwd_pe.m
A modified version of the above get_trailing_pe.m to retrieve the forward P/E instead.

simple_mvo.m
A Matlab starter script for dabbling with Modern Portfolio Theory and mean-variance optimization. See the accompanying article about this here.


{ 8 comments… read them below or add one }

sjev September 26, 2010 at 4:00 pm

Thanks for the yahoo downloader code! After using it for a year I’ve cleaned it up and added exact period for data download. It’s posted on my blog.

Lumilog October 3, 2010 at 7:15 am

Thanks for writing Sjev, and glad it’s been useful. I added a link to your blog on the site. Looks like some interesting topics you’re exploring there.

sudhanshu November 30, 2010 at 2:20 am

can i get some matlab quoets and script for comparison between various diversity techniques..especially for space and frequency

Lumilog December 26, 2010 at 3:18 pm

Hi Sudhanshu – at the moment I’m not doing any research in that area, but if I do I might put up some scripts that are useful. Maybe try the Matlab File Exchange in the mean time.

- Lumi

alex January 21, 2011 at 11:47 pm

Are you aware of any reason why

get_last_trade_google.m

is not working for the last three days? Thank you.

rep January 24, 2011 at 4:07 pm

alex: I noticed the same thing. Very frustrating. Just figured it out though…

Google must’ve recently (slightly) modified the format of their page.

Open the original get_last_trade_google.m script and edit the for loop on line 31.
It says “for i = 1:8″ .
Just change it to “for i = 1:10″ and it should work again.

Hope that helps. This is a very cool script. Thanks to the creator for posting it.

Lumilog February 13, 2011 at 5:00 pm

Alex – thanks for pointing out the problem.

Rep – thanks for fixing it for us.

I updated the file so that it should work going forward.

-lumi

Russell December 26, 2011 at 1:32 am

Hi LumiLog,
Thanks for the excellent reference scripts to help me begin using Matlab to retrieve financial data online. My question is simple: your examples show how to easily retrieve historical stock price and volume data. But, from Yahoo! finance only CURRENT stock metrics, like P/E and Revenue can be retrieved. Is there any quick and easy source of HISTORICAL stock metrics, like P/E and Revenue. My idea to this point is to use similar commands to scan the EDGAR database at sec.gov. However, to open and parse financial statements and accurately caluclate stock metrics of interest seems like a very tedious and error-prone process.
The end-game is to backtest trading algorithms based on stock metrics (like the ‘Magic Formula’) before I apply these formulas to current metrics and put my own skin in the game.
Any ideas/suggestions are greatly appreciated. And thanks for posting this exellent website/blog/reference source. Best Regards, ~Russell

Leave a Comment

{ 2 trackbacks }