Skip to content

Commit b401e01

Browse files
committed
new article
1 parent 562f4ef commit b401e01

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+4153
-336
lines changed

assets/images/background.webp

-279 KB
Binary file not shown.

assets/images/site/icon.webp

-95.6 KB
Binary file not shown.
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
---
2+
title: "Monte Carlo Simulation for Option Pricing"
3+
date: 2024-06-23T00:08:25+01:00
4+
description: Physical Process of Percolation
5+
menu:
6+
sidebar:
7+
name: Option Pricing
8+
identifier: MonteCarlo_optionpricing
9+
parent: monte_carlo
10+
weight: 9
11+
hero: Option-Pricing-Models-1.jpg
12+
tags: ["Finance", "Options", "Statistics"]
13+
categories: ["Finance"]
14+
---
15+
16+
## 1. Introduction
17+
18+
In the dynamic world of finance, options play a crucial role in risk management, speculation, and portfolio optimization. An option is a contract that gives the holder the right, but not the obligation, to buy (call option) or sell (put option) an underlying asset at a predetermined price (strike price) within a specific time frame. The challenge lies in accurately pricing these financial instruments, given the uncertainties in market movements.
19+
20+
Traditional analytical methods, while powerful, often struggle with complex option structures or realistic market conditions. This is where Monte Carlo simulation steps in, offering a flexible and robust approach to option pricing. By leveraging the power of computational methods, Monte Carlo simulations can handle a wide array of option types and market scenarios, making it an indispensable tool in a quantitative analyst's toolkit.
21+
22+
## 2. The Black-Scholes Model
23+
24+
Before diving into Monte Carlo methods, it's crucial to understand the Black-Scholes model, a cornerstone in option pricing theory. Developed by Fischer Black, Myron Scholes, and Robert Merton in the early 1970s, this model revolutionized the field of quantitative finance.
25+
26+
### The Black-Scholes Formula
27+
28+
For a European call option, the Black-Scholes formula is:
29+
30+
$$
31+
C = S₀N(d_1) - Ke^{-rT}N(d_2)
32+
$$
33+
Where:
34+
$$
35+
d_1 = \frac{(ln(S_0/K) + (r + σ²/2)T)}{(σ\sqrt{T})}, \quad
36+
d_2 = d_1 - \sigma \sqrt{T}
37+
$$
38+
- C: Call option price
39+
- S₀: Current stock price
40+
- K: Strike price
41+
- r: Risk-free interest rate
42+
- T: Time to maturity
43+
- σ: Volatility of the underlying asset
44+
- N(x): Cumulative standard normal distribution function
45+
46+
### Assumptions of the Black-Scholes Model
47+
48+
The Black-Scholes model rests on several key assumptions:
49+
50+
1. The stock price follows a geometric Brownian motion with constant drift and volatility.
51+
2. No arbitrage opportunities exist in the market.
52+
3. It's possible to buy and sell any amount of stock or options (including fractional amounts).
53+
4. There are no transaction costs or taxes.
54+
5. All securities are perfectly divisible.
55+
6. The risk-free interest rate is constant and known.
56+
7. The underlying stock does not pay dividends.
57+
58+
### Limitations of the Black-Scholes Model
59+
60+
While groundbreaking, the Black-Scholes model has several limitations:
61+
62+
1. **Constant Volatility**: The model assumes volatility is constant, which doesn't hold in real markets where volatility can change dramatically.
63+
64+
2. **Log-normal Distribution**: It assumes stock returns are normally distributed, which doesn't account for the fat-tailed distributions observed in reality.
65+
66+
3. **Continuous Trading**: The model assumes continuous trading is possible, which isn't realistic in practice.
67+
68+
4. **No Dividends**: It doesn't account for dividends, which can significantly affect option prices.
69+
70+
5. **European Options Only**: The original model only prices European-style options, not American or exotic options.
71+
72+
6. **Risk-free Rate**: It assumes a constant, known risk-free rate, which can vary in reality.
73+
74+
These limitations highlight why more flexible approaches like Monte Carlo simulation are valuable in option pricing.
75+
76+
## 3. Monte Carlo Simulation: Theoretical Background
77+
78+
Monte Carlo simulation addresses many of the Black-Scholes model's limitations by using computational power to model a wide range of possible future scenarios.
79+
80+
### Basic Principles
81+
82+
Monte Carlo methods use repeated random sampling to obtain numerical results. In the context of option pricing, we simulate many possible price paths for the underlying asset and then calculate the option's payoff for each path.
83+
84+
### Application to Option Pricing
85+
86+
For option pricing, we model the stock price movement using a stochastic differential equation:
87+
88+
```
89+
dS = μSdt + σSdW
90+
```
91+
92+
Where:
93+
- S: Stock price
94+
- μ: Expected return
95+
- σ: Volatility
96+
- dW: Wiener process (random walk)
97+
98+
This equation is then discretized for simulation purposes.
99+
100+
## 4. Implementing Monte Carlo Simulation in Python
101+
102+
Let's implement a basic Monte Carlo simulation for pricing a European call option:
103+
104+
```python
105+
import numpy as np
106+
import matplotlib.pyplot as plt
107+
108+
def monte_carlo_option_pricing(S0, K, T, r, sigma, num_simulations, num_steps):
109+
dt = T / num_steps
110+
paths = np.zeros((num_simulations, num_steps + 1))
111+
paths[:, 0] = S0
112+
113+
for t in range(1, num_steps + 1):
114+
z = np.random.standard_normal(num_simulations)
115+
paths[:, t] = paths[:, t-1] * np.exp((r - 0.5 * sigma**2) * dt + sigma * np.sqrt(dt) * z)
116+
117+
option_payoffs = np.maximum(paths[:, -1] - K, 0)
118+
option_price = np.exp(-r * T) * np.mean(option_payoffs)
119+
120+
return option_price, paths
121+
122+
# Example usage
123+
S0 = 100 # Initial stock price
124+
K = 100 # Strike price
125+
T = 1 # Time to maturity (in years)
126+
r = 0.05 # Risk-free rate
127+
sigma = 0.2 # Volatility
128+
num_simulations = 10000
129+
num_steps = 252 # Number of trading days in a year
130+
131+
price, paths = monte_carlo_option_pricing(S0, K, T, r, sigma, num_simulations, num_steps)
132+
print(f"Estimated option price: {price:.2f}")
133+
```
134+
135+
This code simulates multiple stock price paths, calculates the option payoff for each path, and then averages these payoffs to estimate the option price.
136+
137+
## 5. Visualization and Analysis
138+
139+
Visualizing the results helps in understanding the distribution of possible outcomes:
140+
141+
```python
142+
plt.figure(figsize=(10, 6))
143+
plt.plot(paths[:100, :].T)
144+
plt.title("Sample Stock Price Paths")
145+
plt.xlabel("Time Steps")
146+
plt.ylabel("Stock Price")
147+
plt.show()
148+
149+
plt.figure(figsize=(10, 6))
150+
plt.hist(paths[:, -1], bins=50)
151+
plt.title("Distribution of Final Stock Prices")
152+
plt.xlabel("Stock Price")
153+
plt.ylabel("Frequency")
154+
plt.show()
155+
```
156+
157+
These visualizations show the range of possible stock price paths and the distribution of final stock prices, providing insight into the option's potential outcomes.
158+
159+
## 6. Comparison with Analytical Solutions
160+
161+
To validate our Monte Carlo results, we can compare them with the Black-Scholes analytical solution:
162+
163+
```python
164+
from scipy.stats import norm
165+
166+
def black_scholes_call(S0, K, T, r, sigma):
167+
d1 = (np.log(S0 / K) + (r + 0.5 * sigma**2) * T) / (sigma * np.sqrt(T))
168+
d2 = d1 - sigma * np.sqrt(T)
169+
return S0 * norm.cdf(d1) - K * np.exp(-r * T) * norm.cdf(d2)
170+
171+
bs_price = black_scholes_call(S0, K, T, r, sigma)
172+
print(f"Black-Scholes price: {bs_price:.2f}")
173+
print(f"Monte Carlo price: {price:.2f}")
174+
print(f"Difference: {abs(bs_price - price):.4f}")
175+
```
176+
177+
The difference between the two methods gives us an idea of the Monte Carlo simulation's accuracy.
178+
179+
## 7. Advanced Topics and Extensions
180+
181+
Monte Carlo simulation's flexibility allows for various extensions:
182+
183+
1. **Variance Reduction Techniques**: Methods like antithetic variates can improve accuracy without increasing computational cost.
184+
2. **Exotic Options**: Monte Carlo can price complex options like Asian or barrier options, which are challenging for analytical methods.
185+
3. **Incorporating Dividends**: We can easily modify the simulation to account for dividend payments.
186+
4. **Stochastic Volatility**: Models like Heston can be implemented to account for changing volatility.
187+
188+
## 8. Conclusion
189+
190+
Monte Carlo simulation offers a powerful and flexible approach to option pricing, addressing many limitations of analytical methods like the Black-Scholes model. While it can be computationally intensive, it handles complex scenarios and option structures with relative ease.
191+
192+
The method's ability to incorporate various market dynamics, such as changing volatility or dividend payments, makes it invaluable in real-world financial modeling. As computational power continues to increase, Monte Carlo methods are likely to play an even more significant role in quantitative finance.
193+
194+
However, it's important to remember that any model, including Monte Carlo simulation, is only as good as its underlying assumptions. Careful consideration of these assumptions and regular validation against market data remain crucial in applying these techniques effectively in practice.
195+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Monte Carlo
3+
menu:
4+
sidebar:
5+
name: Monte Carlo
6+
identifier: monte_carlo
7+
parent: finance
8+
weight: 10
9+
---

