UnRisk 5 & Mathematica 8
Blazingly Fast and Insightful Risk Analytics

Michael Aichinger and Sascha Kratky

uni software plus GmbH
MathConsult GmbH

UnRisk Product Family

UnRisk-Q

Financial Instrument Types based on

Interest

Equity

FX

Credit

Inflation

Hybrids

Models

Generalized Hull & White (1 Factor Model & 2 Factor Model)

LIBOR

Black-Karasinski

Black-Scholes

Dupire

Heston

Exponential Levy

Optional Value-At-Risk module

Technology

C++ engine

Parallel Computation on CPU based on OpenMP and gridMathematica

Optional GPU support with CUDA (requires Tesla 2050 or better)

UnRisk-Q Example

Valuation: Fixed Rate Bond

Needs["UnRisk`UnRiskFrontEnd`"]

MyBondCaseA=MakeFixedRateBond[
0.04,
{2012,10,10},{2010,4,10},
CouponBasis->"BondBasis",
CouponFrequency->"Semi-Annual",
FaceAmount->1000]

Properties[MyBondCaseA]

MySwapCurve=MakeSwapCurve[
{2010,8,2},
{{1,0.05},{7,0.0502},{31,0.052},{92,0.0532},{183,0.055},{365,0.0572},{730,0.061},{1460,0.064}}]

MyYieldCurve=MakeYieldCurve[MySwapCurve]

ListLinePlot[Transpose[{"Terms","Rates"}/.Properties[MyYieldCurve]]]

MyVal1=Valuate[
MyBondCaseA,
{2010,8,2},{2010,8,7},
MyYieldCurve,
ReturnValues->{CleanValue,DirtyValue}]

UnRisk VaR Module

Different Risk Factors

(Subscript[r, i])==(Subscript[r, 0])+Δ(Subscript[r, i])

(Subscript[S, i])==(Subscript[S, 0])((Subscript[S, i+1])/(Subscript[S, i]))

F(Subscript[X, i])==F(Subscript[X, 0])((F(Subscript[X, i+1]))/(F(Subscript[X, i])))

(Subscript[c, i])==(Subscript[c, 0])+Δ(Subscript[c, i])

(Subscript[σ, c/(Subscript[s, i])])==(Subscript[σ, c/(Subscript[s, i])])((Subscript[σ, c/(Subscript[s, i+1])])/(Subscript[σ, c/(Subscript[s, i])]))

(Subscript[y, i])==(Subscript[y, 0])+Δ(Subscript[y, i])

(Subscript[I, i])==(Subscript[I, 0])((Subscript[I, i+1])/(Subscript[I, i]))

(Subscript[i, (Subscript[r, i])])==(Subscript[i, (Subscript[r, 0])])+Δ(Subscript[i, (Subscript[r, i])])

Built in VaR Types

Parametric VaR

Workflow

Define a set of risk factors β=={(Subscript[β, 1]),…,(Subscript[β, (Subscript[N, β])])}

Calculate the derivatives for each instrument in your portfolio (assume (Subscript[N, P]) instruments in your portfolio) with respect to each of the risk factors

(Subscript[d, l,i])==∂(Subscript[V, l])/∂(Subscript[β, i])

Therefore for each of the (Subscript[N, P]) instruments a 1×(Subscript[N, β]) matrix (Subscript[D, l]) is generated

(Subscript[D, l])==[(Subscript[d, l,1]),(Subscript[d, l,2]),…,(Subscript[d, l,(Subscript[N, β])])]

The matrix for the overall portfolio is

(Subscript[D, P])==(∑_(l==1)^(Subscript[N, P]))(Subscript[D, l])

Calculate the standard deviation of the changes for each risk factor and calculate the correlations between them using N+1 historical data points.

