Asian Options II: Monte Carlo

In a recent post, I introduced Asian options, an exotic option which pay the average of the underlying over a sequence of fixing dates.

The payoff of an Asian call is

C(T) = \Big({1 \over N}\sum^N_{i=0} S_{t_i} - K \Big)^+

and to price the option at an earlier time via risk-neutral valuation requires us to solve the integral

C(t) = P_{t,T}\ \big( \iint\cdots\int \big) \Big({1 \over N}\sum^N_{i=0} S_{t_i} - K \Big)^+ \phi(S_{t_1},S_{t_1},\cdots,S_{t_N}) dS_{t_1}dS_{t_2}\cdots dS_{t_N}

A simple way to do this is using Monte Carlo – we simulate a spot path drawn from the distribution \inline \phi(S_{t_1},S_{t_1},\cdots,S_{t_N}) and evaluate the payoff at expiry of that path, then average over a large number of paths to get an estimate of C(t).

It’s particularly easy to do this in Black-Scholes, all we have to do is simulate N gaussian variables, and evolve the underlying according to a geometric brownian motion.

I’ve updated the C++ and Excel Monte Carlo pricer on the blog to be able to price asian puts and calls by Monte Carlo – have a go and see how they behave relative to vanilla options. One subtlety is that we can no longer input a single expiry date, we now need an array of dates as our function input. If you have a look in the code, you’ll see that I’ve adjusted the function optionPricer to take a datatype MyArray, which is the default array used by XLW (it won’t be happy if you tell it to take std::vector). This array can be entered as a row or column of excel cells, and should be the dates, expressed as years from the present date, to average over.

Excel Monte-Carlo Pricer

I’ve updated the Monte-Carlo pricer to run in excel. Give it a go and the benefits should be obvious – no more messing around with consoles or repeated typing, excel provides a handy interface for running C++ files.

What you’ll need to do is:

  • Download the Excel pricing sheet
  • Download the .xll library (large!) – this is the equivalent of the old .exe file
  • Open the Excel file, and drag-and-drop the .xll file inside the pricing sheet
  • Click on the option to “enable this add-on for this session only”
  • The Option Price function should now re-calculate option price as you make changes to the parameters!

Try using the option pricer function yourself – it now works just like a native excel function, so you can drag it into many cells and it will adjust target cells as usual allowing for easy variation of parameters and plotting of results.

If you’ve successfully set up XLW and Code::Blocks as I described in a previous post, I’ve also made the source code available in a .zip file which you can load in Code::Blocks and fiddle with yourself. I’ll be doing a bit of updating soon to make the code slightly cleaner and allow pricing of more interesting options.

The old console project source code is still available in compiled form and with the source code in a zip file at the bottom of the MC pricers page.

Digital Options

Today I’m going to talk about the valuation of another type of option, the digital (or binary) option. This can be seen as a bit of a case study, as I’ll present the option payoff and the analytical price and greeks under BS assumptions, and give add-ons to allow pricing with the MONTE CARLO pricer. I’ve also updated the ANALYTICAL pricer to calculate the price and greeks of these options.

Digital options are very straight-forward, they are written on an underlying S and expire at a particular date t, at which point digital calls pay $1 if S is greater than a certain strike K or $0 if it is below that, and digital puts pay the reverse – ie. the payoff is

