diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/analytics/portfolio.py | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/python/analytics/portfolio.py b/python/analytics/portfolio.py index b797fb50..ab9084b1 100644 --- a/python/analytics/portfolio.py +++ b/python/analytics/portfolio.py @@ -34,12 +34,12 @@ class Portfolio: self.indices = [t for t in trades if isinstance(t, Index)] self.swaptions = [t for t in trades if isinstance(t, BlackSwaption)] self._keys = [] - for index in self.indices: - self._keys.append(_key_from_index(index)) - #pick the first available trade_date trade_dates = set() for index in self.indices: + self._keys.append(_key_from_index(index)) + #pick the first available trade_date trade_dates.add(index.trade_date) + for swaption in self.swaptions: trade_dates.add(swaption.index.trade_date) self._trade_date = trade_dates.pop() @@ -83,22 +83,25 @@ class Portfolio: self._trade_date = d def mark(self, source_list=[], option_type=None, model="black", surface_id=None): + #add None so that we always try everything + source_list = source_list + [None] for index, (index_type, series, tenor) in zip(self.indices, self._keys): index.mark() + if tenor != '5yr': + continue k = (index.trade_date, index_type, series, tenor) - #add None so that we always try everything - source_list = source_list + [None] - if k not in self._vs: - vs = VolatilitySurface(index_type, series, tenor, index.trade_date) - if surface_id is None: - for source in source_list: - if len(vs.list(source, option_type, model)) >=1: - break + if self.swaptions: + if k not in self._vs: + vs = VolatilitySurface(index_type, series, tenor, index.trade_date) + if surface_id is None: + for source in source_list: + if len(vs.list(source, option_type, model)) >=1: + break + else: + raise ValueError("No market data available for this day") + self._vs[k] = vs[vs.list(source, option_type, model)[-1]] else: - raise ValueError("No market data available for this day") - self._vs[k] = vs[vs.list(source, option_type, model)[-1]] - else: - self._vs[k] = vs[surface_id] + self._vs[k] = vs[surface_id] for swaption in self.swaptions: vol_surface = self._vs[(swaption.index.trade_date, ) + \ _key_from_index(swaption.index)] |
