Skip to main content
Skip table of contents

Examples of the functions for VaR

The object is only provided by a CalculationObject in the list of risk factors. The runtime in days (year=360 days) always refers to the evaluation date that was transferred to a CalculationObject in the context.

The entry point is always a risk model, currently always the DeltaNormalValueAtRiskModel and a list of ValueAtRiskPositions.

While DeltaNormalValueAtRiskModel does not expect any parameters, ValueAtRiskPosition requires three parameters: Security or account, position (for account 1), balance (currently any, e.g. 0).

From these two objects together with an evaluation date and an evaluation currency, a calculation object is obtained with CalculationObject.

Beispiel A

$Pos:= securities account valuation[$evaluation date.default[today]; $currency].transactions.append[account.tolist];

{auxiliary function}

$VarPos:=#[](if(is["transaction"];ValueAtRiskPosition(wp;as["transaction"].bestand;1);ValueAtRiskPosition(object;1;1))));

{Compile risk positions}

$rps:=map(#[]($VarPos.apply[object]);$pos).concatenate.concatenate;

{Get costing object}

$CalcObj:=DeltaNormalValueAtRiskModel.CalculationObject[$Auswertungsdatum.Default[heute];$Währung;$rps;$Zeitreihenanalysezeitraum];

With the functions ValueAtRisk, ValueAtRiskWithoutCurrencyRisk and ValueAtRiskCurrencyRisk the risk can now be calculated. (Return is an object of the type "ValueAtRisk", note the same name of the function and the object!)

The functions always expect a time period and a confidence interval (between 0 and 1).

If no other parameters are specified, the risk is calculated for the entire risk position-induced portfolio transferred to the calculation object.

The ValueAtRisk objectnow returns the following via ExposureInValuationCurrency or RiskInValuationCurrency the exposure (simplified: the risky value) or the risk.


Beispiel B

{Calculate different risk decompositions for the overall level}

$TotalVar:=$CalcObj.ValueAtRisk[$ForecastPeriod;$Confidence;_;_];.RiskInEvaluationCurrency[] ;

In the context of risk decomposition, however, it is not only the risk with regard to the overall portfolio and all risk factors that is of interest, but also the restriction to certain risk factors or subsets of instruments (and possibly sub-portfolios).

Therefore, the third parameter can be used to pass a list(!) of risk factors to which the calculation is restricted.

The function RiskFactors function provides a list of all identified risk factors on the costing objects.

Beispiel C

$TotalVarInterest:=$CalcObj.ValueAtRiskWithoutCurrencyRisk[$forecastperiod;$confidence;$calcobj.riskfactors.deleteifnot[#[](is["DiscountFactor"])]].RiskInEvaluationCurrency[];

$TotalVarInterestShort:=$CalcObj.ValueAtRiskWithoutCurrencyRisk[$forecastperiod;$confidence;$calcobj.riskfactors.deleteifnot[#[](is[&quot;DiscountFactor&quot;] and term<=$short-term_to)]].RiskInEvaluationCurrency[] ;

$TotalVarInterestAverage:=$CalcObj.ValueAtRiskWithoutCurrencyRisk[$forecastperiod;$confidence;$calcobj.riskfactors.deleteifnot[#[](is[&quot;DiscountFactor&quot;] and term> $short-term_to and term<=$medium-term_to)]].RiskInEvaluationCurrency[] ;

$TotalVarInterestLong:=$CalcObj.ValueAtRiskWithoutCurrencyRisk[$forecastperiod;$confidence;$calcobj.riskfactors.deleteifnot[#[](is["DiscountFactor"] and term>$medium-term_to)]].RiskInEvaluationCurrency[] ;

It should be noted that, due to their nature, currency risks are treated separately (i.e. currencies are not included in the risk factors in the sense discussed here).

ValueAtRisk provides the overall risk including currency risk, possibly limited to the subsets of risk factors and instruments.

ValueAtRiskWithoutCurrencyRisk provides the risk excluding currency risk, possibly restricted to the subsets of risk factors and instruments.

ValueAtRiskCurrencyRisk now provides the currency risk, possibly restricted to the subsets of risk factors and instruments, for a list of currencies that are defined as the 5th currency. Parameter is passed.

Beispiel D

$TotalCurrencyEURVar:=$CalcObj.ValueAtRiskCurrencyRisk[$forecastperiod;$confidence;_;_;$Calcobj.currencies.deleteifnot[#[](abbreviation="EUR")]].RiskInEvaluationCurrency[] ;

$TotalCurrencyCHFVar:=$CalcObj.ValueAtRiskCurrencyRisk[$forecastperiod;$confidence;_;_;$Calcobj.currencies.deleteifnot[#[](abbreviation="CHF")]].RiskInEvaluationCurrency[] ;

$TotalCurrencyUSDVar:=$CalcObj.ValueAtRiskCurrencyRisk[$forecastperiod;$confidence;_;_;$Calcobj.currencies.deleteifnot[#[](abbreviation="USD")]].RiskInEvaluationCurrency[] ;

$TotalCurrencyRestVar:=$CalcObj.ValueAtRiskCurrencyRisk[$forecastperiod;$confidence;_;_;$Calcobj.currencies.deleteif[#[]
(abbreviation="USD" or abbreviation="EUR" or abbreviation="CHF")]]
.RiskInEvaluationCurrency[] ;

In addition to the restriction to a set of risk factors, the restriction to instruments or instruments and changed portfolios is also interesting.

The 4. Parameter , a list of risk positions (see creation of the calculation object above) or a list containing securities and/or accounts can be transferred, to which a restriction is then applied.

This makes it possible to carry out the complex and time-consuming bootstrapping calculations only once for a securities account, a holder or a group and to calculate partial risks efficiently. This requires the excessive use of MM-Talk list functions.


Beispiel E

(cf. Asset class analysis report)

{Calculation of market value}

$KW:=#[](If(Is["Transaction"];

(as["Transaction"].TA_PriceValueSale+as["Transaction"].TA_UnitInterest + as["Transaction"].TA_InterimGain)*as["Transaction"].TA_ExchangeRateSale;

If(Is["specialasset"];

(as["specialasset"].TA_KurswertVerkauf + as["specialasset"].TA_Stückzinsen) * as["specialasset"].TA_WechselkursVerkauf;

(Balance[$EvaluationDate.Default[today]] * Currency.exchange.rate[$currency; $evaluation.date.default[today]]))));

$Consolidation level:=$Consolidation level.Default["Classes"];

{class grouping filter}

$PartAK:=#[](If(Is["Transaction"];
WP.UserField["Assetclass"];
If(Is["specialasset"];
"Plus "+Type;
"Liquidity")));

$w:= if(Currency.abbreviation="USD"; "USD";
if(Currency.abbreviation="EUR"; "EUR";
if(Currency.abbreviation="JPY"; "JPY";
if(Currency.abbreviation="GBP"; "GBP";
if(Currency.Abbreviation="CHF"; "CHF";
if(Currency.Abbreviation="CAD"; "CAD";
if(Currency.Abbreviation="HKD"; "HKD";
"Other currencies")))))));
{define UserField["Currency class"] accordingly}

$PartWK:=#[](If(Is["Transaction"];
WP.UserField["Currency class"];
If(Is["specialasset"];
$w;
UserField["Currency class"])));

$PartSK:=#[](If(Is["Transaction"];
WP.UserField["Segment"];
If(Is["specialasset"];
"Additional "+Type;
"Additional "+Type; "Additional "+Type. Liquidity")));

$PartBK:=#[](If(Is["Transaction"];
WP.UserField["Region"];
If(Is["specialasset"];
"Additional "+Type;
"Additional "+Type; "Additional "+Type. Liquidity")));

{auxiliary function}

$VarPos:=#[](if(is["transaction"];ValueAtRiskPosition(wp;as["transaction"].bestand;1);ValueAtRiskPosition(object;1;1))));

{Select the class grouping}

$PartKlas:=if($Klasse="Asset classes";$PartAk;if($Klasse="Segments";$PartSK;if($Klasse="Currencies";$PartWK;$PartBK)));

{depot grouping}

$PartDep:=#[](if(is["transaction"];depot.name;if(is["account"]; "accounts";"")));

{holder grouping}

$PartInh:=#[](Owner.Name) ;

{securities grouping}

$PartValue:=#[](if(is["transaction"];wp.name;name)) ;

$Part:=if($ConsolidationLevel="Holder";$PartInh;if($ConsolidationLevel="Deposits";$PartDep;if($ConsolidationLevel="Classes";$PartClass;$PartValue))) ;

$igroups:=$pos.groupby[_;$GroupingAfterDepot];

map(#[](
{Grouping by depot}
$kg:=object;
$depot:=$GroupingByDepot.apply[$kg.tolist.nth[0]] ;
$kgroups:=$kg.groupby[_;$Part] ;

$kg2:=map(#[]($VarPos.apply[object]);$kg.deleteifnot[#[](is["transaction"])].append[$kg.deleteif[#[](is["transaction"])]]);
$Vari:=$calcobj.ValueAtRisk[$periods;$confidence;_;$kg2];

map(#[](
{calculations for the class}
$il:=object;
$il2:=map(#[]($VarPos.apply[object]);$il.deleteifnot[#[](is["transaction"])].append[$il.deleteif[#[](is["transaction"])]]);
$Vark:=$calcobj.ValueAtRisk[$periods;$confidence;_;$il2];
$gr:=$Part.apply[$il.tolist.nth [0]];

map(#[](
{calculations for the position}
$P:=if(is["transaction"] or is["account"];true;false);
$D:=if(is["transaction"];wp;if(is["account"];object;0));
$filter:=if($P;$calcobj.Instruments.deleteifnot[#[](id=$D.id)]; 0.MakeList);
$varo:=$calcobj.ValueAtRisk[$Periods;$Confidence;_;$Filter];

{Compilation of the results}

makeCollection
{instrument level}
.add["instr";object]
.add["instrrisk";if($P;$Varo.riskinvaluationcurrency;0) ]
.add["instrexp";if($P;$Varo.exposureinvaluationcurrency;0) ]
.add["market value";$KW.apply[object]]

{holder grouping}
.add["Depot";$depot]
.add["DepotVar";$vari.RisikoInAuswertungswährung[]]
{class grouping (asset class, currency class, sector..)}
.add["Grouping";$gr]
.add["GroupVar";$vark.RiskInEvaluationCurrency[]]
.add["GroupExp";$vark.ExposureInEvaluationCurrency[]]

{total}
.add["totalxp";$Vark.ExposureEvaluationCurrency]
.add["totalvarow";$totalcurrencyvar]
.add["totalvarw";$totalcurrencyvar]
.add["totalvarrestw";$totalcurrencyrestvar]
.add["totalvareurw";$totalcurrencyurvar]
.add["totalvarusdw";$totalcurrencyusdvar]
.add["totalvar";$totalVaR]
.add["totalvarinterest";$totalVaRinterest]
.add["TotalVarEquity";$TotalVaREquity]
.add["TotalVarInterestShort";$TotalVaRInterestShort]
.add["TotalVarInterestLong";$TotalVaRInterestLong]
);$il)

);$kgroups)

);$Igroups)

.concatenate.concatenate

$klgroups:=$pos.groupby[_;$Part];

map(#[](
{calculations for the class}
$il:=object;
$VermClass:=map(#[]($KW.apply[$il.nth[object]]);$il.length.makelist);
$il2:=map(#[]($VarPos.apply[object]);$il).concatenate;
$gr:=$Part.apply[$il.tolist.nth [0]].tolist.nth[0];
$KlaGesamtVar:=$calcobj.ValueAtRisk[$Prognosezeitraum;$Konfidenz;_;$il2];
$KlaGesamtVarEigenkap:=$CalcObj.ValueAtRiskWithoutCurrencyRisk[$forecastperiod;$confidence;$calcobj.riskfactors.deleteifnot[#[](is["Wp"])];$il2].RiskInEvaluationCurrency[];
$ClaimTotalCurrencyInterest:=$CalcObj.ValueAtRiskWithoutCurrencyRisk[$forecastperiod;$confidence;$calcobj.riskfactors.deleteifnot[#[](is["DiscountFactor"])];$il2].RiskInEvaluationCurrency[];
$KlaGesamtVarZinsenKurz:=$CalcObj.ValueAtRiskWithoutCurrencyRisk[$forecastperiod;$confidence;$calcobj.riskfactors.deleteifnot[#[](is["DiscountFactor"] and term<=$short-term_to)];$il2].RiskInEvaluationCurrency[];
$KlaGesamtVarZinsmittel:=$CalcObj.ValueAtRiskOhneWährungsrisiko[$Prognosezeitraum;$Konfidenz;$calcobj.risikofaktoren.deleteifnot[#[](is["DiscountFactor"] and term>$short-term_to and term<=$medium-term_to)];$il2]
.RiskInEvaluationCurrency[];
$ClaimTotalVarInterestLong:=$CalcObj.ValueAtRiskWithoutCurrencyRisk[$forecastperiod;$confidence;$calcobj.riskfactors.deleteifnot[#[](is["DiscountFactor"] and term>$medium-term_to)];$il2].RiskInEvaluationCurrency[];
$ClaimTotalCurrencyVar:=$CalcObj.ValueAtRiskCurrencyRisk[$forecastperiod;$confidence;_;$il2].RiskInEvaluationCurrency[];
$ClaimTotalCurrencyEURVar:=$CalcObj.ValueAtRiskCurrencyRisk[$forecastperiod;$confidence;_;$il2;$Calcobj.currencies.deleteifnot[#[](abbreviation="EUR")]].RiskInEvaluationCurrency[];
$ClaimTotalCurrencyCHFVar:=$CalcObj.ValueAtRiskCurrencyRisk[$forecastperiod;$confidence;_;$il2;$Calcobj.currencies.deleteifnot[#[](abbreviation="CHF")]].RiskInEvaluationCurrency[];
$ClaimTotalCurrencyUSDVar:=$CalcObj.ValueAtRiskCurrencyRisk[$forecastperiod;$confidence;_;$il2;$Calcobj.currencies.deleteifnot[#[](abbreviation="USD")]].RiskEvaluationCurrency[];
$ClaimTotalCurrencyRemainingVar:=$CalcObj.ValueAtRiskCurrencyRisk[$forecastperiod;$confidence;_;$il2;$Calcobj.currencies.deleteif[#[](abbreviation="USD" or abbreviation="CHF" or abbreviation="EUR")]]
.RiskInEvaluationCurrency[];
$KlaGesamtOhneWährungVar:=$CalcObj.ValueAtRiskOhneWährungsrisiko[$Prognosezeitraum;$Konfidenz;_;$il2].RiskInEvaluationCurrency[];

{Compilation of the results}

_.makeCollection
{class level}
.add["Grouping";$gr]
.add["TotalClaimvarow";$ClaimTotalCurrencyvar]
.add["TotalClaimvarw";$ClaimTotalCurrencyvar]
.add["Klagesamtvarrestw";$Klaagesamtwährungrestvar]
.add["Klagesamtvareurw";$Klaagesamtwährungeurvar]
.add["Klagesamtvarchfw";$Klaagesamtwährungchfvar]
.add["TotalClaimsVarusdw";$TotalClaimsCurrencyusdvar]
.add["TotalClaimsVar";$TotalClaimsVaR]
.add["TotalClaimsVarInterest";$TotalClaimsVaRInterest]
.add["TotalClaimsVarEigencap";$TotalClaimsVaREigencap]
.add["KlaGesamtVarZinsenKurz";$KlaGesamtVaRZinsenKurz]
.add["KlaGesamtVarZinsenMittel";$KlaGesamtVaRZinsenMittel]
.add["KlaGesamtVarZinsenLang";$KlaGesamtVaRZinsenLang]

{Total}

.add["totalvarow";$totalcurrencyvar]
.add["totalvarw";$totalcurrencyvar]
.add["totalvarrestw";$totalcurrencyrestvar]
.add["totalvareurw";$totalcurrencyurvar]
.add["totalvarchfw";$totalcurrencychfvar]
.add["totalvarusdw";$totalcurrencyusdvar]
.add["TotalVar";$totalVar]
.add["TotalVarInterest";$totalVaRInterest]
.add["TotalVarEigenkap";$totalVaREigenkap]
.add["TotalCashInterestShort";$TotalVaRInterestShort]
.add["TotalCashInterestMean";$TotalVaRInterestMean]
.add["TotalCashInterestLong";$TotalVaRInterestLong]

);$klgroups)

.concatenate

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.