The one-dollar.us Options Scalper

The one-dollar.us Options Scalper was another project that had a lot of potential during its time, but would have required some startup capital (VC attention) and more care and nurturing in order to really get off the ground.  Now I feel like the guys at Quantopian are quite on the right track, but they too have recognized that designing an intuitive interface for stock options analysis will be difficult... plus there's just so much data!!!  Nevertheless, Dan Dunn at Quantopian seemed to like the interface I provided, but they're designing the interface I ultimately wanted to provide so I'm just going to let them finish it up. ;)  (Plus, they know a little more Python than I do, which seems a great programming language choice for this task.)

The scalper was designed as a means to learn and study option decay in a graphical manner.  As weekly options were relatively new back in 2011, I decided those would be a great target because there's not a lot of data you need to store for weekly options before they expire, plus as being new instruments, perhaps one could pick up on potential arbitrage from market inefficiencies.  It was also to show the motion of the options themselves, or an entire spread, in a manner that brings it up at the same level as a stock's price.  Graphing tools I was familiar with back then typically would put the option way down on the Y axis compared to the stock's current price, and thus it's hard to draw comparisons when you're trying to study the dynamics of a cheap out-of-the-money call or a butterfly spread on a very expensive stock.  This solves the problem by smartly transposing the option's X axis ($0 price level) up to its strike price on the Y axis of the stock's graph.  At the time, there were 12 stocks whose weekly options I cared about; nowadays, I'd probably switch some of them out for more trendy or volatile securities.

The fundamental backbone of the one-dollar.us options scalper is the options data.  A great source for options data is Yahoo! Finance, but writing a crawler & scraper for each of those pages could prove unreliable as everyone knows how many times sites change their markup, and I didn't want to have to deal that much with maintenance.  Luckily I happened to walk down the sidewalk at school once during my masters with another fellow who was an intern at Yahoo! complaining about how he perceived very few people were using the Yahoo! Query Language (YQL), so I ended up exploring this and finding out you can obtain stock and in fact options data using YQL queries.  Great!

Here's the exact query I used to fetch the prices of the stocks tracked on the Scalper:

http://query.yahooapis.com/v1/public/yql?q=select%20LastTradePriceOnly%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22USO%22%2C%22GLD%22%2C%22GOOG%22%2C%22AMZN%22%2C%22SPY%22%2C%22QQQ%22%2C%22^DJX%22%2C%22BIDU%22%2C%22GS%22%2C%22C%22%2C%22PCLN%22%2C%22AAPL%22%2C%22SLV%22)&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys

This query simply returns the last trade price, and I store this information along with a timestamp into a MySQL database in order to present a graph of these stocks over the desired time frame.  Here's the query used to collect the options prices for AAPL in particular:

http://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20yahoo.finance.options%20WHERE%20symbol%3D'AAPL'&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys

The options query collects only the data for the current month (weekly series & monthly series if unexpired), but gets much more information than the stock query.  It fetches the options's symbol, whether it's a put or call, its strike price, last traded price, change from yesterday's close, bid & ask price, volume, and open interest.  In general, I ran the collection cron job every 15 minutes.  It was a compromise between smooth data points & exceeding the storage limits on my server. :-P

The other interesting facet about the Scalper was the user didn't directly have access to the underlying data, much like the model Quantopian has adopted.  In fact, Dan told me that dealers of the historical stock & options data are likely to work with you for much cheaper if you don't directly redistribute the data, so simply being able to query & visualize the data without the user needing to know the value of every single point is important.  This also means you need a really good front-end, which I whipped up using JavaScript and Flot.js charts.

The boxy elements on the front page were meant to summarize the stock price and the 4 nearest to at-the-money contracts in the front-week expiration.  The different elements would highlight in red or green depending on what had moved up or down.  With no new data in years, they all pretty much show N/A.  I had begun experimenting with some different graphical elements on http://www.one-dollar.us/options/index2.php before I abandoned the project.  The top bar, listing the ticker symbols tracked, is the gateway to all the historical information hosted on one-dollar.us.  From here, you can see a graph of the stock, and select an expiration day to play with the options for that particular week.  Once you select an expiration week, it will load the option chain on the bottom left.  You can click on any strike price to see the motion of that option graphed on top of the stock's motion in a graph right below the main stock graph.

By far, the most interesting feature is the big white graph at the bottom.  This is where you can click any of the +1/-1 fields in the option chain to simulate going long or short on any of the puts or calls in the option chain.  You can put together spreads on the fly including verticals and lopsided butterflies, or whatever you desire (as long as it doesn't involve shares of the underlying security), and the total value of that spread over the course of the whole week will be represented in the white graph.

I ended up using some of this data in a project for my master's where we tried to predict which iron condor spreads would be most ideal to sell on a given week, assuming low market volatility.  None of the visualizations were incredibly useful for it, but we were able to churn through a lot of data real fast and feed it into some pattern analyzers and machine learning algorithms.  As it turned out, the classification data worked very well on the real-world example just in time for our final presentation, but the following week, the market dynamics changed and our algorithm would have lost us a bunch of money!  There must have been an earnings surprise we didn't account for before picking.

Comments

Popular posts from this blog

Making a ROM hack of an old arcade game

Start Azure Pipeline from another pipeline with ADO CLI & PowerShell

I/O 2021: New Decade, New Frontiers