簡體   English   中英

隱含波動率 3D Plot Python

[英]3D Plot of Implied Volatility in Python

I would like to plot 3D Surface of Implied volatility in Python. I have the following set of data but when I am trying to plot them it doesn't plot well as we can see in Excel. Could you please help me to plot the surface對於下面這組數據?

樣品表面

樣本數據

2020 2021年 2022年 2023年 2024年
100 0.0565 0.0876 0.6545 0.5643 0.0765
200 0.7675 0.0777 0.0654 0.8765 0.0651
300 0.0434 0.1234 0.5455 0.3498 0.7512
400 0.2223 0.5412 0.5354 0.1111 0.7433
500 0.2388 0.3421 0.7111 0.2398 0.0666

首先將您的數據加載為 DataFrame(此處為df ),並使用pandas.read_excel獲取:

       2020    2021    2022    2023    2024
100  0.0565  0.0876  0.6545  0.5643  0.0765
200  0.7675  0.0777  0.0654  0.8765  0.0651
300  0.0434  0.1234  0.5455  0.3498  0.7512
400  0.2223  0.5412  0.5354  0.1111  0.7433
500  0.2388  0.3421  0.7111  0.2398  0.0666

然后使用matplotlib

import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

X, Y = np.meshgrid(df.columns.astype(int), df.index)
ax.plot_surface(X, Y, df.to_numpy(), cmap=cm.gist_rainbow)

output:

曲面圖

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM