Option Pricing With Java
Option Pricing With Java
1 Introduction
Option Pricing has lost much of it’s former allure as ”rocket science” and now-
days almost any high-school kid with a computer can calculate the price of
the most exotic of financial products. It is probably no coincidence that this
development coincides with a reduction of profits generated at option trading
desks. Most international financial institutions are only able to make money
with either very unsophisticated customers, who are not able to determine
the value of some (mostly intentionally) quite obscure products offered to
them or by taking larger and larger bets in a way only hedge-funds used to
do.
Two factors have contributed to this equalisation of the financial playing
field: On the one hand the publication of very good books to introduce
almost any interested person to the field of option pricing theory (e.g. ”Paul
Wilmott on Quantitative Finance”, by, well, Paul Wilmott, Wiley 2000 or
”An Introduction to the Mathematics of Financial Derivatives”, by Salih
Neftci, Academic Press 2000). On the other hand the proliferation of very
powerful personal computers on which even sophisticated programs can be
run in very efficiently.
In this paper we try to give an introduction to the basic concepts of option
pricing using Java.
1
3 Deriving the Black Scholes Equation
Starting with a portfolio Π of a long position in this option and a short
position (of ∆) in the underlying asset:
Π = V (S, t) − ∆S (2)
Now looking at a small change in this portfolio we get the following equation:
δV δV 1 δ2V
dV = dt + dS + σ 2 S 2 2 dt (4)
δt δS 2 δS
we can see that a small change in the portfolio is equal to:
δV δV 1 δ2V
dΠ = dt + dS + σ 2 S 2 2 dt − ∆dS (5)
δt δS 2 δS
δV
A little bit of classic delta-hedging (∆ = δS
) will reduced this to:
δV 1 2 2 δ2V
δΠ = ( + σ S )dt (6)
δt 2 δS 2
The assumption of no-arbitrage dictates that:
dΠ = rΠdt (7)
δV 1 δ2V δV
+ σ 2 S 2 2 + rS − rV = 0 (8)
δt 2 δS δS
Now, in order to use this equation for valuation purposes we need to specify
the final conditions. These are for a call: V (S, T ) = max(S − E, 0) and for
a put V (S, T ) = max(E − S, 0).
/sectoinSolution of the Black Scholes Formula Now the famous formula
for the call is a solution to this equation:
The value of a call on stock S is:
where:
2
log ES + (r + 21 σ 2 )(T − t)
d1 = √ (10)
σ T −t
√
d2 = d1 − σ T − t (11)
Here, log denotes the natural logarithm, and:
S = the price of the underlying stock (the order-size)
E = the strike price (the amount of stock in the warehouse)
r = the continuously compounded risk free interest rate (depreciation
rate for stock)
t = the time in years until the expiration of the option (well, what ever)
σ = the implied volatility for the underlying stock (volatility of orders)
N = the standard normal cumulative distribution function.
δV δ2V δV
+ a(S, t) 2 + b(S, t) + c(S, t)V = 0 (12)
δt δS δS
Using finite differences to approximate the derivatives this gives:
where
δt k 1 δt k
Aki = a − b (15)
δS 2 i 2 δS i
δt k
Bik = −2 2
ai + δtcki (16)
δS
δt k 1 δt k
Cik = a + b (17)
δS 2 i 2 δS i
3
5 Monte Carlo Method
Using the Monte-Carlo method is even easier. We know that the value of an
option (at least in the happy world of Black and Scholes) is the present value
of the expected payoff at expiry under a risk-neutral random walk. The risk
neutral random walk for S is:
therefore
V (S, t) = er(T −t) E[payof f (S, T )] (19)
But using the log-normal random walk we can write
1
d(logS) = (r − σ 2 )dt + σdX (20)
2
which cnan be integrated to
1 √
S(t + δt) = S(t) exp((r − σ 2 )t + σ δtφ (21)
2
public Main() {
double asset = 100;
double strike = 105;
double drift = 0.05;
double volatility = 0.2;
double time = 1.0;
double interestRate = 0.05;
4
new Main();
}
}
5
}
return value;
}
double sumOfValues = 0;
for (int j = 0; j < numSimulationRuns; j++) {
double asset = assetValue;
for (int i = 0; i < numTimeSteps; i++) {
6
asset = asset
* Math.exp((r - 0.5 * sig2) * timestep
+ Math.sqrt(sig2 * timestep)
* rand.nextGaussian());
}
sumOfValues += Math.max(asset - strikeValue, 0);
}
return value;
}
return v;
}
return d1;
}