-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path!_optionPriceSurface.py
49 lines (36 loc) · 1.21 KB
/
!_optionPriceSurface.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
"""
!_optionPriceSurface.py
Created by Luca Camerani at 31/08/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.dataDownload.ticker import Ticker
# [1] Setup variables
ticker = Ticker('MSFT')
# [2] Get data regarding optionsExp and merge in a variable
surfaces = getPricesSurface(ticker)
# [3] Prepare plot area
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
fig.suptitle('Option price surfaces')
# [4] Plot surfaces for Call and Put optionsExp
for type in ['call', 'put']:
if type == 'call':
surface = surfaces.call
else:
surface = surfaces.put
maturity = surface['maturity']
X, Y = np.meshgrid(surface['strike'], maturity)
Z = np.array(surface['prices'])
surf = ax.plot_surface(X, Y, Z, alpha=0.6, label='{} price'.format(type))
surf._facecolors2d = surf._facecolors3d
surf._edgecolors2d = surf._edgecolors3d
ax.set_xlabel('Strike')
ax.set_ylabel('Days to maturity')
ax.set_zlabel('Price')
ax.legend()
plt.show()