Just for fun, lets use a little web voodoo to combine Yahoo Finance data with Google Charts. Why?… because we can. All we need is a little PHP, a web server, and a URL. The goal is to download Yahoo Finance daily price data for two stocks, convert it to an array of daily returns, and plot the results using Google Charts simply by calling a URL. For instance, to produce this:

We just need to type this into our browser: http://stotastic.com/php/scatterPlot.php?tick1=BP&tick2=SPY&mm=01&dd=01&yyyy=2008
Where tick1 and tick2 are the stock tickers; and mm, dd, yyyy represent the starting date from which data is grabbed. So lets dig in and find out how PHP is used to make all this web magic work.
Read the rest of this entry »
I recently needed to generate multivariate normal values in a web browser. Since I was unable to find a simple implementation, I wrote the following JavaScript code. This code is not the fastest, and it also makes use of the Math.random() method which I can’t vouch for, but it seems to do a decent job. The first two functions are needed to generate normal values via the Box-Muller method. This implementation uses the basic trig functions of the JavaScript Math object. The third function performs a Cholesky decomposition, which is need to decompose a correlation matrix. Finally, the last function combines these functions to generate iid normals and then transform them to correlated normals.
Read the rest of this entry »