aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/analytics/index.py2
-rw-r--r--python/analytics/option.py24
-rw-r--r--python/analytics/portfolio.py41
3 files changed, 33 insertions, 34 deletions
diff --git a/python/analytics/index.py b/python/analytics/index.py
index b06891f9..aa93b5ee 100644
--- a/python/analytics/index.py
+++ b/python/analytics/index.py
@@ -342,7 +342,7 @@ class Index(object):
def observe(self, obj):
self._observed.add(obj)
- def mark(self):
+ def mark(self, **args):
if self.value_date == datetime.date.today():
with init_bbg_session(BBG_IP) as session:
security = self.name + " Corp"
diff --git a/python/analytics/option.py b/python/analytics/option.py
index d76c1888..cf02cbeb 100644
--- a/python/analytics/option.py
+++ b/python/analytics/option.py
@@ -112,6 +112,30 @@ class BlackSwaption(ForwardIndex):
instance._original_pv = instance.pv
return instance
+ def mark(self, source_list=[], surface_id=None, **args):
+ ind = self.index
+ self.index.mark()
+ # add None so that we always try everything
+ source_list = source_list + [None]
+ k = ind.index_type, ind.series, ind.tenor, ind.value_date
+ vs = BlackSwaptionVolSurface(*k, **args)
+ if surface_id is None:
+ for source in source_list:
+ if len(vs.list(source, self.option_type)) >=1:
+ break
+ 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)))
+
+ @property
+ def value_date(self):
+ return self.index.value_date
+
+ @value_date.setter
+ def value_date(self, d):
+ self.index.value_date = d
+
@property
def exercise_date(self):
return self.forward_date
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):