diff options
Diffstat (limited to 'python/analytics/option.py')
| -rw-r--r-- | python/analytics/option.py | 64 |
1 files changed, 23 insertions, 41 deletions
diff --git a/python/analytics/option.py b/python/analytics/option.py index 08410ed3..c8079702 100644 --- a/python/analytics/option.py +++ b/python/analytics/option.py @@ -8,7 +8,7 @@ import pandas as pd from db import dbengine from .black import black -from .utils import GHquad +from .utils import GHquad, build_table from .index import g, ForwardIndex, Index, engine from yieldcurve import roll_yc from pandas.tseries.offsets import BDay @@ -300,46 +300,28 @@ class BlackSwaption(ForwardIndex): s = ["{:<20}{}".format(self.index.name, self.option_type), "", "{:<20}\t{:>15}".format("Trade Date", ('{:%m/%d/%y}'. - format(self.index.trade_date))), - "{:<20}\t{:>15.2f}\t\t{:<20}\t{:>10,.2f}".format("Ref Sprd (bp)", - self.index.spread, - "Coupon (bp)", - self.index.fixed_rate), - "{:<20}\t{:>15.3f}\t\t{:<20}\t{:>10}".format("Ref Price", - self.index.price, - "Maturity Date", - ('{:%m/%d/%y}'. - format(self.index.end_date))), - "", - "Swaption Calculator", - "", - "{:<20}\t{:>15,.0f}\t\t{:<19}\t{:>12,.2f}".format("Notional", - self.notional, - "Premium", - self.pv), - "{:<20}\t{:>15.2f}\t\t{:<20}\t{:>10}".format("Strike", - self.strike, - "Maturity Date", - ('{:%m/%d/%y}'. - format(self.exercise_date))), - "{:<20}\t{:>15.4f}\t\t{:<19}\t{:>12,.3f}".format("Spread Vol", - self.sigma, - "Spread DV01", - self.DV01), - "{:<19}\t{:>16.3f}%\t\t{:<19}\t{:>11.3f}%".format("Delta", - self.delta * 100, - "Gamma", - self.gamma * 100), - "{:<20}\t{:>15,.3f}\t\t{:<19}\t{:>12,.3f}".format("Vega", - self.vega, - "Theta", - self.theta), - "{:<20}\t{:>15.3f}\t\t{:<20}\t{:>10.0f}".format("Breakeven", - self.breakeven, - "Days to Exercise", - self.T*365), - "" - ] + format(self.index.trade_date)))] + rows = [["Ref Sprd (bp)", self.index.spread, "Coupon (bp)", self.index.fixed_rate], + ["Ref Price", self.index.price, "Maturity Date", self.index.end_date]] + format_strings = [[None, "{:.2f}", None, "{:,.2f}"], + [None, "{:.3f}", None, '{:%m/%d/%y}']] + s += build_table(rows, format_strings, "{:<20}\t{:>15}\t\t{:<20}\t{:>10}") + s += ["", + "Swaption Calculator", + ""] + rows = [["Notional", self.notional, "Premium", self.pv], + ["Strike", self.strike, "Maturity Date", self.exercise_date], + ["Spread Vol", self.sigma, "Spread DV01", self.DV01], + ["Delta", self.delta * 100, "Gamma", self.gamma * 100], + ["Vega", self.vega, "Theta", self.theta], + ["Breakeven", self.breakeven, "Days to Exercise", self.T*365]] + format_strings = [[None, '{:,.0f}', None, '{:,.2f}'], + [None, '{:.2f}', None, '{:%m/%d/%y}'], + [None, '{:.4f}', None, '{:,.3f}'], + [None, '{:.3f}%', None, '{:.3f}%'], + [None, '{:,.3f}', None, '{:,.3f}'], + [None, '{:.3f}', None, '{:.0f}']] + s += build_table(rows, format_strings, "{:<20}{:>19}\t\t{:<19}{:>16}") return "\n".join(s) def __str__(self): |
