diff options
Diffstat (limited to 'python/analytics')
| -rw-r--r-- | python/analytics/index_data.py | 3 | ||||
| -rw-r--r-- | python/analytics/portfolio.py | 18 |
2 files changed, 10 insertions, 11 deletions
diff --git a/python/analytics/index_data.py b/python/analytics/index_data.py index 439f80fc..48aa9331 100644 --- a/python/analytics/index_data.py +++ b/python/analytics/index_data.py @@ -120,7 +120,8 @@ def index_returns(df=None, index=None, series=None, tenor=None, from_date=None, pct_change(periods=per)) df.columns = ['spread_return', 'price_return'] df = df.groupby(level=['date', 'index', 'series', 'tenor']).nth(0) - coupon_data = pd.read_sql_query("SELECT index, series, tenor, coupon * 1e-4 AS coupon, maturity FROM " + coupon_data = pd.read_sql_query("SELECT index, series, tenor, coupon * 1e-4 AS coupon, " + "maturity FROM " "index_maturity WHERE coupon is NOT NULL", _engine, index_col=['index', 'series', 'tenor']) diff --git a/python/analytics/portfolio.py b/python/analytics/portfolio.py index 2c83b8f0..809b49a2 100644 --- a/python/analytics/portfolio.py +++ b/python/analytics/portfolio.py @@ -1,12 +1,9 @@ from .index import Index from .option import BlackSwaption, BlackSwaptionVolSurface -from db import dbengine from warnings import warn import pandas as pd import numpy as np -serenitasdb = dbengine('serenitasdb') - def portf_repr(method): def f(*args): obj = args[0] @@ -28,6 +25,7 @@ def portf_repr(method): return header + s return f + class Portfolio: def __init__(self, trades): self.trades = trades @@ -78,7 +76,7 @@ class Portfolio: 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 + # 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() @@ -114,8 +112,8 @@ class Portfolio: if len(self.indices) == 1: self.indices[0].ref = val elif len(self.indices) == 0: - ##no index, so set the individual refs - for t in trades: + # no index, so set the individual refs + for t in self.swaptions: t.index.ref = val elif len(self.indices) == len(val): for index, val in zip(self.indices, val): @@ -135,8 +133,8 @@ class Portfolio: if len(self.indices) == 1: self.indices[0].spread = val elif len(self.indices) == 0: - ##no index, so set the individual refs - for t in trades: + # no index, so set the individual refs + for t in self.swaptions: t.index.spread = val elif len(self.indices) == len(val): for index, val in zip(self.indices, val): @@ -164,8 +162,8 @@ class Portfolio: return sum(t.theta for t in self.trades) def _todf(self): - headers = ["Product", "Index", "Notional", "Ref", "Strike", "Direction", "Expiry", - "Vol", "PV", "Delta", "Gamma", "Theta", "Vega"] + headers = ["Product", "Index", "Notional", "Ref", "Strike", "Direction", + "Expiry", "Vol", "PV", "Delta", "Gamma", "Theta", "Vega"] rec = [] for t in self.trades: if isinstance(t, Index): |
