Options Trading 5: Graphing Options

Now we have a basic understanding of options, the tools by which we can combine them to query and see how they behave with real world numbers, and a little bit of evaluation, all we need is a more complete visualization tool for differentiate strategies. GNU Plot will be our weapon of choice for this area, and rather than building a true interface to it in CL, we'll just call it and pipe commands to it. A full tutorial of GNU Plot is out of scope of this document (and there are plenty on the web), but I'll go through and explain the few commands we're going to use for those that don't desire to learn it fully.

We are going to use 5 basic commands:

As an example, the following would be a graph of a simple stock purchase (1000 shares at $12) between $10 and $14 with a label put in at the zero point for good measure:

echo "set terminal png size 500,500
set output 'test.png'
set xzeroaxis lt -1
set label 'Even at 0' at first 12, first 0
plot '-' with lines ti 'Stock Purchase'
10 -2000
11 -1000
12 0
13 1000
14 2000
e" | gnuplot

In actuality, we're going to give gnuplot a lot more data points (one per penny of stock change), but that would have cluttered this space. When looking at the above, the only things we will be replacing will be the labels, the plot, and the titles. For simplicity, we'll just always output 640x480 to 'output.png'. The following function should do just that.

(defun build-strat-plot (low high strats &optional labels)
 (let*
  ((proc (sb-ext:run-program "/usr/bin/gnuplot" nil :wait nil :input :stream :output t))
   (str (sb-ext:process-input proc)))
  (format str "set terminal png size 640,480~%")
  (format str "set output 'output.png'~%")
  (format str "set xzeroaxis lt -1~%")
  (format str "~{~{set label '$~$: $~$' at first ~2:*~$, first ~$~%~}~}"
              (mapit (mapcar #'m-to-float it) labels))
  (format str "plot ~{'-' with lines ti '~A'~^,~}~%" (mapcar #'car strats))
  (format str "~{~A~}" (mapit (strat-to-plots it low high) (mapcar #'cadr strats)))
  (close str)))

To give you an idea of what's going on here, what we're doing is getting into the 'str' variable the input stream for the process created calling '/usr/bin/gnuplot'. From there, we write out the strings as discussed above. The expected arguments are the minimum X axis, maximum X axis (stock price point), a list of pairs of the titles vs strategies we'll be looking at, and optionally a list of labels to put on the graph at various points. For completion sake, here is the mapit macro:

(defmacro mapit (fn-body lst)
 `(mapcar (lambda (it) ,fn-body) ,lst))

The only function not yet defined is #'strat-to-plots which loops over all the strategies and and creates the plot points. To do this we're going to need two utility functions first:

(defun strat-on-range (strat low high)
 (loop for price = low then (m+ $0.01 price) until (m> price high)
         collect (list price (funcall strat price))))

(defun m-to-float (money) (/ (money-pennies money) 100))

The first loops by penny from low to high creating a pair for the price and the dollar amount of the strategy at that point. Now that we have these two, we can write a short function to convert a strat, low price, and high price to points gnuplot can understand:

(defun strat-to-plots (strat low high)
 (format nil "~{~{~$ ~$~%~}~}e" (mapit (mapcar #'m-to-float it)
                                (strat-on-range strat low high))))

Now we have the tools to take a look at how certain strategies interact look over a continuum.

Graphing what we know

It'd like to take a second and graph all the strategies we've talked about so far. As a recap, here they are defined:

We should be able to get enough of an idea using the range of $9 to $15, so that's what we'll use. Here is the above list reproduced, except in code with a call to #'build-strat-plot:

(build-strat-plot $9 $15 `(("Simple Purchase" ,(buy-stock $12 1000))))
(build-strat-plot $9 $15 `(("Hold Call"       ,(hold-call $12 $0.60 1000))))
(build-strat-plot $9 $15 `(("Hold Put"        ,(hold-put $12 $0.60 1000))))
(build-strat-plot $9 $15 `(("Write Call"      ,(write-call $12 $0.55 1000))))
(build-strat-plot $9 $15 `(("Write Put"       ,(write-put $12 $0.55 1000))))
(build-strat-plot $9 $15 `(("Covered Call"    ,(covered-call $12 1000 $12 $0.55))))
(build-strat-plot $9 $15 `(("CC (Reinvested)" ,(reinvested-covered-call $12 1000 $12 $0.55))))
(build-strat-plot $9 $15 `(("Straddle"        ,(straddle $12 $0.60 $0.60 1000))))

And if we wanted to see them all on one giant graph:

(build-strat-plot $9 $15 `(("Simple Purchase" ,(buy-stock $12 1000))
                           ("Hold Call"       ,(hold-call $12 $0.60 1000))
                           ("Hold Put"        ,(hold-put $12 $0.60 1000))
                           ("Write Call"      ,(write-call $12 $0.55 1000))
                           ("Write Put"       ,(write-put $12 $0.55 1000))
                           ("Covered Call"    ,(covered-call $12 1000 $12 $0.55))
                           ("CC (Reinvested)" ,(reinvested-covered-call $12 1000 $12 $0.55))
                           ("Straddle"        ,(straddle $12 $0.60 $0.60 1000))))

This graph is definitely very tidy, because we're comparing things all based on the $12 price point. So you can easily see that there is an implied vertical line there. You can also see how all the rates of return are the same vector because we're dealing in 1000 shares, which would be much different if we used our leverage with options to purchase more. We can also classify the different strategies based on what corners they end up in:

Only things in the fourth category are potentially devastating (at this point, that's only the Written Call), but the categorization is not complete. If we look at only them, the Straddle seems to be the best strategy, so let's add one more classification:

Interesting questions

With our toolbelt ready, we can start asking some interesting questions about the previous graph.

Each of these questions we can see visually on the graph, and we can ask the system specifically. We're going to use that more later as we look at how different strategies compare to each other, and while all of the answers will intuitively make sense based on the input values we gave, the graph points us in the right direction of what to ask.

Short Sale

Let's only look at the basic tools once more in the graph. Without the Straddle or covered calls, the code and graph looks like this:

(build-strat-plot $9 $15 `(("Simple Purchase" ,(buy-stock $12 1000))
                           ("Hold Call"        ,(hold-call $12 $0.60 1000))
                           ("Hold Put"         ,(hold-put $12 $0.60 1000))
                           ("Write Call"       ,(write-call $12 $0.55 1000))
                           ("Write Put"        ,(write-put $12 $0.55 1000))))

It seems to be missing something, since it's almost symmetrical, but not quite. What we're missing is a type of strategy that makes money as the stock goes down, but loses it as the stock goes up, which is the opposite of a stock purchase. The opposite of buying selling, and so this represents a sell of stock. In code, that function would look like this:

(defun short-sale (initial-price)
 (lambda (final-price)
  (m* (m- initial-price final-price) num-shares)))

But you can't sell stock you don't own. Actually, this isn't strictly true because in the real world you borrow shares from other people and pay interest on them, but let's imagine for a moment that no one was willing to do that for you, or that is was illegal. Is there a way to achieve the same effect with options? It turns out that there is, and the insight comes from looking at the Straddle. With the Straddle, we combined an option that gained money as the price went down with an option that made money as the price went up, so maybe if we do the same thing here, we'll get a short sale. What we want is an option where losses increase as the underlying stock goes up, and money is made as it goes down. It so happens that we can easily see those on the above graph! So let's try it out and see if combining a Written Call and a Held Put does what we want:

(defun short-sale-via-options (strike-price call-premium put-premium num-shares)
 (combine
  (write-call strike-price call-premium num-shares)
  (hold-put strike-price put-premium num-shares)))

Reusing the numbers from above, the graph would look like this:

(build-strat-plot $9 $15 `(("Short sale?" ,(short-sale-via-options $12 $0.55 $0.60 1000))))

We can see that it does perform very slightly worse than a hypothetical short sale. This is due to the difference in premiums, and if we could find a Written Call and Held Put of the same price, we would have a true short sale. We'll look at this idea in more depth later on (for instance, what happens when you use this strategy and the stock price is not currently the strike price), but for now it's interesting enough that we were able to take a strategy we wished existed and were able to create it by looking at the patterns of other options.

Addendum, buying stock as options

If we can create a Short Sale like that, could we do the same for purchasing stock? Holding a Call and Writing a Put should do the trick, and indeed if we write that function, we see it to be so:

(defun buy-stock-via-options (strike-price call-premium put-premium num-shares)
 (combine
  (hold-call strike-price call-premium num-shares)
  (write-put strike-price put-premium num-shares)))

Looking at an instance vs the vanilla stock purchase shows them to be identical:

(build-strat-plot $9 $15 `(("Stock (Options)" ,(buy-stock-via-options $12 $0.60 $0.55 1000))
                             ("Stock" ,(buy-stock $12 1000))))

So why is this interesting at all? One thing that isn't captured in these various graphs and modelling is the upfront costs, and in this case that's actually of import. The up front cost of this strategy is zero, whereas a similar stock purchase would be $12000. So let's say you have a margin account, and you don't want to sell any of your currently invested funds (perhaps they are in a nice dividend paying stock). You don't want to pay the interest that you'd incur if you tapped into your margin balance, but you'd like to purchase a stock for a short to medium term. Of course, this way you don't actually own any stock so if it pays out dividends you aren't going to see any of that return, but you can use this strategy to fulfil those needs. If the stock goes down one dollar, you do have to pay the $1000 to close the positions, but that still requires far less than the $12000 for the original purchase.

On the other side, the idea of making $1000 when a stock goes up with zero up front capital investment is fascinating.