({{(Subscript[σ, (Subscript[β, i])]^2), ==, (1/(N-1))(∑_(k==1)^N)((((Subscript[Δβ, i,k])))^2)}, {(Subscript[ρ, (Subscript[β, i])(Subscript[β, j])]), ==, (1/(N-1))((((∑_(k==1)^N)(Subscript[Δβ, i,k])(Subscript[Δβ, j,k]))/((Subscript[σ, (Subscript[β, i])])(Subscript[σ, (Subscript[β, j])]))))}})

Build up the variance-covariance matrix

C==(({{ (Subscript[σ, (Subscript[β, 1])]^2) ,  (Subscript[ρ, (Subscript[β, 1])(Subscript[β, 2])])(Subscript[σ, (Subscript[β, 1])])(Subscript[σ, (Subscript[β, 2])]) ,  ⋯ ,  (Subscript[ρ, (Subscript[β, 1])(Subscript[β, (Subscript[N, β])])])(Subscript[σ, (Subscript[β, 1])])(Subscript[σ, (Subscript[β, (Subscript[N, β])])]) }, { (Subscript[ρ, (Subscript[β, 1])(Subscript[β, 2])])(Subscript[σ, (Subscript[β, 1])])(Subscript[σ, (Subscript[β, 2])]) ,  (Subscript[σ, (Subscript[β, 2])]^2) ,  ⋯ ,  (Subscript[ρ, (Subscript[β, 2])(Subscript[β, (Subscript[N, β])])])(Subscript[σ, (Subscript[β, 2])])(Subscript[σ, (Subscript[β, (Subscript[N, β])])]) }, { ⋮ ,  ⋮ ,  ⋯ ,  ⋮ }, { (Subscript[ρ, (Subscript[β, 1])(Subscript[β, (Subscript[N, β])])])(Subscript[σ, (Subscript[β, 1])])(Subscript[σ, (Subscript[β, (Subscript[N, β])])]) ,  (Subscript[ρ, (Subscript[β, 2])(Subscript[β, (Subscript[N, β])])])(Subscript[σ, (Subscript[β, 2])])(Subscript[σ, (Subscript[β, (Subscript[N, β])])]) ,  ⋯ ,  (Subscript[σ, (Subscript[β, (Subscript[N, β])])]^2) }}))

Calculate the VaR using

VaR==(Subscript[α, z])(Sqrt[(Subscript[D, P])C(Subscript[D, P]^T)])

where (Subscript[α, z]) is calculated using your desired percentile (for example for a 99%-VaR (Subscript[α, z])≈2.33)

Historical VaR

* Generate scenarios by adding historical scenario deltas to todays values
* Value your instruments under these scenarios
* Sort the results and use the one corresponding to your quantile

Monte Carlo VaR

Monte Carlo Value at Risk  Using MC VaR the problem of measuring risk can be devided into two main steps

*the modelling of the joint evolution of risk factor returns affecting portfolio profit and loss distribution during a specified holding period 

The use of a copula function allows us to overcome the issue of estimating the multivariate d.f. by splitting it into two parts:  
- determine the margins (marginal distributions) (Subscript[F, 1]),...,(Subscript[F, n]), which represent the distribution of each risk factor, and estimate their parameters, fitting the available data 
- determine the dependence structure of the random variables (Subscript[X, 1]),...,(Subscript[X, n]), specifying a meaningful copula function

*the modelling of the impact of changes in risk factor returns on the value of portfolio instruments using pricing models

Evaluation

Full Evaluation

PCA

UnRisk-Q VaR Example

Needs["UnRisk`UnRiskVaRModule`"]

<<UnRisk`VaRMarketData`

MyHistoricalEURYieldCurves

Historical VaR: Fixed Rate Bond

MyBond=MakeFixedRateBond[0.05,{2020,10,10},{2008,10,10},FaceAmount->100,Currency->"EUR"]

MyActualBondDirtyValue=Valuate[MyBond,{2010,9,22},{2010,9,27},MyActualEURYieldCurve,CreditSpread->MyActualCreditSpread,ReturnValues->{DirtyValue}]//First

