-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmontecarloSurface.py
53 lines (38 loc) · 1.36 KB
/
montecarloSurface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
montecarloSurface.py
Created by Luca Camerani at 13/09/2020, University of Milano-Bicocca.
All rights reserved.
This file is part of the EcoFin-Library (https://github.com/LucaCamerani/EcoFin-Library),
and is released under the "BSD Open Source License".
"""
import matplotlib.pyplot as plt
import numpy as np
from EcoFin.math.stochasticProcess.itoProcess import ItoProcess
from EcoFin.stat.montecarloDistribution import MonteCarlo
t = 20
T = 100
dt = 1
n = 300
ito = ItoProcess(T, dt, t=t, x0=100, n=n)
simulation = None
# ---[GEOMETRIC BROWNIAN MOTION]----------------------------------------------
simulation = ito.geometricBrownianMotion(0.01, 0.02)
# ----------------------------------------------------------------------------
MC = MonteCarlo(simulation)
output = []
for i in MC.getIndexSpace():
EPDF = MC.getEmpiricalDist(index=i, bandwidth=10, fullSpace=True)
output.append(EPDF.probabilities)
X, Y = np.meshgrid(MC.getIndexSpace(), MC.getValues())
Z = np.array(output).transpose()
fig = plt.figure(figsize=(15, 8))
ax = fig.add_subplot(111, projection='3d')
fig.suptitle('Montecarlo Distribution Evolution')
surf = ax.plot_surface(X, Y, Z, alpha=.6)
for i in range(0, n):
plt.plot(MC.getIndexSpace(), simulation[i], alpha=.6)
ax.set_xlabel('Index (time)')
ax.set_ylabel('Value')
ax.set_zlabel('Probability')
plt.show()