diff options
Diffstat (limited to 'python/analytics/portfolio.py')
| -rw-r--r-- | python/analytics/portfolio.py | 41 |
1 files changed, 8 insertions, 33 deletions
diff --git a/python/analytics/portfolio.py b/python/analytics/portfolio.py index ad09b09e..22ccaaf7 100644 --- a/python/analytics/portfolio.py +++ b/python/analytics/portfolio.py @@ -31,10 +31,10 @@ class Portfolio: self.trades = trades self.indices = [t for t in trades if isinstance(t, Index)] self.swaptions = [t for t in trades if isinstance(t, BlackSwaption)] - value_dates = set(index.value_date for index in self.indices) - self._keys = [(index.index_type, index.series, index.tenor) for index in self.indices] + value_dates = set(t.value_date for t in self.trades) + self._keys = set([(index.index_type, index.series, index.tenor) for index in self.indices]) for swaption in self.swaptions: - value_dates.add(swaption.index.value_date) + self._keys.add((swaption.index.index_type, swaption.index.series, swaption.index.tenor)) self._value_date = value_dates.pop() if len(value_dates) >= 1: warn("not all instruments have the same trade date, picking {}". @@ -67,38 +67,13 @@ class Portfolio: @value_date.setter def value_date(self, d): - #we try to keep everybody in sync - for index in self.indices: - index.value_date = d - if len(self.indices) == 0: - for swaption in self.swaptions: - swaption.index.value_date = d + for t in self.trades: + t.value_date = d self._value_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.value_date, index_type, series, tenor) - if self.swaptions: - if k not in self._vs: - vs = BlackSwaptionVolSurface(index_type, series, tenor, index.value_date) - if surface_id is None: - for source in source_list: - if len(vs.list(source)) >=1: - break - else: - raise ValueError("No market data available for this day") - self._vs[k] = vs[vs.list(source)[-1]] - else: - self._vs[k] = vs[surface_id] - for swaption in self.swaptions: - ind = swaption.index - vol_surface = self._vs[(ind.value_date, ind.index_type, ind.series, ind.tenor)] - swaption.sigma = float(vol_surface.ev(swaption.T, swaption.moneyness)) + def mark(self, **kwargs): + for t in self.trades: + t.mark(**kwargs) @property def ref(self): |
