diff options
Diffstat (limited to 'python/swaption.py')
| -rw-r--r-- | python/swaption.py | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/python/swaption.py b/python/swaption.py index ba164e62..6a1174a7 100644 --- a/python/swaption.py +++ b/python/swaption.py @@ -138,6 +138,8 @@ class Index(): self._trade_date = d self._step_in_date = self.trade_date + datetime.timedelta(days=1) self._value_date = (pd.Timestamp(self._trade_date) + 3* BDay()).date() + if self._spread is not None: + self.spread = self.spread @classmethod def from_name(cls, index, series, tenor, trade_date = datetime.date.today()): @@ -170,29 +172,15 @@ def year_frac(d1, d2, day_count_conv = "Actual/365"): elif day_count_conv.lower() in ["actual/360", "act/360"]: return (d2-d1).days/360 -# def flat_hazard(spread, yc, trade_date=datetime.date.today(), -# cash_settle_date = None, -# start_date = datetime.date.today(), -# end_date = datetime.date(2021, 6, 20), -# recovery_rate = 0.4): -# step_in_date = trade_date + datetime.timedelta(days=1) -# if cash_settle_date is None: -# cash_settle_date = (pd.Timestamp(trade_date) + 3* BDay()).date() -# sc = SpreadCurve(trade_date, yc, start_date, step_in_date, -# cash_settle_date, -# [end_date], array.array('d', [spread]), recovery_rate) -# sc_data = sc.inspect()['data'] -# ## conversion to continuous compounding -# hazard_rate = math.log(1 + sc_data[0][1]) -# return (hazard_rate, SpreadCurve.from_flat_hazard(trade_date, hazard_rate)) -def calib(S0, fp, forward_yield_curve, exercise_date_settle, index, tilt, w): - S = S0 * tilt - a, b = strike_vec(S, forward_yield_curve, exercise_date_settle, +def calib(S0, fp, exercise_date, exercise_date_settle, index, tilt, w): + S = S0 * tilt * 1e-4 + a, b = strike_vec(S, index._yc, exercise_date, exercise_date_settle, index.start_date, index.end_date, index.recovery) - vec = a - index.fixed_rate * b - df = forward_yield_curve.discount_factor(exercise_date_settle) - return 1/df*np.inner(vec - fp, w) + vec = a - index.fixed_rate * b * 1e-4 + df = index._yc.discount_factor(exercise_date_settle) / \ + index._yc.discount_factor(index._value_date) + return np.inner(vec * df - fp, w) def g(index, spread, exercise_date): """ computes the strike price using the expected forward yield curve """ @@ -344,3 +332,12 @@ def option(index, exercise_date, sigma, K, option_type="payer"): index.start_date, index.end_date, index.recovery) val = ((a - b * index.fixed_rate)/df - G) * 1/math.sqrt(2*math.pi) * np.exp(-Z**2/2) return simps(val, Z) * yield_curve.discount_factor(exercise_date_settle) + +if __name__ == "__main__": + import datetime + from swaption import Index, Option + ig26_5yr = Index.from_name('ig', 26, '5yr', datetime.date(2016, 8, 19)) + ig26_5yr.spread = 70 + payer = Option(ig26_5yr, datetime.date(2016, 9, 21), 70) + payer.sigma = 0.4847 + payer.notional = 100e6 |
