Sonntag, 4. September 2011

kdb+ and option pricing/hedging

Hedging short call option Problem

Background

Imagine that there are four guys ( christoph,tsvetan, laziz,kim) shorting a call option. Now they want to hedge their risks. Let's see what their strategies are and try to compare their risks.

Christ does nothing and will just pay out the difference between the strike price and the underlying value at the expiration date.

Tsvetan will buy the underlying at the beginning and close his position at expiration date.

Lazis use a so called stoploss-strategy. On a daily basis he will buy the underlying when it is above the strike price and close the position when it is below the strike price.

Kim pretends to be smart. On a daily basis he calculates the delta of the option and holds the position according to this number.

Assume further that the
  1. spot is 100,
  2. strike is 100,
  3. maturity is 1.0 ( This refers usually to one year),
  4. vola is 0.25,
  5. risk-free-rate is 0.01.
We will use kdb+ to analyse the four strategies. For this purpose i implemented several functions in Q and the code can be downloaded from here. All the functions are in the namespace .ql.

Black scholes formula:
All four guys will receive the option value. To know what they receive at the beginning we need to 
implement the black scholes formula in KDB+.
Using the function .ql.bls will do the job.



We can see from the first colum that the option value is 10.4035392. This is the money they receive at the beginning.

Gaussian distributed random numbers
We will use geometric brownian motion to simulate the underlying process. To simulate geometric brownian motion we need gaussian distributed random numbers.
Using the function .ql.randn will do the job.

 Here you can see the typical shape of the gaussian distribution.


Numerical solution of stochastic differential equation
Now we have gaussian random numbers. We need  to implement the numerical solution of the geometric brownian motion. The function .ql.paths will do the job.

Here you can see the typical shape of the lognormal distribution. 


Christ's strategy
We will simulate  100000 paths, and each path will have 251 points. Since in a year there are 251 trading days.
 
 The frequency table shows that 53243 from 100000 cases christ does not need to pay anything. The underlying was above the strike price. Now let's plot the cumulative distribution function. 
 
It shows that the probability that Christ will loose more than 47.1 over one year of trading is 5%.


Tsvetan's Strategy
Tsvetans's strategy will generate  a negative cashflow at the beginning. 
Let's take a look at the cumulative distribution function.
 
Here you can see that Tsvetans has a lower value at risk.


Lazis's Strategy
 
On the first day Lazis buys the underlying since it is above the strike price. On the second day Lazis close his position, since it is below the strike price. Then the asset stays under the strike price until the 14 days. There he is long the asset again.
 
Lazis's var is 25.1.

Kim's Strategy
On a daily basis Kim calculates the delta according to the underlying price. He adjusts his position according to the delta.
 
The frequency plot shows that the cost is concentrated on the option value.
 
Kim's var is 11.3.