Monday, August 9, 2010

Turning the Open SciCal into a handheld hedge fund tool

Shortly after the handheld Open SciCal got picked up, I got an order for a few Open SciCal's, hand-made, with the wifi-attachment, and to be delivered to an address in downtown Manhattan. I did a little more research, and it turns out that they're going to be used by an actual trading firm on Wallstreet. I don't know how to verify this, but it may be one of the first documented cases of a super-secret Wallstreet firm actually using Open Source Hardware.

I also got a handful of emails from people asking what on earth stock auto-correlation is, and why it's interesting. Although I'm not a professional trader, I emailed a couple of old friends of mine who are programmers at quantitative finance trading firms, and this is probably the simplest explanation I got back:

"Correlation is a popular tool for hedge funds, because it tells you whether the returns from one stock are closely linked to the returns of an industry or another stock. Auto-correlation is when you compare the returns of one stock on a given day, with it's historical returns 1, 2, 3, ... n seconds, minutes, days. weeks into the future. It helps you determine whether the stock's performance at one time can predict it's performance at some time in the future, or vice versa."

I asked for an example in source code, and here it is - very simplified, and coded up for Yahoo finance, and posted on the "Open Source App Store". This is what it does:

  • Uses the Wifi Module to connect to the internet
  • Take a stock ticker, send it to Yahoo Finance's CSV downloader
  • Download it to R, save it to an array
  • Calculate percent change in price figures (returns) for each pair of consecutive days
  • Run 1-10 day auto-correlations of the stock against itself
  • Kick out a simple little line chart showing the auto-correlation profile
To use it, I just opened R on the Open SciCal, and typed:


Now the obvious disclaimer: if you use this Open Source program, using free data from Yahoo Finance, on the Open Source Hardware calculator, and find that you lose a lot of money... you can't complain that anyone hid any part of this, since literally everything was open or free along the way. At least this way, you can see the entire inner workings of how you're gambling, as opposed to what might happen at a casino or in Las Vegas, where they do everything possible to hide the fact.

Here's a picture of Apple's stock price, on the Open SciCal:

It looks a lot like the actual Apple stock price from Yahoo, except revered in time series order:

And then here's the result of the auto-correlation algorithm with a couple different stocks (I have it repeating with Apple AAPL, Texas Instruments TXN, Yahoo YHOO, and Google GOOG):

And this would technically let someone just walk around a building, running stock return auto-correlations in their hands, presumably downloading data from a more reliable and faster updating source than just Yahoo finance, and actually making big trades as a result.

Here's a full video:

And another, longer one:

Alright, now that that's out of my system, time to get back to hacking with a few of the new sensors Justin and Mike have been working on...


1 comment:

Matt said...

Maybe they really should start using open source hardware, to prevent things like this: