File:Black-Scholes surface plot with random paths.svg
From testwiki
Jump to navigation
Jump to search
Original file (SVG file, nominally 900 × 900 pixels, file size: 1.47 MB)
Contents
This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.
Summary
| DescriptionBlack-Scholes surface plot with random paths.svg |
English: Desc
Pythonimport numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
# Define parameters
K = 1.0
sigma = 0.2
T = 1
x = np.linspace(-0.5, 0.5, 100)
tau = np.linspace(0.0001, T, 100)
X, TAU = np.meshgrid(x, tau)
def black_scholes(x, tau):
d_plus = (1 / (sigma * np.sqrt(tau))) * (x + 0.5 * sigma**2 * tau + 0.5 * sigma**2 * tau)
d_minus = (1 / (sigma * np.sqrt(tau))) * (x + 0.5 * sigma**2 * tau - 0.5 * sigma**2 * tau)
u = K * (np.exp(x + 0.5 * sigma**2 * tau) * norm.cdf(d_plus) - norm.cdf(d_minus))
return u
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(projection='3d')
K = 1.0
sigma = 0.05
num_walks = 10
starting_points = [-0.2, -0.1, 0, 0.1, 0.2]
num_starting_points = len(starting_points)
num_points = 1000
t_values = np.linspace(1e-4, 1, num_points)
brownian_walks = np.zeros((num_starting_points, num_walks, num_points))
for i in range(num_starting_points):
for j in range(num_walks):
dt = 1 / num_points
dW = np.random.normal(0, np.sqrt(dt), num_points)
brownian_walks[i, j] = np.cumsum(dW) * sigma + starting_points[i]
for i in range(num_starting_points):
for j in range(num_walks):
B_t = brownian_walks[i,j]
S_t = np.exp(B_t)-1
S_t = S_t[::-1]
ax.plot(T-t_values, S_t, black_scholes(S_t, t_values), color='w', alpha=0.2)
ax.plot_surface(T-TAU, X, black_scholes(X, TAU), cmap='viridis')
ax.set_ylabel(r'$(S-C)}} )
ax.set_xlabel(r'$t}})
ax.set_zlabel(r'$V(S, t)}})
ax.view_init(elev=20, azim=0, roll=0)
plt.savefig("black_scholes_surface.svg")
plt.show()
|
| Date | |
| Source | Own work |
| Author | Cosmia Nebula |
Licensing
I, the copyright holder of this work, hereby publish it under the following license:
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
Captions
Add a one-line explanation of what this file represents
Items portrayed in this file
depicts
image/svg+xml
0bdeca01eba0649685532c40484f4b5456b53fb7
1,543,714 byte
900 pixel
900 pixel
File history
Click on a date/time to view the file as it appeared at that time.
| Date/Time | Thumbnail | Dimensions | User | Comment | |
|---|---|---|---|---|---|
| current | 03:51, 18 October 2023 | 900 × 900 (1.47 MB) | wikimediacommons>Cosmia Nebula | Uploaded while editing "Black–Scholes equation" on en.wikipedia.org |
File usage
There are no pages that use this file.