Class for setting up Riskfactor objects.
The mapping between e.g. curve or index objects and their corresponding risk factors
is automatically done by using regular expressions to match the names.
Riskfactors always have to begin with ’RF_’ followed by the object name.
If certain nodes of curves or surfaces are shocked, the name is followed by an additional node identifier,
e.g. ’RF_IR_EUR_SWAP_1Y’ for shocking an interest rate curve or ’RF_VOLA_IR_EUR_1825_3650’
for shocking a certain point on the volatility tenor / term surface.
Riskfactors can be either shocked during stresses, where custom absolute or relative shocks can be defined.
During Monte-Carlo scenario generation risk factor shocks are calculated by applying statistical processes
according to specified stochastic model. The random numbers follow a match of given
mean, standard deviation, skewness and kurtosis according to distributions selected by
the Pearson Type I-VII distribution system.
This class contains all attributes and methods related to the following Riskfactor types:
- RF_IR: Interest rate risk factor.
- RF_SPREAD: Spread risk factor.
- RF_COM: Commodity risk factor.
- RF_RE: Real estate risk factor.
- RF_EQ: Equity risk factor.
- RF_VOLA: Volatility risk factor.
- RF_ALT: Alternative investment risk factor.
- RF_INFL: Inflation risk factor.
- RF_FX: Forex risk factor.
In the following, all methods and attributes are explained and a code example is given.
Methods for Riskfactor object obj:
- Riskfactor(id) or Riskfactor(): Constructor of a Riskfactor object. id is optional and specifies id and name of new object.
- obj.set(attribute,value): Setter method. Provide pairs of attributes and values. Values are checked for format and constraints.
- obj.get(attribute): Getter method. Query the value of specified attribute.
- obj.getValue(scenario, abs_flag, sensitivity): Return Riskfactor value
according to scenario type. If optional parameter abs_flag is true returns Riskfactor scenario values.
Therefore static method Riskfactor.get_abs_values will be called.
- Riskfactor.help(format,returnflag): show this message. Format can be [plain text, html or texinfo].
If empty, defaults to plain text. Returnflag is boolean: True returns
documentation string, false (default) returns empty string. [static method]
- Riskfactor.get_abs_values(model, scen_deltavec, value_base, sensitivity): Calculate absolute
scenario value for given base value, sensitivity, model and shock. [static method]
- Riskfactor.get_basis(dcc_string): Return basis integer value for given day count convention string.
Attributes of Riskfactor objects:
- id: Riskfactor id. Has to be unique identifier. Default: empty string.
- name: Riskfactor name. Default: empty string.
- description: Riskfactor description. Default: empty string.
- type: Riskfactor type. Can be [RF_IR, RF_SPREAD, RF_COM, RF_RE, RF_EQ, RF_VOLA, RF_ALT, RF_INFL or RF_FX]
- model: Stochastic risk factor model. Can be [Geometric Brownian Motion (GBM), Brownian Motioan (BM),
Black-Karasinsky Model (BKM), Shifted LogNormal (SLN), Ornstein-Uhlenbeck (OU), Square-Root Diffusion (SRD)]. Default: empty string.
- mean: Annualized targeted marginal mean (drift) of risk factor. Default: 0.0
- std: Annualized targeted marginal standard deviation of risk factor. Default: 0.0
- skew: Targeted marginal skewness of risk factor. Default: 0.0
- kurt: Targeted marginal kurtosis of risk factor. Default: 0.0
- value_base: Base value of risk factor (required for mean reverting stochastic models). Default: 0.0
- mr_level: Mean reversion level. Default: 0.0
- mr_rate: Mean reversion parameter. Default: 0.0
- node: Risk factor term value in first dimension (in days). For curves equals term in days at x-axis (term). Default: 0.0
- node2: Risk factor term value in second dimension. For interest rate surfaces equals term in days at y-axis (tenor or term).
For index surfaces equals moneyness. Default: 0.0
- node3: Risk factor term value in third dimension. For volatility cubes equals moneyness at z-axis. Default: 0.0
- sln_level: Shift parameter (shift level) of shifted log-normal distribution. Default: 0.0
- scenario_mc: Vector with risk factor shock values.
MC rates for several MC timesteps are stored in layers.
- scenario_stress: Vector with risk factor shock values.
- timestep_mc: String Cell array with MC timesteps. Automatically appended if values for new timesteps are set.
- shocktype_mc: Specify how to apply risk factor shocks in Monte Carlo
scenarios. Can be [absolute, relative, sln_relative].
Automatically set by scripts. Default: absolute
- shift_type: Specify a vector specifying stress risk factor shift type .
Can be either 0 (absolute) or 1 (relative) shift.
For illustration see the following example:
A swap risk factor modelled by a shifted log-normal model at the three year node
is set up and shifted in three stress scenarios (absolute up- and downshift, relative downshift):
disp('Setting up Swap(3650) risk factor')
r = Riskfactor();
r = r.set('id','RF_EUR-SWAP_3Y','name','RF_EUR-SWAP_3Y', ...
'scenario_stress',[0.02;-0.01;0.8], ...
'type','RF_IR','model','SLN','shift_type',[0;0;1], ...
'mean',0.0,'std',0.117,'skew',0.0,'kurt',3, ...
'node',1095,'sln_level',0.03)