diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/analytics/option.py | 6 | ||||
| -rw-r--r-- | python/analytics/portfolio.py | 5 | ||||
| -rw-r--r-- | python/analytics/tranche_basket.py | 30 |
3 files changed, 25 insertions, 16 deletions
diff --git a/python/analytics/option.py b/python/analytics/option.py index 449ea273..898742bb 100644 --- a/python/analytics/option.py +++ b/python/analytics/option.py @@ -111,7 +111,11 @@ class BlackSwaption(ForwardIndex): else: raise ValueError("No market data available for this day") surface_id = vs.list(source, self.option_type)[-1] - self.sigma = float(vs[surface_id](self.T, np.log(self.moneyness))) + try: + self.sigma = float(vs[surface_id](self.T, np.log(self.moneyness))) + except ValueError: + surface_id = vs.list(source, "receiver")[-1] + self.sigma = float(vs[surface_id](self.T, np.log(self.moneyness))) @property def value_date(self): diff --git a/python/analytics/portfolio.py b/python/analytics/portfolio.py index 89210058..2681afae 100644 --- a/python/analytics/portfolio.py +++ b/python/analytics/portfolio.py @@ -101,7 +101,10 @@ class Portfolio: def mark(self, **kwargs): for t in self.trades: - t.mark(**kwargs) + try: + t.mark(**kwargs) + except: + continue def shock(self, params=["pnl"], **kwargs): return {trade_id: trade.shock(params, **kwargs) for trade_id, trade in self.items()} diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py index b8db1183..8e484a32 100644 --- a/python/analytics/tranche_basket.py +++ b/python/analytics/tranche_basket.py @@ -291,19 +291,18 @@ class DualCorrTranche(): names=['spread_shock', 'corr_shock'])) def mark(self, **args): - if self.index_type == "BS": - return - sql_query = ("SELECT close_spread from index_quotes_pre " - "WHERE date=%s and index=%s and series=%s and " - "tenor=%s and source=%s") - conn = serenitas_engine.raw_connection() - with conn.cursor() as c: - c.execute(sql_query, (self.value_date, self.index_type, self.series, - self.tenor, args.get("source", "MKIT"))) - params = (self.value_date, self.index_type, self.series, - self.tenor, args.get("source", "MKIT")) - spread, = c.fetchone() - self._index.tweak([spread]) + if not self.index_type == "BS": + sql_query = ("SELECT close_spread from index_quotes_pre " + "WHERE date=%s and index=%s and series=%s and " + "tenor=%s and source=%s") + conn = serenitas_engine.raw_connection() + with conn.cursor() as c: + c.execute(sql_query, (self.value_date, self.index_type, self.series, + self.tenor, args.get("source", "MKIT"))) + params = (self.value_date, self.index_type, self.series, + self.tenor, args.get("source", "MKIT")) + spread, = c.fetchone() + self._index.tweak([spread]) if 'skew' in args: el, skew_fun = args['skew'] @@ -331,7 +330,10 @@ class DualCorrTranche(): self._tranche_id = tranche_id except UnboundLocalError: pass - conn.close() + try: + conn.close() + except UnboundLocalError: + pass def jump_to_default(self, skew): curves = self._index.curves |
