Scenario contexts enable the user to price and calculate risk under varying market states and pricing environments.
from gs_quant.instrument import IRSwaption
from gs_quant.risk import MarketDataPattern, MarketDataShock, MarketDataShockType, MarketDataShockBasedScenario, \
RollFwd, CurveScenario, IndexCurveShift
from gs_quant.session import Environment, GsSession
# external users should substitute their client id and secret; please skip this step if using internal jupyterhub
GsSession.use(Environment.PROD, client_id=None, client_secret=None, scopes=('run_analytics',))
# Create and price a swaption
swaption = IRSwaption('Pay', '5y', 'USD', expiration_date='3m')
base_price = swaption.price()
base_price
Allows the user to create a bespoke market data shock
MarketDataShockBasedScenario?
# Scenario Creation: Shock all points on the Vol Curve by 1bp
ir_vol_scenario = MarketDataShockBasedScenario(
shocks={
MarketDataPattern('IR Vol'): MarketDataShock(MarketDataShockType.Absolute, 1e-4)
}
)
# Price swaption under scenario
with ir_vol_scenario:
scenario_price = swaption.price()
scenario_price
# Swaption Price Comparison: Base vs. Shocked Vol Curves
diff = scenario_price - base_price
diff
# Comparing Parallel Bump Scenario w/ Vega
from gs_quant.risk import IRVegaParallel
vega = swaption.calc(IRVegaParallel)
vega
A predefined scenario used to modify the shape of the curve with bespoke transformations - by applying both parallel and slope shifts.
CurveScenario?
# Scenario Creation: modify the Vol Curve by a 5bp parallel shift, 1bp slope shift pivoted at 5y point (up to 50y)
curve_scenario = CurveScenario(market_data_pattern=MarketDataPattern('IR', 'USD'), parallel_shift=5,
curve_shift=1, pivot_point=5, tenor_end=50, tenor_start=0)
with curve_scenario:
swaption_scenario_price = swaption.price()
# Look at the difference between scenario and base prices
print('Base price: {:,.2f}'.format(base_price))
print('Scenario price: {:,.2f}'.format(swaption_scenario_price))
A predefined scenario used to evolve market data and trades over a period of time
RollFwd?
# RollFwd Scenario - Roll forward 1 month
base_price = swaption.price()
with RollFwd(date='1m', holiday_calendar='NYC', realise_fwd=False):
fwd_price = swaption.price()
print('Base price: {:,.2f}'.format(base_price))
print('Scenario price: {:,.2f}'.format(fwd_price))
print('Diff: {:,.2f}'.format(fwd_price - base_price))
A predefined scenario used to modify the shape of the index curve. This allows the user to easily shock the curve including parallel shift and slope shift. Users can even specify which part of the curve for parallel shift through custom bucket.
IndexCurveShift?
# Scenario Creation: modify the index curve of this swaption by a 1bp parallel shift, 1bp slope shift, pivoted default to 0 year with floor value -1bp (up to 50y)
index_curve_shift = IndexCurveShift(rate_option="USD-LIBOR-BBA", tenor="3m", annualised_parallel_shift=1,
annualised_slope_shift=1, floor=-1, cutoff=50)
with index_curve_shift:
swaption_scenario_price = swaption.price()
# Look at the difference between scenario and base prices
print('Base price: {:,.2f}'.format(base_price))
print('Scenario price: {:,.2f}'.format(swaption_scenario_price))