Calc Params

ultibi allows you to override parameters of the regulation, which in turn allows you to define your own parameter sets. For example if a regulatory set is not yet supported - just override parameters which are different in "calc_params" part of your request.

What you can override

Use .calc_params attribute to get the list of overridable parameters.

for calc_param in dataset.calc_params:
    print(calc_param["name"], " - ", calc_param["hint"])

Explanation

Most of these are self explanatory. However, one needs to understand what exactly some of those do:

  1. Some calc_params end with _base and some with _low/_medium/_high. Those which end with _base (eg. com_delta_rho_diff_loc_base) are components of an actual rho. For example com_delta_rho_diff_loc_base is (a float) and is part of three components which are multiplied to produce a commodity inner bucket rho as per 21.83.3. This has one important implication. Low/High function as per paragraph 21.6 in the text will be applied after this multiplication. On the other hand, those calc_params which end with _low/_medium/_high (eg girr_delta_gamma_low) will be used as they are.

  2. Those calc_params (eg com_delta_diff_cty_rho_per_bucket_base) which are lists are usually per bucket, where index of the item indicates the number of the bucket.

  3. jurisdiction - currently BCBS or CRR2 - points to which parameter set (rhos, gammas etc) to be used by default. Also for FX if reporting_ccy is not provided

  4. reporting_ccy - used for FX. Only those FX delta/curvature sensitivites where RiskFactor is XXXCCY (where CCY is the reporting_ccy) will be used for calculation. (eg if reporting_ccy is USD, GBPUSD will be used, but GBPEUR will not - this applies for Delta and Curvature calculations only).

  5. For gamma correlation matrixes the diagonal has to be 0.

  6. You have to be very careful with the way to provide a calc_param in your request, especially for vectors and matrixes. Use json.dumps for calc_params. Follow examples below. 'v' is always 1.

Examples

A request with calc_params looks like this. This is an arbitrary example just for illustrative purposes:

import ultibi as ul
import json

ds = ul.FRTBDataSet.from_config_path("./data/frtb/datasource_config.toml")

for calc_param in ds.calc_params:
    if "com_delta_" in calc_param[0]:
        # print(calc_param) #<-- uncomment to see
        pass
# fmt: off
com_delta_diff_cty_rho_per_bucket_base = json.dumps(
    [1.55, 1.95, 1.4, 1.8, 1.6, 1.65, 1.55, 1.45, 1.15, 1.4, 1.15]
)
com_delta_gamma_low = json.dumps(
    {
        "v": 1,
        "dim": [11, 11],
        "data": [
            0.0,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2,0.0,
            1.2,0.0,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2,0.0,
            1.2,1.2,0.0,1.2,1.2,1.2,1.2,1.2,1.2,1.2,0.0,
            1.2,1.2,1.2,0.0,1.2,1.2,1.2,1.2,1.2,1.2,0.0,
            1.2,1.2,1.2,1.2,0.0,1.2,1.2,1.2,1.2,1.2,0.0,
            1.2,1.2,1.2,1.2,1.2,0.0,1.2,1.2,1.2,1.2,0.0,
            1.2,1.2,1.2,1.2,1.2,1.2,0.0,1.2,1.2,1.2,0.0,
            1.2,1.2,1.2,1.2,1.2,1.2,1.2,0.0,1.2,1.2,0.0,
            1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2,0.0,1.2,0.0,
            1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2,0.0,0.0,
            0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
        ],
    }
)
# fmt: on
calc_params = dict(
    com_delta_diff_cty_rho_per_bucket_base=com_delta_diff_cty_rho_per_bucket_base,
    com_delta_gamma_low=com_delta_gamma_low,
)
print(calc_params)

request1 = dict(
    measures=[
        ["Commodity DeltaCharge Low", "scalar"],
        ["Commodity DeltaCharge Medium", "scalar"],
        ["Commodity DeltaCharge High", "scalar"],
    ],
    groupby=["Group"],
    hide_zeros=True,
    calc_params=calc_params,
)

result1 = ds.compute(request1)

# print(result1) #<-- uncomment to see

request2 = dict(
    measures=[
        ["Commodity DeltaCharge Low", "scalar"],
        ["Commodity DeltaCharge Medium", "scalar"],
        ["Commodity DeltaCharge High", "scalar"],
    ],
    groupby=["Group"],
    hide_zeros=True,
)

result2 = ds.compute(request2)

# print(result2) #<-- uncomment to see
print(result1)
print(result2)

If a parameters could not get parsed

Currently, if your passed calc_param could not get parsed into a correct value (eg you provided float instead of a vector) - it will silently fall back to the defaulted value of the jurisdiction. This will be changed in the next release to return an error to avoid ambiguity.