diff options
Diffstat (limited to 'python/analytics/portfolio.py')
| -rw-r--r-- | python/analytics/portfolio.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/python/analytics/portfolio.py b/python/analytics/portfolio.py index d8bc675f..583f5582 100644 --- a/python/analytics/portfolio.py +++ b/python/analytics/portfolio.py @@ -1,15 +1,21 @@ from .index import Index -from .option import BlackSwaption, BlackSwaptionVolSurface +from .option import BlackSwaption from warnings import warn import pandas as pd import numpy as np + def portf_repr(method): def f(*args): obj = args[0] - thousands = lambda x: "{:,.2f}".format(x) - percent = lambda x: "N/A" if np.isnan(x) else f"{100*x:.2f}%" - header = "Portfolio {}\n\n".format(obj.value_date) + thousands = "{:,.2f}".format + + def percent(x): + if np.isnan(x): + return "N/A" + else: + return f"{100*x:.2f}%" + header = f"Portfolio {obj.value_date}\n\n" kwargs = {'formatters': {'Notional': thousands, 'PV': thousands, 'Delta': percent, @@ -38,8 +44,7 @@ class Portfolio: 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 {}". - format(self._value_date)) + warn(f"not all instruments have the same trade date, picking {self._value_date}") def __iter__(self): for t in self.trades: |
