Introducing QuantLib BlackScholes and the Greeks

Post on: 23 Май, 2015 No Comment

Introducing QuantLib BlackScholes and the Greeks

The Black-Scholes Equation

So lets take a closer look at the Black-Scholes equation. First, it is important to understand the basic assumptions of the Black-Scholes model, which Ive taken from the excellent book, “Options, Futures and Other Derivatives ”, by John Hull:

  • The underlying asset price follows a random walk in accordance with a process known as Geometric Brownian Motion
  • Shorts sales are permitted
  • No transaction costs are incurred
  • No dividends are paid prior to expiration of the option
  • Security trading is continuous, with no jumps in the underlying asset price
  • The risk-free interest rate, r, is constant

The first assumption leads to a model of stock price behavior that I briefly touched on in my last post in which the underlying assets return is assumed to be constant and normally distributed, the assets price is lognormally distributed and its volatility is constant. The discrete time version of the lognormal model of stock prices is described by the equation below, which is also the starting point for the derivation of the Black-Scholes differential equation, where delta S is the change in stock price over an instantaneous period of time, t, mu represents the underlying return, sigma its volatility and delta z is a normally distributed random (stochastic) variable:

The next step is to apply Itos Lemma. which describes how a function, f, of the underlying S and time t is related to changes in S and t.  Then a riskless portfolio is formed consisting of a long position in the derivative and a short position in delta  units of the underlying (Ill get to what delta means in a moment). This effectively cancels out the randomness of the underlying stochastic process and create an instantaneously riskless position.   The position is riskless only for an instant because the relationship between f, S and t is constantly changing as the market moves.  I wont go into all the math, which is beyond the scope of this post, but the end result is the Black-Scholes differential equation:

Lastly, to solve for the value of a call and put, the appropriate boundary conditions must be used, which should be familiar from my last post as the payoff functions for a call and put respectively.

For a call, the boundary condition is:

For a put, the boundary condition is:

This results in the following equation for the value of a call:

where d1 and d2 are defined as follows:

and N is the normal cumulative probability density function. As such, N(x) is the probability that a normally distributed random variable is less than x.

To illustrate how these equations are used in practice to calculate the value of a call and put, Ive uploaded a spread sheet to my Box account at https://app.box.com/s/iqekbg6phhf9m23tuzki .  A screen shot is below:

Note that N(x) is implemented in LibreOffice (and Excel) as the function normsdist.

Also you can see that the call and put values agree with those from my previous post.

The Greeks

So lets move on to the second part of this post, in which Ill introduce and show how to calculate the Greeks .  In the context of option valuation, the Greeks refer to a standard set of option sensitivity measures.   They are:

  • Delta (df/dS) the change in the value of an option (f) given a one point change in the price of the underlying (S).  Delta is defined as the first derivative of f with respect to S.
  • Gamma (d2f/d2S) the change in the delta of an option given a one point change in the price of the  underlying (S).  Gamma is defined as the second derivative of f with respect to S.
  • Theta (df/dt) the change in the value of an option (f) given a 1 day decrease in the options time to maturity (t).  Theta is often referred to as the decay rate of an option. It is defined as the first derivative of f with respect to t.
  • Vega (df/dsigma) the change in the value of an option (f) given a one point change in the volatility (sigma).  Vega is defined as the first derivative of f with respect to sigma.
  • Rho (df/dr) the change in the value of an option (f) given a one basis point change in the risk-free rate (r).  Rho is defined as the first derivative of f with respect to r.

In options trading, the Greeks are critical to managing the risk of an options portfolio. For example, vega can be used to measure the PnL impact of a change in market volatility.

Additionally, as most option traders seek to limit their exposure to movements in the underlying, the delta of an option is used as a hedge ratio.  To achieve a delta neutral position, a trader must offset his delta by buying (selling) delta units of the underlying if the traders option delta is negative (positive).

Also, by virtue of the fact that delta and gamma are the first and second derivatives of the option valuation function (f) with respect to S, the new value of an option can be estimated by means of a Taylor series expansion .  As such, delta and gamma are similar in many respects to duration and convexity in the fixed income domain (see my March 2013 post,  Introducing QuantLib: Duration and Convexity).

So now that weve covered all the key background concepts related to the valuation of options with Black-Scholes and the measurement of option price sensitivity,  Ill show how easy it is to value an option in QuantLib using the BlackScholesCalculator class. This class, in keeping with the Black-Scholes assumptions above, takes a constant volatility (sigma) and rate (r) as input along with the underlyings price (S), the options strike (K) and the options time to maturity (t).

Unlike the original, classic Black-Scholes model, the QuantLib BlackScholesCalculator also supports an optional dividend yield.   Also, a subtle quirk of the BlackScholesCalculator implementation to watch out for is that the constructor expects sigma to be multiplied by the square root of time.

When run, the code produces the following output:

Value of 110.0 call is 2.6119

Delta of 110.0 call is 0.3095

Gamma of 110.0 call is 0.0249

Vega of 110.0 call is 0.2493

Theta of 110.0 call is -0.0160

Value of 110.0 call (spot up $1) is 2.9340

Value of 110.0 call (spot up $1) estimated from delta is 2.9214

Value of 110.0 call (spot up $1) estimated from delta and gamma is 2.9339

Value of 110.0 call (sigma up 0.01) is 2.8631

Value of 110.0 call (sigma up 0.01 estimated from vega) is 2.8612

As you can see, for small changes in the Black-Scholes input parameters, the Greeks can accurately estimate the new price of the option.   For larger changes in parameter values or when needing to consider the combined effect of multiple parameter changes (often called a scenario ), it is necessary to revalue all of the options in a portfolio. This can be expensive and time consuming depending on the performance of the option pricing code, the number of options and the complexity of the scenario.

At this point, I think weve covered all the essentials of computing option values and sensitivities with QuantLibs BlackScholesCalculator class. I hope you enjoyed my latest Introducing QuantLib post. Until next time, have fun with QuantLib!


Categories
Options  
Tags
Here your chance to leave a comment!