P_{\rm dig\ call} = \Big\{ \ \begin{matrix} \$1 \quad S \geq K\\ \$0 \quad S < K\end{matrix}

We can calculate the price exactly in the BS approximation using the same method that I used to calculate vanilla option prices by risk-neutral valuation as follows

C_{\rm dig\ call}(0) = \delta(0,t)\ {\mathbb E}[ C_{\rm dig\ call}(t) ]

where \inline C_{\rm dig\ call}(t') is the price of the option at time \inline t', and we know that this must converge to the payoff as \inline t \to t', so \inline C_{\rm dig\ call}(t) = P_{\rm dig\ call}

= \delta(0,t)\ \int^{\infty}_{-\infty} P_{\rm dig\ call} \cdot e^{-{1\over 2}x^2} dx

\inline P_{\rm dig\ call} is zero if \inline S = S_0 e^{(r - {1\over 2}\sigma^2)t + \sigma \sqrt{t} x} < K which corresponds to \inline x < {\ln{K \over S_0} - (r-{1\over 2}\sigma^2)t \over \sigma \sqrt{t}} = -d_2

= \delta(0,t)\ \cdot \$1 \cdot \int^{\infty}_{-d_2} e^{-{1\over 2}x^2} dx

= \$ \delta(0,t)\cdot \Phi(d_2)

where

d_1 = {\ln{S\over K}+(r+{1\over 2}\sigma^2)t \over \sigma \sqrt{t}} \quad ;\quad d_2 = {\ln{S\over K}+(r-{1\over 2}\sigma^2)t \over \sigma \sqrt{t}}

Since we have an analytical price, we can also calculate an expression for the GREEKS of this option by differentiating by the various parameters that appear in the price. Analytical expressions for a digital call’s greeks are:

\Delta = {\partial C \over \partial S} = e^{-rt}\cdot {\phi(d_2)\over S\sigma \sqrt{t}}

\nu = {\partial C \over \partial \sigma} = -e^{-rt}\cdot {d_1 \ \phi(d_2)\over \sigma}

\gamma = {\partial^2 C\over \partial S^2} = -e^{-rt}\cdot {d_1 \ \phi(d_2)\over S^2 \sigma^2 t} = -e^{-rt}\cdot {d_1\ \phi(d_1)\over S K \sigma^2 t}

{\rm Vanna} = {\partial^2 C \over \partial S \partial \sigma} =e^{-rt}\cdot {\phi(d_2)\over S \sigma^2 \sqrt{t}}\Big( d_1 d_2 - 1 \Big)

{\rm Volga} = {\partial^2 C \over \partial \sigma^2} = e^{-rt}\cdot {\phi(d_2)\over \sigma^2}\cdot \Big( d_1 + d_2 - d_1^2 d_2 \Big)

where

\phi(d_1) = {1\over \sqrt{2 \pi}}\ {e^{-{1\over 2}d_1^2} }

Holding a binary put and a binary call with the same strike is just the same as holding a zero-coupon bond, since we are guaranteed to receive $1 wherever the spot ends up, so the price of a binary put must be

e^{-rt} = e^{-rt}\cdot \Phi(d_2) + C_{\rm dig\ put}(t'=0)\quad \quad \quad \quad [1]

C_{\rm dig\ put}(0) = e^{-rt} \cdot \Phi(-d_2)

Moreover, differentiating equation [1] above shows that the greeks of a digital put are simply the negative of the greeks of a digital call with the same strike.

Graphs of these are shown for a typical binary option in the following graphs. Unlike vanilla options, these option prices aren’t monotonic in volatility: if they’re in-the-money, increasing vol will actually DECREASE the price since it makes them more likely to end out-of-the-money!

Price and first-order greeks for a digital call option.
Price and first-order greeks for a digital call option.
DigitalGreeks2
Second-order greeks for a digital call option. Greeks for digital puts are simply the negative of these values

One final point on pricing, note that the payoff of a digital call is the negative of the derivative of a vanilla call payoff wrt. strike; and the payoff of a digital put is the positive of the derivative of a vanilla put payoff wrt. strike. This means that any binary greek can be calculated from the corresponding vanilla greek as follows

\Omega_{\rm dig\ call} = -{\partial \Omega_{\rm call}\over \partial K}

\Omega_{\rm dig\ put} = {\partial \Omega_{\rm put}\over \partial K}

where here \inline \Omega represents a general greek.

If you haven’t yet installed the MONTE CARLO pricer, you can find some instructions for doing so in a previous post. The following links give the header and source files for binary calls and puts which can be dropped in to the project in your C++ development environment

These will register the option types with the option factory and allow monte carlo pricing of the options (so far, all of the options in the factory also have analytical expressions, but I’ll soon present some options that can only be priced by Monte Carlo).

New Section: Monte Carlo in C++

Good news, this blog has a new section – Monte Carlo pricers! I’m going to experiment to find the most convenient way of making it available for download, and would like it to be available both as a compiled .exe and also as uncompiled source code to allow readers to examine and alter it.

The first iteration can be found online now in the MONTE CARLO section. It is code for a straight-forward Monte Carlo pricer that will price calls and puts, with uniform random variates selected by park-miller and converted into gaussian variates using one of the box-muller processes (for more information on these, refer to the post on Random Numbers).

I’ve used a factory pattern so in principle it should be very straight forward to add new options and also RNG processes to the code, although there are a few more improvements that I will be making in the near future, which will extend the code to basic path-dependent options and allow easier data input by the user. I’ll be going over various aspects of the code in detail in future posts, and also putting together some instructions on how to compile the code yourself using Dev C++ (a free, open-source compiler) and how to add options and processes via the factory.

As always, if you have any problems getting the code to work, please tell me!

The Greeks

I’ve already discussed how to price vanilla options in the BS model. But options traders need to know more than just the price: they also want to know how price changes with the various other parameters in their models.

The way traders make money is just the same way that shop-keepers do – by selling options to other people for a little bit more than they buy them for. Once they sell an option, they have some money but they also have some risk, since if the price of the underlying moves in the wrong direction, they stand to lose a large amount of money. In the simplest case, a trader might be able to buy a matching option on the market for less than she sold the original option to her client for. This would cancel (‘hedge’) all of her risk, and generate a small positive profit (‘PnL’ or Profit & Loss) equal to the difference in the two prices.

This might be difficult to do, however, and it won’t generate as much profit as the trader would like, because whoever she buys the hedging option from will also be trying to charge a premium over the actual price. Another possibility is to try and create a hedged portfolio consisting of several options and the underlying stock as well, so as to minimise the net risk of the portfolio.

Since she has sold an option on a stock (for concreteness, let’s say she has sold a call option expiring at time T on a stock with a spot price S(t) and the option has strike K – because she has sold it, we say she is ‘short’ a call option), the trader will have to pay the larger of zero or ( S(T) – K ) at the option expiry to the client. Clearly, if the stock price goes up too high, she will lose more money than she received for selling the option. One possibility might be for her to buy the stock for S(t). Since she will have to pay a maximum of S(T) – K, but would be able to sell the stock for S(T), she would cover her position in the case that the stock price goes very high (and actually guarantee a profit in this case). But she has over-hedged her position – in the case that the stock falls in price, she will lose S(t) – S(T) on the stock. This is shown in the graph below.

GreekHedge3
The payoff at expiry of the three portfolios shown in the text. The unhedged option makes the trader money if spot doesn’t rise by more than the premium. The overhedged option is the reverse – now the trader loses money if the stock falls too far below the strike price – this is called a covered call, the payoff is the same as the payoff for an uncovered put option. Finally, a delta hedged option will make money as long as the spot does not move too far in either direction – the trader has taken a directionless bet, she is instead betting on volatility remaining low 

In fact, she can ‘delta-hedge’ the option by buying a fraction \inline \Delta of the stock. One way of deriving the BS equation (which I’ll get to at some point) is to construct a portfolio consisting of one option and a (negative) fraction of the underlying stock where the movement of the option price due to the underlying moving is exactly cancelled out but the movement of the underlying in the portfolio – any small increase in S(t) will increase the price of the option but decrease the value of the negative stock position so that the net portfolio change is zero. The fraction \inline \Delta is called the Delta of the option, mathematically it is the derivative of the option price C with respect to the stock price S

The price of a vanilla call is roughly the same as the payoff at expiry for very high spots and very low spots. Near-the-money, the difference between the option price and its payoff at expiry is greatest as the implicit insurance provided by the option is most useful. The delta of this option is the local gradient of the call price with spot. This is the amount of the underlying that would be required to delta-hedge the portfolio, so that its value is unaffected by small changes in the spot price.

\Delta = {\partial C \over \partial S}

For a call option this will be positive and for a put it will be negative, and the magnitude of both will be between 0 when far out-of-the-money and 1 when far in-the-money.

GreekHedge2
This graph shows the instantaneous change in PnL due to changes in spot for the three portfolios discussed above. Both the covered and the uncovered calls have some delta – a change in the spot price will have a direct effect in the value of the portfolio. By contrast, the value of the delta hedged portfolio is insensitive to the value of spot for small moves. Unfortunately, it is short gamma, so large moves in either direction will reduce portfolio value, so the trader must be careful to re-hedge frequently. As all of these portfolios are short an option, they are long theta – that is, the value of the portfolio will INCREASE with time if other factors remain constant, as the time value of the option is decaying towards expiry.

Similarly, if the market changes its mind about the implied volatility of an option, this will increase or decrease the price of the trader’s current option portfolio. This exposure can also be hedged, but now she will need to do it by trading options in the stock as the stock price itself is independent of volatility. This time the relevant quantity is the ‘vega’ of the option, the rate of change of price with respect to vol.

These sensitivities of the derivative price are called the Greeks, as they tend to be represented with various greek letters. Some examples are delta (variation with spot), vega (variation with vol), theta (variation with time); and second-order greeks like gamma (sensitivity of delta to spot), vanna (sensitivity of delta to vol, or equivalently sensitivity of vega to spot), and volga (sensitivity of vega to vol).

For vanilla options in the BS model, there are simple expressions for the greeks (see, for example, the Wikipedia page). I’ve updated the PRICERS page to give values for a few of the vanilla greeks of these options along with the price, and there are some graphs of typical greeks below.

vanillaGreeks
The deltas of a long call and long put position – note that these are opposite sign and everywhere separated by a constant value (here 1, but in general the discount factor at the option expiry). Vega is always positive – so increased vol will always increase the price. Increasing spot tends to increase the value of a call, while it decreases the value of a put, but by a progressively smaller amount as spot increases. For these options (and the graph below), spot = fwd = strike = 100; vol = 0.1, expiry = 1 and r = 0.
vanillaGreeks2
The Gamma, Vanna and Volga of long vanilla options (these are the same for a call and a put). Gamma is always positive for long options – this means that price is a convex function of spot. Vanna and volga tell us the sensitivity of other greeks to volatility, and are useful in hedging portfolios if vol is changing rapidly.

For exotic options greeks are often intractable analytically, so typically they will be calculated by ‘bump and revalue’, where input parameters are varied slightly and the change in price is observed. For example, a derivative’s \inline \Delta at spot price S could be calculated from its price by ‘bumping’ spot \inline S by a small amount \inline \delta S:

\begin{matrix} C(S+\delta S,\sigma) = C(S,\sigma) + {\partial C \over \partial S}\delta S + {1 \over 2}{\partial^2 C \over \partial S^2} (\delta S)^2 + O[(\delta S)^3] \\ C(S-\delta S,\sigma) = C(S,\sigma) - {\partial C \over \partial S}\delta S + {1 \over 2}{\partial^2 C \over \partial S^2} (\delta S)^2 + O[(\delta S)^3] \end{array}

{C(S+\delta S, \sigma) - C(S-\delta S, \sigma) \over 2 (\delta S) } = {\partial C \over \partial S} + O[(\delta S)^3] \simeq \Delta

which is the derivative delta to a very good approximation for small \inline \delta S.

Since banks will have large portfolios and want to calculate their total exposure fairly frequently, pricing procedures will typically need to be fairly fast so that these risk calculations can be done in a reasonable amount of time, which usually rules out Monte Carlo as a technique here.

These hedges will only work for small changes in the underlying price (for example, delta itself changes with the underlying price according to the second-order greek, gamma). What this means is that the trader will need to re-hedge from time to time, which will cost her some money to do – one of the main challenges for a trader is to balance the need to hedge her portfolio with the associated costs of doing so. Hopefully by buying and selling a wide variety of options to various clients she will be able to minimise many of her greek exposures naturally – this ‘warehousing of risk’ is one of the main functions that banks undertake and a key driver of their profits.

A First Pricer

Well, this wouldn’t be much of a derivatives blog without a discussion of, and pricer for, vanilla options. ‘Vanilla’ options are what quants call the basic call and put options that really are the bread-and-butter of what we do (there are good descriptions all over the web of what these are, and I’m not going to go into too much detail here).

A call(put) option on an asset is the right to buy(sell) that asset at a certain strike price, K, at a certain time, T. Usually, the underlying asset will be an asset that has a quoted market spot price, S, that it can be readily traded at. If at time T the price S is more than K, then the call option will have some value, as the asset can be bought at K and sold at S for a profit of (S – K). The put will be worthless, since the right to sell the asset at K isn’t much good if you can readily sell it on the market for a higher price S anyway! If the spot price S is below K, then the situation is reversed.

So calculating the price of the option at the expiry time is straight-forward. The question is, what is the price before this time? The answer is given by the famous Black-Scholes equation, and I’ve implemented a version in the pricer section for you to play with here: Vanilla Pricer. Clearly, before time T we don’t know what the stock price will be at time T. However, we might have some idea of what it’s probability distribution will look like. The amazing thing about option prices is that (within certain approximations) they depend only on the variance of this distribution, and not its expected value – no matter how fast we think the stock will grow, the option value is determined only by the spread of values. The more spread, the more valuable the option – because options have positive values for high terminal S, and losses are capped at zero for low terminal S, they are move valuable if there is a widespread set of outcomes possible.

What’s even more amazing is that we can get information the other way round – if we don’t know how the spot price S is going to end up, but we do have access to a market where options are being liquidly traded, we can IMPLY the terminal spot distribution from how these prices vary with strike! This is a really rich area of study and can be approached from lots of different angles, I’ll be going over some of this fairly slowly and in no particular order in the coming months.

Future posts will probably get a bit more mathematical, particularly once I’ve worked out how to use the equation editor here. Also, in implementing the pricer for vanilla options I’ve realised how woefully inadequate the maths infrastructure is in javascript for this sort of thing. I needed a cumulative normal distribution function but no default was available so I snatched the first one I could find from Wikipedia (due to Abramowitz and Stegun) but it’s not too good so I’ll address a quest for a better method of doing this quickly fairly soon. Posts of this sort will be just as much for my benefit as yours, as these sorts of tasks I’ve taken for granted before!

-QuantoDrifter