- Jupyter for Data Science
- Dan Toomey
- 366字
- 2021-07-08 09:22:33
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:
- Draw I (pseudo) random numbers from the standard normal distribution.
- 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).
- 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).
- SQL Server 從入門到項目實踐(超值版)
- 黑客攻防從入門到精通(實戰秘笈版)
- Redis入門指南(第3版)
- Amazon S3 Cookbook
- Java網絡編程實戰
- OpenMP核心技術指南
- Julia數據科學應用
- 超簡單:Photoshop+JavaScript+Python智能修圖與圖像自動化處理
- Python網絡爬蟲實例教程(視頻講解版)
- Google Maps JavaScript API Cookbook
- Scala編程(第4版)
- MySQL從入門到精通
- IBM DB2 9.7 Advanced Application Developer Cookbook
- 深度學習:基于Python語言和TensorFlow平臺(視頻講解版)
- 深入理解C++11:C++11新特性解析與應用