aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/analytics/portfolio.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/python/analytics/portfolio.py b/python/analytics/portfolio.py
index 66cdfe0c..ceef78c6 100644
--- a/python/analytics/portfolio.py
+++ b/python/analytics/portfolio.py
@@ -82,21 +82,21 @@ class Portfolio:
self.swaption.trade_date = d
self._trade_date = d
- def mark(self, source=None, option_type=None, model=None, surface_id=None):
- vs_dict = {}
+ def mark(self, source_list=[], option_type=None, model="black", surface_id=None):
for index, (index_type, series, tenor) in zip(self.indices, self._keys):
- run = serenitasdb.execute("""SELECT * FROM index_quotes
- WHERE index=%s AND series=%s AND tenor=%s AND date=%s""",
- (index_type, series, tenor, self.trade_date))
- rec = run.fetchone()
- index.spread = rec.closespread
- k = (self.trade_date, index_type, series, tenor)
+ index.mark()
+ 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, self.trade_date)
- if surface_id is None and len(vs.list(source, option_type, model)) >=1:
+ 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")
surface_id = vs.list(source, option_type, model)[-1]
- else:
- raise ValueError("No market data available for this day")
self._vs[k] = vs[surface_id]
for swaption in self.swaptions:
vol_surface = self._vs[(swaption.index.trade_date, ) + \
@@ -141,6 +141,10 @@ class Portfolio:
def dv01(self):
return sum(t.dv01 for t in self.trades)
+ @property
+ def theta(self):
+ return sum(t.theta for t in self.trades)
+
def _todf(self):
headers = ["Product", "Index", "Notional", "Ref", "Direction", "Expiry",
"Vol", "PV", "Delta", "Gamma", "Theta", "Vega"]