diff options
Diffstat (limited to 'python/analytics/option.py')
| -rw-r--r-- | python/analytics/option.py | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/python/analytics/option.py b/python/analytics/option.py index f21f683f..4257b4e9 100644 --- a/python/analytics/option.py +++ b/python/analytics/option.py @@ -104,7 +104,7 @@ class BlackSwaption(ForwardIndex): if rec is None: return ValueError("trade_id doesn't exist") if index is None: - index = Index.from_name(redcode=rec.security_id, maturity=rec.maturity, trade_date=rec.trade_date) + index = Index.from_name(redcode=rec.security_id, maturity=rec.maturity, value_date=rec.trade_date) index.ref = rec.index_ref instance = cls(index, rec.expiration_date, rec.strike, rec.swaption_type.lower(), direction="Long" if rec.buysell else "Short") @@ -243,7 +243,7 @@ class BlackSwaption(ForwardIndex): if self._original_pv is None: raise ValueError("original pv not set") else: - if self.index.trade_date > self.forward_date: #TODO: do the right thing + if self.index.value_date > self.forward_date: #TODO: do the right thing return 0 - self._original_pv else: return self.pv - self._original_pv @@ -268,7 +268,7 @@ class BlackSwaption(ForwardIndex): if self._T: return self._T else: - return ((self.exercise_date - self.index.trade_date).days + 0.25)/365 + return ((self.exercise_date - self.index.value_date).days + 0.25)/365 @property def gamma(self): @@ -330,7 +330,7 @@ class BlackSwaption(ForwardIndex): s = ["{:<20}{}".format(self.index.name, self.option_type), "", "{:<20}\t{:>15}".format("Trade Date", ('{:%m/%d/%y}'. - format(self.index.trade_date)))] + format(self.index.value_date)))] rows = [["Ref Sprd (bp)", self.index.spread, "Coupon (bp)", self.index.fixed_rate], ["Ref Price", self.index.price, "Maturity Date", self.index.end_date]] format_strings = [[None, "{:.2f}", None, "{:,.2f}"], @@ -448,7 +448,7 @@ def _get_keys(df, models=["black", "precise"]): yield (quotedate, source, option_type) class QuoteSurface(): - def __init__(self, index_type, series, tenor='5yr', trade_date=datetime.date.today()): + def __init__(self, index_type, series, tenor='5yr', value_date=datetime.date.today()): self._quotes = pd.read_sql_query( "SELECT quotedate, index, series, ref, fwdspread, expiry, " \ "swaption_quotes.*, quote_source " \ @@ -459,7 +459,7 @@ class QuoteSurface(): "ORDER BY quotedate DESC", _engine, parse_dates=['quotedate', 'expiry'], - params=(trade_date, index_type.upper(), series)) + params=(value_date, index_type.upper(), series)) self._quotes.loc[(self._quotes.quote_source == "GS") & (self._quotes['index'] =="HY"), ["pay_bid", "pay_offer", "rec_bid", "rec_offer"]] *=100 if self._quotes.empty: @@ -468,7 +468,7 @@ class QuoteSurface(): dt.tz_convert('America/New_York'). dt.tz_localize(None)) self._quotes = self._quotes.sort_values('quotedate') - self.trade_date = trade_date + self.value_date = value_date def list(self, source=None): """returns list of quotes""" @@ -481,8 +481,8 @@ class QuoteSurface(): return r class VolSurface(QuoteSurface): - def __init__(self, index_type, series, tenor='5yr', trade_date=datetime.date.today()): - super().__init__(index_type, series, tenor, trade_date) + def __init__(self, index_type, series, tenor='5yr', value_date=datetime.date.today()): + super().__init__(index_type, series, tenor, value_date) self._surfaces = {} def __getitem__(self, surface_id): @@ -491,7 +491,7 @@ class VolSurface(QuoteSurface): quotes = self._quotes[(self._quotes.quotedate == quotedate) & (self._quotes.quote_source == source)] quotes = quotes.assign(moneyness=quotes.strike / quotes.fwdspread, - time=((quotes.expiry - self.trade_date).dt.days + 0.25) / 365) + time=((quotes.expiry - self.value_date).dt.days + 0.25) / 365) spline = lambda df: CubicSpline(np.log(df.moneyness), df.vol, bc_type="natural") h = quotes.sort_values('moneyness').groupby('time').apply(spline) self._surfaces[surface_id] = MyInterp(h.index.values, h.values) @@ -552,9 +552,9 @@ def _calibrate(index, quotes, option_type, **kwargs): return _calibrate_sabr(index, quotes, option_type, kwargs['beta']) class ModelBasedVolSurface(VolSurface): - def __init__(self, index_type, series, tenor='5yr', trade_date=datetime.date.today()): - super().__init__(index_type, series, tenor, trade_date) - self._index = Index.from_name(index_type, series, tenor, trade_date, notional=1.) + def __init__(self, index_type, series, tenor='5yr', value_date=datetime.date.today()): + super().__init__(index_type, series, tenor, value_date) + self._index = Index.from_name(index_type, series, tenor, value_date, notional=1.) self._surfaces = {} self._quotes = self._quotes.assign( pay_mid=self._quotes[['pay_bid', 'pay_offer']].mean(1) * 1e-4, @@ -619,18 +619,18 @@ def _forward_annuity(expiry, index): step_in_date = expiry + datetime.timedelta(days=1) expiry_settle = pd.Timestamp(expiry) + 3* BDay() df = index._yc.discount_factor(expiry_settle) - a = index._fee_leg.pv(index.trade_date, step_in_date, - index.trade_date, index._yc, index._sc, False) + a = index._fee_leg.pv(index.value_date, step_in_date, + index.value_date, index._yc, index._sc, False) Delta = index._fee_leg.accrued(step_in_date) q = index._sc.survival_probability(expiry) return a - Delta * df * q class ProbSurface(QuoteSurface): - def __init__(self, index_type, series, tenor='5yr', trade_date=datetime.date.today()): - super().__init__(index_type, series, tenor, trade_date) + def __init__(self, index_type, series, tenor='5yr', value_date=datetime.date.today()): + super().__init__(index_type, series, tenor, value_date) self._surfaces = {} - self._index = Index.from_name(index_type, series, tenor, trade_date) + self._index = Index.from_name(index_type, series, tenor, value_date) def __getitem__(self, surface_id): if surface_id not in self._surfaces: @@ -638,7 +638,7 @@ class ProbSurface(QuoteSurface): quotes = self._quotes[(self._quotes.quotedate == quotedate) & (self._quotes.quote_source == source)] self._index.ref = quotes.ref.iat[0] - quotes = quotes.assign(time=((quotes.expiry - self.trade_date).dt.days + 0.25) / 365, + quotes = quotes.assign(time=((quotes.expiry - self.value_date).dt.days + 0.25) / 365, pay_mid=quotes[['pay_bid','pay_offer']].mean(1), rec_mid=quotes[['rec_bid','rec_offer']].mean(1), forward_annuity=quotes.expiry.apply(_forward_annuity, |
