- 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).
- 計算機網絡
- C++案例趣學
- GAE編程指南
- 計算機圖形學編程(使用OpenGL和C++)(第2版)
- Apache Spark 2.x Machine Learning Cookbook
- Web交互界面設計與制作(微課版)
- OpenCV for Secret Agents
- Magento 2 Development Cookbook
- Mastering macOS Programming
- jQuery Mobile移動應用開發實戰(第3版)
- 深度學習原理與PyTorch實戰(第2版)
- Apache Solr PHP Integration
- Get Your Hands Dirty on Clean Architecture
- Wearable:Tech Projects with the Raspberry Pi Zero
- Java語言GUI程序設計