aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/analytics/index.py11
-rw-r--r--python/analytics/option.py21
2 files changed, 14 insertions, 18 deletions
diff --git a/python/analytics/index.py b/python/analytics/index.py
index 85842d15..75a3e0b2 100644
--- a/python/analytics/index.py
+++ b/python/analytics/index.py
@@ -21,25 +21,24 @@ from bbg_helpers import BBG_IP, retrieve_data, init_bbg_session
from yieldcurve import get_curve, rate_helpers, YC, ql_to_jp
from weakref import WeakSet
-def g(index, spread, exercise_date, forward_yc=None, pv=None):
+def g(index, spread, exercise_date, pv=None):
"""computes the strike clean price using the expected forward yield curve. """
- if forward_yc is None:
- forward_yc = index._yc
step_in_date = exercise_date + datetime.timedelta(days=1)
exercise_date_settle = pd.Timestamp(exercise_date) + 3 * BDay()
if spread is None and index._sc is not None:
sc = index._sc
- prot = index._default_leg.pv(exercise_date, step_in_date, exercise_date_settle, forward_yc,
+ prot = index._default_leg.pv(exercise_date, step_in_date,
+ exercise_date_settle, index._yc,
index._sc, index.recovery)
else:
rates = array.array('d', [spread * 1e-4])
upfront = 0. if pv is None else pv
- sc = SpreadCurve(exercise_date, forward_yc, index.start_date,
+ sc = SpreadCurve(exercise_date, index._yc, index.start_date,
step_in_date, exercise_date_settle,
[index.end_date], rates, array.array('d', [upfront]),
array.array('d', [index.recovery]))
a = index._fee_leg.pv(exercise_date, step_in_date, exercise_date_settle,
- forward_yc, sc, True)
+ index._yc, sc, True)
if pv is not None:
return 1e4 * pv / a + spread
diff --git a/python/analytics/option.py b/python/analytics/option.py
index 9a829b15..4617cdc7 100644
--- a/python/analytics/option.py
+++ b/python/analytics/option.py
@@ -34,9 +34,9 @@ from scipy.optimize import least_squares
from scipy.special import logit, expit
def calib(S0, fp, exercise_date, exercise_date_settle,
- index, rolled_curve, tilt, w):
+ index, tilt, w):
S = S0 * tilt * 1e-4
- pv = pv_vec(S, rolled_curve, exercise_date, exercise_date_settle,
+ pv = pv_vec(S, index._yc, exercise_date, exercise_date_settle,
index.start_date, index.end_date, index.recovery,
index.fixed_rate * 1e-4)
return np.inner(pv, w) - fp
@@ -75,13 +75,12 @@ def ATMstrike(index, exercise_date):
class BlackSwaption(ForwardIndex):
"""Swaption class"""
- __slots__ = ['_forward_yc', '_T', '_G', '_strike', 'option_type',
+ __slots__ = ['_T', '_G', '_strike', 'option_type',
'notional', 'sigma', '_original_pv', '_direction']
def __init__(self, index, exercise_date, strike, option_type="payer",
direction="Long"):
ForwardIndex.__init__(self, index, exercise_date, False)
- self._forward_yc = roll_yc(index._yc, exercise_date)
self._T = None
self.strike = strike
self.option_type = option_type.lower()
@@ -121,12 +120,11 @@ class BlackSwaption(ForwardIndex):
def exercise_date(self, d):
self.forward_date = d
ForwardIndex.__init__(self, self.index, d)
- self._forward_yc = roll_yc(self.index._yc, d)
if self.index._quote_is_price:
self._strike = g(self.index, self.index.fixed_rate,
- self.exercise_date, self._forward_yc, self._G)
+ self.exercise_date, self._G)
else:
- self._G = g(self.index, K, self.exercise_date, self._forward_yc)
+ self._G = g(self.index, K, self.exercise_date)
@property
def strike(self):
@@ -140,11 +138,10 @@ class BlackSwaption(ForwardIndex):
if self.index._quote_is_price:
self._G = (100 - K) / 100
self._strike = g(self.index, self.index.fixed_rate,
- self.exercise_date, self._forward_yc, self._G)
+ self.exercise_date, self._G)
else:
- self._G = g(self.index, K, self.exercise_date, self._forward_yc)
+ self._G = g(self.index, K, self.exercise_date)
self._strike = K
- #self._G = g(self.index, K, self.exercise_date)
@property
def atm_strike(self):
@@ -374,7 +371,7 @@ class Swaption(BlackSwaption):
T = self.T
tilt = np.exp(-self.sigma**2/2 * T + self.sigma * self._Z * math.sqrt(T))
args = (self.forward_pv, self.exercise_date, self.exercise_date_settle,
- self.index, self._forward_yc, tilt, self._w)
+ self.index, tilt, self._w)
eta = 1.05
a = self.index.spread * 0.99
b = a * eta
@@ -397,7 +394,7 @@ class Swaption(BlackSwaption):
else:
raise ValueError("option_type needs to be either 'payer' or 'receiver'")
S = S0 * np.exp(-self.sigma**2/2 * T + self.sigma * Z * math.sqrt(T))
- r = pv_vec(S * 1e-4, self._forward_yc, self.exercise_date,
+ r = pv_vec(S * 1e-4, self.index._yc, self.exercise_date,
self.exercise_date_settle, self.index.start_date,
self.index.end_date, self.index.recovery, self.index.fixed_rate * 1e-4)
val = (r - self._G) * 1/math.sqrt(2*math.pi) * np.exp(-Z**2/2)