aboutsummaryrefslogtreecommitdiffstats
path: root/python/risk
diff options
context:
space:
mode:
Diffstat (limited to 'python/risk')
-rw-r--r--python/risk/portfolio.py25
1 files changed, 11 insertions, 14 deletions
diff --git a/python/risk/portfolio.py b/python/risk/portfolio.py
index ad3665d3..df9ef6ba 100644
--- a/python/risk/portfolio.py
+++ b/python/risk/portfolio.py
@@ -103,20 +103,19 @@ def build_portfolio(position_date, value_date=None, fund="SERCGMAST"):
return portf, syn_portf
-def generate_vol_surface(portf, try_days_back=5, source="MS"):
+def generate_vol_surface(portf, lookback=5, source="MS"):
vol_surface = {}
- unique = {
- (trade.index.index_type, trade.index.series, trade.option_type)
- for trade in portf.swaptions
- }
- for (
- index_type,
- series,
- option_type,
- ) in unique:
+ for trade in portf.swaptions:
+ index_type, series, option_type = (
+ trade.index.index_type,
+ trade.index.series,
+ trade.option_type,
+ )
+ if (k := (index_type, series, option_type)) in vol_surface:
+ continue
i = 0
- while i < try_days_back:
+ while i < lookback:
try:
vs = BlackSwaptionVolSurface(
index_type,
@@ -129,8 +128,6 @@ def generate_vol_surface(portf, try_days_back=5, source="MS"):
logger.info(f"Trying {portf.value_date - BDay(i)}")
else:
break
- vol_surface[(index_type, series, option_type)] = vs[
- vs.list(source=source, option_type=option_type)[-1]
- ]
+ vol_surface[k] = vs[vs.list(source=source, option_type=option_type)[-1]]
return vol_surface