aboutsummaryrefslogtreecommitdiffstats
path: root/python/graphics.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/graphics.py')
-rw-r--r--python/graphics.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/python/graphics.py b/python/graphics.py
index cc538aa8..fc9764bb 100644
--- a/python/graphics.py
+++ b/python/graphics.py
@@ -141,4 +141,19 @@ def plot_prob_map(df, attr="pnl", path=".", color_map=cm.RdYlGn, index='IG'):
ax.set_ylabel('Probability')
ax.set_title('{} of Trade'.format(attr.title()))
- fig.colorbar(chart, shrink=.8) \ No newline at end of file
+ fig.colorbar(chart, shrink=.8)
+
+def plot_swaption_df(df, spread_shock, vol_shock, attr="pnl"):
+ val_date = df.index[0].date()
+ fig = plt.figure()
+
+ ax = fig.gca(projection='3d')
+ ## use smoothing spline on a finer grid
+ series = df[attr]
+ f = SmoothBivariateSpline(df.vol_shock.values, df.spread_shock.values, series.values)
+ xx, yy = np.meshgrid(vol_shock, spread_shock)
+ surf = ax.plot_surface(xx, yy, f(vol_shock, spread_shock).T, cmap=cm.viridis)
+ ax.set_xlabel("Volatility shock")
+ ax.set_ylabel("Spread")
+ ax.set_zlabel("PnL")
+ ax.set_title('{} of Trade on {}'.format(attr.title(), val_date)) \ No newline at end of file