aboutsummaryrefslogtreecommitdiffstats
path: root/python/analytics
diff options
context:
space:
mode:
Diffstat (limited to 'python/analytics')
-rw-r--r--python/analytics/cms_spread.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/python/analytics/cms_spread.py b/python/analytics/cms_spread.py
index 49a59c71..71b8f601 100644
--- a/python/analytics/cms_spread.py
+++ b/python/analytics/cms_spread.py
@@ -12,8 +12,14 @@ from quantlib.time.api import (
from quantlib.time.calendars.united_states import GovernmentBond
from quantlib.indexes.swap.usd_libor_swap import UsdLiborSwapIsdaFixAm
from quantlib.experimental.coupons.swap_spread_index import SwapSpreadIndex
+from quantlib.experimental.coupons.lognormal_cmsspread_pricer import \
+ LognormalCmsSpreadPricer
from quantlib.termstructures.volatility.api import (
VolatilityType, SwaptionVolatilityMatrix)
+from quantlib.cashflows.conundrum_pricer import (
+ YieldCurveModel, NumericHaganPricer, AnalyticHaganPricer)
+from quantlib.quotes import SimpleQuote
+
from quantlib.math.matrix import Matrix
from scipy.interpolate import RectBivariateSpline
from yieldcurve import YC
@@ -92,8 +98,10 @@ def get_swaption_vol_surface(date, data, vol_type):
def get_swaption_vol_matrix(date, data, vol_type):
# figure out what to do with nan
calendar = UnitedStates()
+ data= np.delete(data, 3, axis=0)
m = Matrix.from_ndarray(data)
- option_tenors = [Period(i, Months) for i in [1, 3, 6, 9]] + \
+ print(m.to_ndarray())
+ option_tenors = [Period(i, Months) for i in [1, 3, 6]] + \
[Period(i, Years) for i in range(1, 11)] + \
[Period(i, Years) for i in [15, 20, 25, 30]]
swap_tenors = option_tenors[-14:]
@@ -107,6 +115,15 @@ def get_swaption_vol_matrix(date, data, vol_type):
Actual365Fixed(),
vol_type=vol_type))
+def quantlib_model(atm_vol, model, vol_type, corr):
+ pricer = NumericHaganPricer(atm_vol, model, SimpleQuote(0.))
+ yc = YC()
+ cmsspread_pricer = LognormalCmsSpreadPricer(pricer,
+ SimpleQuote(corr),
+ yc,
+ vol_type=vol_type)
+ return cmsspread_pricer
+
def plot_surf(surf, tenors):
xx, yy = np.meshgrid(tenors, tenors[-14:])
fig = plt.figure()