官术网_书友最值得收藏!

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).

主站蜘蛛池模板: 察雅县| 阿拉尔市| 塘沽区| 喜德县| 博爱县| 万安县| 娄底市| 石屏县| 新沂市| 黄龙县| 枣强县| 靖宇县| 宜兰县| 平潭县| 贵港市| 祥云县| 毕节市| 当阳市| 绩溪县| 石家庄市| 桐梓县| 无棣县| 昭通市| 无棣县| 东乡县| 腾冲县| 忻城县| 定远县| 长武县| 汕头市| 麦盖提县| 朝阳区| 株洲市| 柘城县| 文水县| 庄浪县| 吉木乃县| 西华县| 鲁甸县| 唐河县| 苏尼特左旗|