Finance, Python - European call option valuation

There is an example of this at https://www.safaribooksonline.com/library/view/python-for-finance/9781491945360/ch03.html which is taken from the book Python for Finance by Yves Hilpisch. The model used is fairly standard for finance work.

We want to arrive at the theoretical value of a call option. A call option is the right to buy a security, such as IBM stock, at a specific (strike) price within a certain time frame. The option is priced based on the riskiness or volatility of the security in relation to the strike price and current price. The example uses a European option which can only be exercised at maturity-this simplifies the problem set.

The example is using Black-Scholes model for option valuation where we have:

  • Initial stock index level S0 = 100
  • Strike price of the European call option K = 105
  • Time-to-maturity T = 1 year
  • Constant, riskless short rate r = 5%
  • Constant volatility σ  = 20%

These elements make up the following formula:

The algorithm used is as follows:

  1. Draw I (pseudo) random numbers from the standard normal distribution.
  2. Calculate all resulting index levels at maturity ST(i) for given z(i) in the previous equation. Calculate all inner values of the option at maturity as hT(i) = max(ST(i) - K,0).
  3. Estimate the option present value via the Monte Carlo estimator given in the following equation:

The script is as follows. We use numpy for the intense mathematics used. The rest of the coding is typical:

from numpy import *
# set parameters
S0 = 100.
K = 105.
T = 1.0
r = 0.05
sigma = 0.2
# how many samples we are using
I = 100000
random.seed(103)
z = random.standard_normal(I)
ST = S0 * exp((r - 0.5 * sigma ** 2) * T + sigma * sqrt(T) * z)
hT = maximum(ST - K, 0)
C0 = exp(-r * T) * sum(hT) / I
# tell user results
print ("Value of the European Call Option %5.3f" % C0)

The results under Jupyter are as shown in the following screenshot:

The 8.071 value corresponds with the published expected value 8.019 due to variance in the random numbers used. (I am seeding the random number generator to have reproducible results).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.109.151