content/posts/finance/stock_prediction/GRU/index.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,16 @@ print(final_capital, bench_capital)
297297
```
298298

299299
> returns
300+
>
301+
>
300302
> True 81
301303
> False 72
304+
>
302305
> Name: count, dtype: int64
303-
> 10535.325897548326 9617.616876598737
306+
307+
> 10535.325 9617.617
304308
305309
## Conclusion
310+
306311
As showed in the previous section, these two simple Deep Learning models exhibits interesting positive results both regarding regression and trading metrics.
307312
The latter is particularly important, indeed a return of **5%** is obtained while the stock price decreased of approximately 4%. This also lead to a very high sharpe and colmar ratio.

data/en/sections/skills.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ skills:
4646
- name: Apache Cassandra DB
4747
logo: /images/sections/skills/cassandra.png
4848
summary: "Experience with NoSQL and distributed database"
49+
url: https://cassandra.apache.org/_/index.html
4950

5051
- name: Apache Spark
5152
logo: /images/sections/skills/spark.png

hugo.yaml

+18-12
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ module:
1010
- path: github.com/hugo-toha/hugo-toha.github.io
1111
disable: false
1212
mounts:
13-
#- source: content
14-
# target: content
15-
- source: layouts
16-
target: layouts
17-
#- source: data
18-
# target: data
19-
- source: assets
13+
# # - source: content
14+
# # target: content
15+
# # - source: layouts
16+
# # target: layouts
17+
# #- source: data
18+
# # target: data
19+
- source: assets
2020
target: assets
2121
- source: static
2222
target: static
@@ -29,6 +29,12 @@ module:
2929
target: static/files
3030
- source: ./node_modules/katex/dist/fonts
3131
target: static/fonts
32+
- source: content
33+
target: content
34+
- source: assets
35+
target: assets
36+
# - source: static
37+
# target: static
3238

3339
# Manage languages
3440
# For any more details, you can check the official documentation: https://gohugo.io/content-management/multilingual/
@@ -38,11 +44,11 @@ languages:
3844
languageName: English
3945
title: "Stefano Giannini"
4046
weight: 1
41-
it:
42-
languageCode: it
43-
languageName: Italiano
44-
title: "Stefano Giannini"
45-
weight: 2
47+
# it:
48+
# languageCode: it
49+
# languageName: Italiano
50+
# title: "Stefano Giannini"
51+
# weight: 2
4652
# se:
4753
# languageCode: se
4854
# languageName: Svenska

public/404.html

-34
Original file line numberDiff line numberDiff line change
@@ -200,40 +200,6 @@
200200

201201

202202

203-
204-
205-
206-
207-
<li class="nav-item dropdown">
208-
<a class="nav-link dropdown-toggle" href="#" id="languageSelector" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
209-
210-
211-
<span class="flag-icon flag-icon-gb"></span>
212-
213-
English
214-
</a>
215-
<div class="dropdown-menu" aria-labelledby="languageSelector">
216-
217-
<a class="dropdown-item nav-link languages-item" href="/404.html">
218-
219-
220-
<span class="flag-icon flag-icon-gb"></span>
221-
222-
English
223-
</a>
224-
225-
<a class="dropdown-item nav-link languages-item" href="/it/404.html">
226-
227-
228-
<span class="flag-icon flag-icon-it"></span>
229-
230-
Italiano
231-
</a>
232-
233-
</div>
234-
</li>
235-
236-
237203

238204
<li class="nav-item dropdown">
239205
<a class="nav-link dropdown-toggle" href="#" id="themeSelector" role="button"

public/application.801f751f884525849ac7f9c90ff0104fa632ccd4ba93f504ec0d16fdd9c82ac9.js

+322
Large diffs are not rendered by default.

public/application.97f51c3e286071444c3471235d1690400d75a930a8787cc86f8c8e4d2767277e.js

+322
Large diffs are not rendered by default.

public/categories/finance/index.html

-2
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,6 @@
238238

239239

240240

241-
242-
243241

244242
<section class="sidebar-section" id="sidebar-section">
245243
<div class="sidebar-holder">

public/categories/index.html

-36
Original file line numberDiff line numberDiff line change
@@ -200,40 +200,6 @@
200200

201201

202202

203-
204-
205-
206-
207-
<li class="nav-item dropdown">
208-
<a class="nav-link dropdown-toggle" href="#" id="languageSelector" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
209-
210-
211-
<span class="flag-icon flag-icon-gb"></span>
212-
213-
English
214-
</a>
215-
<div class="dropdown-menu" aria-labelledby="languageSelector">
216-
217-
<a class="dropdown-item nav-link languages-item" href="/categories">
218-
219-
220-
<span class="flag-icon flag-icon-gb"></span>
221-
222-
English
223-
</a>
224-
225-
<a class="dropdown-item nav-link languages-item" href="/it/categories">
226-
227-
228-
<span class="flag-icon flag-icon-it"></span>
229-
230-
Italiano
231-
</a>
232-
233-
</div>
234-
</li>
235-
236-
237203

238204
<li class="nav-item dropdown">
239205
<a class="nav-link dropdown-toggle" href="#" id="themeSelector" role="button"
@@ -272,8 +238,6 @@
272238

273239

274240

275-
276-
277241

278242
<section class="sidebar-section" id="sidebar-section">
279243
<div class="sidebar-holder">

public/categories/physics/index.html

-2
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,6 @@
238238

239239

240240

241-
242-
243241

244242
<section class="sidebar-section" id="sidebar-section">
245243
<div class="sidebar-holder">

0 commit comments

Comments
 (0)