diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/analytics/scenarios.py | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/python/analytics/scenarios.py b/python/analytics/scenarios.py index 6ce10899..f1763100 100644 --- a/python/analytics/scenarios.py +++ b/python/analytics/scenarios.py @@ -3,8 +3,8 @@ from joblib import delayed, Parallel import pandas as pd from copy import deepcopy -def run_swaption_scenarios(swaption_copy, date_range, spread_shock, vol_shock, vol_surface, - params=["pv"]): +def run_swaption_scenarios(swaption, date_range, spread_shock, vol_shock, + vol_surface, params=["pv"]): """computes the pv of a swaption for a range of scenarios Parameters @@ -15,32 +15,20 @@ def run_swaption_scenarios(swaption_copy, date_range, spread_shock, vol_shock, v vol_shock : `np.array` vol_surface params : list of strings - list attributes to call on the swaption object. + list of attributes to call on the swaption object. """ r = [] - swaption = deepcopy(swaption_copy) - spread_start = swaption.index.spread + swaption = deepcopy(swaption) + spread = swaption.ref * (1 + spread_shock) for date in date_range: swaption.index.trade_date = date.date() T = swaption.T - for ss in spread_shock: - spread = spread_start * (1 + ss) - swaption.index.ref = spread - swaption._update() - atm_strike = ATMstrike(swaption.index, swaption.exercise_date) - moneyness = (swaption.strike / atm_strike) - curr_vol = float(vol_surface(T, moneyness)) - def aux(swaption, vol, params, prepend): - swaption.sigma = vol - import pdb; pdb.set_trace() - return prepend + [getattr(swaption, p) for p in params] + for s in spread: + swaption.ref = s + curr_vol = float(vol_surface(T, swaption.moneyness)) for vs in vol_shock: - r.append(aux(swaption, curr_vol * (1 + vs), params, [date, spread, vs])) - #r.append(Parallel(1)( - # delayed(aux(swaption, curr_vol * (1 + vs), params, [date, spread, vs])) \ - # for vs in vol_shock)) - - df = pd.DataFrame.from_records(r, columns=['date', 'spread_shock', - 'vol_shock'] + params) + swaption.sigma = curr_vol * (1 + vs) + r.append([date, s, vs] + [getattr(swaption, p) for p in params]) + df = pd.DataFrame.from_records(r, columns=['date', 'spread_shock', 'vol_shock'] + params) return df.set_index('date') |