DeltasMyBond=ParallelCalculateHistoricalDeltas[
MyBond,"Fixed Rate Bond EUR",{2010,9,22},{2010,9,27},MyActualEURYieldCurve,MyActualBondDirtyValue,
MakeTimeSeries[
	YieldCurves->MyHistoricalEURYieldCurves,
	CreditSpreads->MyHistoricalCreditSpreads],
MakeActualMarketDataSet[
	ActualYieldCurve->MyActualEURYieldCurve,
	ActualCreditSpread->MyActualCreditSpread],
MakeContributionDefinitionSet[YieldCurves->True,CreditSpreads->True],
VaRTimeHorizon->"1D"]

quantiles=Range[1,99];

MyBondIndividualVar=CalculateIndividualVaRs[quantiles,DeltasMyBond]

GetAllRiskFactorIndividualVaR[MyBondIndividualVar,99]

Needs["UnRisk`UnRiskVaRVisualization`"]

VaRBarChart[MyBondIndividualVar,All]

Historical VaR: Vanilla FX Option

MyUnderlyingFX=MakeFX[MyActualEURperUSDFXRate,"USD","EUR"];
MyVanillaFXOption=MakeVanillaFXOption[MyUnderlyingFX,0.8,{2012,10,10},
OptionType->"Call",ExerciseType->"European"]

MyVanillaFXOptionValue=Valuate[MyVanillaFXOption,{2010,9,22},{2010,9,27},0.1,MyActualEURYieldCurve,MyActualUSDYieldCurve,Method->"Analytic",ReturnValues->{Value}]//First

DeltasMyVanillaFXOption=ParallelCalculateHistoricalDeltas[
MyVanillaFXOption,"Vanilla FX Option USD",{2010,9,22},{2010,9,27},0.1,
MyVanillaFXOptionValue,
MakeTimeSeries[YieldCurves->MyHistoricalEURYieldCurves,ForeignYieldCurves->MyHistoricalUSDYieldCurves,FXRates->MyHistoricalEURperUSDFXRates],
MakeActualMarketDataSet[
	ActualYieldCurve->MyActualEURYieldCurve,
	ActualForeignYieldCurve->MyActualUSDYieldCurve,
	ActualFXRate->MyActualEURperUSDFXRate],
MakeContributionDefinitionSet[YieldCurves->True,FXRates->True],
VaRTimeHorizon->"1D"]

Historical VaR: Equity

MyEquity=MakeEquity[MyActualEquityPrice,Currency->"USD"]

DeltasMyEquity=CalculateHistoricalDeltas[
MyEquity,"Equity USD",{2010,9,22},{2010,9,27},0.1,
MyActualEquityPrice,
MakeTimeSeries[EquityPrices->MyHistoricalEquityPrices],
MakeActualMarketDataSet[ActualEquityPrice->MyActualEquityPrice],
MakeContributionDefinitionSet[EquityPrices->True],
VaRTimeHorizon->"1D"]

Historical VaR: Portfolio VaR

MyPortfolio={{1000,DeltasMyBond},{100000,DeltasMyVanillaFXOption},{200,DeltasMyEquity}};

MyPortfolioValue=
1000*MyActualBondDirtyValue+
100000*MyVanillaFXOptionValue+
200*MyActualEURperUSDFXRate*MyActualEquityPrice

quantiles=Range[1,99];

MyPortfolioVar=CalculatePortfolioVaRs[
quantiles,
MyPortfolio,"Portfolio EUR",
MyPortfolioValue,
{"USD"->MyActualEURperUSDFXRate},
MyPortfolioFXRateTimeSeries,
VaRTimeHorizon->"1D",Currency->"EUR"]

GetAllRiskFactorPortfolioVaR[MyPortfolioVar,99]

GetSingleRiskFactorPortfolioVaR[MyPortfolioVar,99,fxrates]

UnRisk-Q Contribution VaR

ContributionVaRManipulate[MyPortfolioVar]

UnRisk PRICING ENGINE Excel

UnRisk Excel Plug-In

Parallel Computation of Excel worksheets

No VaR module

UnRisk FACTORY

UnRisk FACTORY architecture

Questions