The document discusses using R for actuarial work, specifically VAR and interest rate models. It summarizes:
1) Developing a VAR model to estimate macroeconomic stress testing using time series models like VAR and GVAR. The model is implemented in R to estimate impacts over time from economic shocks.
2) Estimating yield curves using the Nelson-Siegel model in R. Spot rates and yield curves are estimated from interest rate data.
3) Using principal component analysis (PCA) in R to decompose interest rate changes into common components to explain variances with fewer factors, like parallel, twist, and butterfly shifts.
4) Comparing interest rate risk measures for different products using PCA
1. FY2012 Annual Meeting of the Institute of Actuaries of Japan
Use of R in Actuarial Work
VAR Model
Interest Rate
November 6, 2012
R Subcommittee, ASTIN Related Study Group
Motoharu Dei, Milliman, Inc.
2. Table of Contents
VAR model
Development of VAR model for stress testing of macro
economy
Interest rate
Interest rate model
PCA of interest rate changes
Vasicek model
1
4. VAR Model
Flow of Stress Test of Macro Economy
•
Start of stress testing
Typical flow of the stress test of (recognize needs, define
purpose)
•Study the past events
macro economy is shown. •Opinion of professionals
•Subjective view of management
• Flexibility and rationality are
1. Trigger event
(shock on an economic
index) •Estimation using macro
retained by splitting trigger event economy model (VAR model,
etc.)
and spreading effect model. 2. Sequential event
•
(impact on other economic
Economic model is converted to
indices) •Projection using linear
regression model, etc.
a risk factor to cope with risk 3. Change in risk factors
characteristics of the own
(impact on detailed indices, which
impact on value of a company) •Sensitivity of corporate value
company. to a risk factor ×Width of
change in a risk factor
• Time-series model is used to
4. Fluctuation of value of a
company
•Analysis of results
allow estimating amount of loss •Consideration of
countermeasures
and its timing of occurrence Managerial decision •Development of a report
simultaneously.
3
5. VAR Model
VAR(Vector AutoRegression) model and impulse response function 1/2
• Definition of VAR model
X t C A1 X t 1 A2 X t 2 Ap X t p t
Macro index at time t
Impact from Noise
(Equity index, GDP, foreign
past X
exchange rate, etc.)
• Definition of impulse response function (= function
showing reminder of the shock)
Impact of shock Δ Expected value of index after n Expected value of index after
after n periods periods with the shock n periods without the shock
I n, , t 1 : E X t n t , t 1 E X t n t 1
Bn B is coefficient matrix when inversely
presenting VAR model to VMA model
4
6. VARモデル
VAR(Vector AutoRegression) model and impulse response function 2/2
• Orthogonal impulse response function
I O n Bn Pe j
j
The jth factor of orthogonal impulse
response function
• Generalized impulse response function
I n
1
G
j jj
2
Bn e j
The jth factor of generalized impulse
response function
5
7. VAR Model
GVAR(Global Vector AutoRegression) model
• VARX(VAR with eXogenous variables) model
(Model by region with exogenous variable (Y: X with
weighted average of region other than i)
X ti C i A1i X ti1 A2 X ti2 Aip X ti p G0Yt k G1iYt 1 GqYt q t
i i k i k
Index at time t Impact of itself in the past External impact Noise
(endogenous variable) (exogenous variable)
• GVAR model (VAR model consolidating VARX model)
X t1 0 G0 X t1 A1
1 1
0 X t11 A21
0 X t1 2 1
2 2 2 2 2 2 t
X G
t 0 0 X t 0
A1 X t 1 0
2
A2 X t 2 t
2
(Case with number of locations: i=1,2, lag of endogenous variable: p=2,
lag of exogenous variable: q=0)
6
8. VAR model
Implementation using R – Condition for Implementation
• Model applied
• Both VAR and GVAR are modeled.
• Lags assumed are 2 for endogenous and 0 for exogenous.
• Region and indices applied
• Region: Japan, US, Europe
• Index: Equity price (NKY225, S&P500, FTSE100),
Interest rate (10-year LIBOR swap)
• Data source
• Monthly data for the period of 10 years (with 120 data
points) between March 2002 and February 2012 of
Bloomberg and MSN Finance is logged and used.
7
9. VAR Model
Past Data Used
【Equity Price Index】 【10-year LIBOR Swap Rate】
20,000 7.000
18,000
6.000
16,000
14,000 5.000
NKY225 JPY
12,000 4.000
10,000 SP500 USD
8,000 FTSE100 3.000 EUR
6,000 2.000
4,000
1.000
2,000
0 0.000
8
10. VAR Model
Output of Results ①
• Package used #Specify VAR package
library(vars)
• “vars”: A package #Obtain data
economic_data <- read.csv("data.csv")
corresponding to VAR model
• Coding with R
#Calibrate VAR model (lag is up to 2 periods)
lag<-2
•
result_var <-
VAR(economic_data,p=lag,type="both",season=NULL,exogen=NULL)
Reading data
• Calibration using function
#Calculate orthogonalized impulse response function (output for the
coming 48 periods)
project_term <- 48
“VAR” result_var_irf <-
irf(result_var,impulse=NULL,response=NULL,n.ahead=project_term,orth
• Calculation of impulse o=TRUE,cumulative=FALSE,boot=FALSE,ci=0.95,runs=1000,seed=1)
#Output VAR coefficient
response function using result_var_Bcoef<-Bcoef(result_var)
write.table(result_var_Bcoef,file="var_Bcoef.csv",sep=",",row.names=F
function “irf” and others ALSE)
• Pasting on Excel sheet upon #Output orthogonalized impulse response function
write.table(result_var_irf$irf,file="var_irf.csv",sep=",",row.names=FALS
outputting future estimation, E)
impulse response function, etc.
9
11. VAR Model
Output of Results ②
• Set up Excel so that desired results can be output
under the following controllable portion.
Macro Economic Stress Test
○Selection of IRF
2 1:orthogonalized IRF 2:generalized IRF
○Amount of impact
Equity (variance % from current) Interest Rate (Absolute value of impact in %)
JPY US EU JPY US EU
-30% 0% 0% 0.00 0.00 0.00
○Results to output
1 1:JPY 2:US 3:EU
• Sample result using the above setup
【Equity Price Index】 【10-year LIBOR Swap Rate (Japan)】
10
13. Interest Rate Model
• Change in the external environment (convergence to
the international accounting standards)
⇒Market value of liabilities (insurance & annuity)
• Estimate of yield curve using Nelson-Siegel model
• Measure of the interest rate risks
Risk measure by PCA and measurement of interest rate risks in line with
product characteristics
Risk measure using Vasicek Mode
12
14. Interest Rate Model
Estimation of Yield Curve
Develop interest rate data based on
1. Time-series interest rate data the information on public & corporate
bonds of Ministry of Finance, Japan
Securities Dealers Association, etc.
Interpolation of spline function and others,
2. Estimation of spot rate Estimate of spot rate from final yield
Selection of model for yield curve
3. Selection of model Spline polynomial
Nelson-Siegel model
Estimate each of the model parameters
4. Estimation of parameter (yield curve) using spot rate values
13
15. Interest Rate Model
Estimation of Yield Curve
Estimation of spot rate
Obtaining interest rate data redemption/zero yield(2011.12.30)
2.5
2
Maximum term available for
1.5
measure (spline interpolation)
利
Rate
率1
actual data
観測値
0.5
Estimation of spot rate from final zero yield
redemption yield
yield 0
n n 0 5 10 15 20 25 30
C R C R
(1 r (s)) s (1 r (n))n
S 0
S 0 (1 rr )
s
(1 rr ) n
年限
Term
z z
Data: Excerpt fro MOF HP (JGB interest rate information)
C:coupon R:redemption payment rz:spot rate rr:redemption yield
16. Interest Rate Model
Estimation of an Yield Curve
Estimation of yield curve ##Read interest rate data, set up term
Data <- read.table("data/kinri_2.csv",header=T,sep=",")
Term <- c(1:10,15,20,30)
Selection of model -------------------------------------------------
<Interpolate by spline function using R function
“smooth.spline” in package “stats” >
Model using basis function (f(t))
#spline interpolation
t 1 a j f j t t:Discountfactor
for (i in 1:nrow(Data)){
sp <- smooth.spline(Term ,as.vector(Data[i,2:ncol(Data)]))
Spline polynomial model round(predict(sp, seq(0.5,30, length=60))[[2]],10) }
B-Spline model -------------------------------------------------
Bernstein polynomial model <Estimate parameters in Nelson-Siegel using R function
“estim_nss” in package “termstrc” >
Yield curve model
##Set data in datazeroyields
Nelson-Siegel model datazeroyields <- zeroyields(Term, yield, dates)
r m 0 1 2 1 e m m / e
2
m ##Estimation of parameters for Nelson-Siegel, Svensson model
ns_res <- estim_nss(datazeroyields,method = "ns",
r m : spot rate tauconstr = c(0.2, 6, 0.1))
asv_res <- estim_nss(datazeroyields,method = "asv",
tauconstr = c(0.2, 7, 0.1))
Estimation of parameter (yield curve)
17. Interest Rate Model
Estimation of an Yield Curve
Parameters in Nelson-Siege model estimate zero yield (2011.12.30)
2.5
2
1.5
利
Rate
率 1
0.5
zero yield
estimate zero yeild
0
0 5 10 15 20 25 30
年限
Term
16
19. PCA of interest rate changes
PCA is a statistical method to aggregate multi-dimensional
variables into lower number of dimensions.
Dissolution of time-series and multi-dimensional interest
change data into non-correlated common components can
explain the interest rate variances with lower number of
variances.
Interest rate changes can be mostly explained with 3
principal components: Parallel, Twist and Butterfly.
R already has the function “prcomp(x)” for PCA, and we
can take advantage of it.
18
20. PCA of JGB spot rate
Analysis on JGB spot rate % of variances
Conditions
Historical data used:
Converting JGB yield to spot rates and calculate monthly variances for Jan. 2002~Dec. 2011
Grid points: Year of 1,2,3,4,5,7,10,15,20,30年
Results
PCA Result
0.6
PC1 PC2 PC3 0.5
0.4
Weight
寄与率 74.85% 17.47% 4.16% 0.3
Accm. weight
累積寄与率 74.85% 92.32% 96.48% 0.2 PC1
0.1 PC2
0 PC3
‐0.1 1 2 3 4 5 7 10 15 20 30
‐0.2
‐0.3
‐0.4
19
21. Comparison of interest risks by products (1)
Compared 2 interest risks: risk by PCA (Assumption) and risk by actual interest changes
(Actual Change), assuming CFs from 2 insurance products
2
PC (a CFn DFn )
3
Risk1( Assumption ) x x ,n
x 1
a x , n ::第x成分の neigenvector at x th component and term n
Element of 年限の固有ベクトルの 値
DFn : DiscountFa ctor (1 rn ) n
Risk 2( Actual Change ) EVt 1 EVt
Period Jan. 2007~Dec. 2011 (monthly)
For PCA, previous 10-year data from valuation date is used
Risk Resource Distribution of Actual Change into principal components of variances
Measure weights in Actual Change among each component (PC1,PC2,PC3,Others) by lease square
リスク量の変動
Actual Change
PCz
PCy
ActualChan ge Weight of PCx
2
weight
PCzの寄与
weight
PCyの寄与
weight
PCxの寄与 PCx
20
22. Comparison of interest risks by products (1)
Products
Whole life lump sum (WLL)
Entry age: age 30
Premium payment period :30 years
Whole life annuity (WLA)
Entry age: age 30
Premium payment period :30 years
Pension commencement age :age 60
We assume the following CFs from the valuation date
CF
12000
10000
8000
6000
4000
2000
0 WLL
終身保険
‐2000 WLA
終身年金
‐4000
‐6000
‐8000
0 5 10 15 20 25 30 35 40 45 50 55 60 65 70
Year
21
30. Vasicek model
Outline
A representative equilibrium model
Pros: Manageable because short rate is subject to normal distribution
Cons: Permit minus interest rate
Vasicek model formula: represent short rate rt with n state variables
n
rt yit dyit i i yit dt i dzit
i 1
Calculate zero bond price using model parameters and obtain term
structure of interest rates
i1 Bi ( )yit
n
A( )
P( ) e
i Bi ( ) i 2 Bi 2 ( ) ij i j
n
1
A( ) Bi ( ) B j ( ) 1 e i j
i 1 i2 4 i i j i j i j
2 i i i 2
Bi ( ) 1 e
1
i i i
i 2
i
i
29
31. Vasicek model
Parameter estimation
Assume the short rate is subject to the following random process and
estimate model parameters (κ, θ, σ, λ).
r (tl ) | Ftl 1 ~ N ( { i (1 e ki t ) e ki t yi }, (tl )| Ft )
l 1
i i, j
One typical solution is to regard the observable shortest interest rate
as short rate and estimate parameters using maximum-likelihood
method.
However, while maximum-likelihood method is efficient to estimate
short rate, it is known that it is not always applicable to model the
whole yield curve as it only uses short rate data.
Using historical “yield curve” information is preferable.
Express the model in “state space model” and estimate the
parameters using “Kalman filter technique”
30
32. Vasicek model
Parameter estimation
1. Express Vasicek model in “state space model”
2. Use Kalman filter algorithm and conditioned probability distribution of
state variables
3. Calculate the log likelihood
4. Estimate parameters maximizing log likelihood in 3.
State space model Predict one period ahead Filter
yt k c F yt k 1 t k yt k |t k 1 c F yt k 1 |t k 1
K t k Vt k |t k 1 H T H Vt k |t k 1 H T R 1
z t k a H yt k t k Vt k |t k 1 F Vt k 1 |t k 1 F T Qt k
yt k |t k yt k |t k 1 K t k z t k a H yt k |t k 1
Vt k |t k I K t k H Vt k |t k 1
Log likelihood
l ( ) mK log 2 z T d t1|t zt
zt k |t k 1
1 K K
log d t k |t k 1 z t k |t k 1
2
k 1 k 1 tk k k 1 k
ztk |tk 1 A H ytk |tk 1 d t k |t k 1 H Vt k |t k 1 H T R
31
33. Vasicek model
Implementation in R and risk measurement
Parameter estimate
1. Calculate coefficients in state space
2. Calculate log likelihood (using function “fkf” in package “FKF”)
3. Estimate parameters maximizing log likelihood (using function “optim”)
Measure interest risk
4. Generate random variables and yield curves 1 yr later
5. Calculate changes in PV of CF and percentile amount
10 samples of yield curves 1 yr later
1年後のイールドカーブ (10個のサンプル) Histogram of changes in PV of CF
現在価値の変動額のヒストグラム
3.50% 12
3.00% 10
2.50% 8
2.00% 6
1.50% 4
1.00%
2
0.50%
0
‐90
‐80
‐70
‐60
‐50
‐40
‐30
‐20
‐10
100
110
‐110
‐100
0
10
20
30
40
50
60
70
80
90
次の級
0.00%
0 5 10 15 20 25 30 35
(Assuming 100 CF in 10 grid points during year 1 - 30)
32
34. Summary
• Even when it is difficult to generate economic
scenarios from scratch on Excel, R provide packages
for most economic models. Utilizing them help
actuaries implement economic models.
• We saw that using the package “vars” enables us
to calibrate the VAR model’s coefficients and
utilize other functions with a single command.
• As to the interest rate model, we saw that R
command can accelerate our analysis in Nelson-
Siegel model, PCA and Kalman filter algorithm.
33
35. Reference
• VAR model
• About generalized impulse response function
• M. H. Pesaran and Shin Y (May 1997), “Generalized Impulse
Response Analysis in Linear Multivariate Models”
• About GVAR
• O. Castren, S. Dees and Zaher, F (February 2008), “Global
Macro-Financial Shocks and Expected Default Frequencies in
the Euro Area”
• About vars package
• Reference manual ”Package ‘vars’ January2, 2012”
34
36. Reference
• Interest Rate Model
• About estimation of yield curve and PCA of interest rate variances
• Mark Deacon & Andrew Derry “Estimating the Term Structure of
Interest Rates”
• 田中 周二 「アクチュアリーの統計分析」 朝倉書店
• About Vasicek model
• 大塚裕次朗 「Vasicek/CIR Modelのキャリブレーション手法と日本
の金利VaR99.5%」 日本アクチュアリー会会報64(1)
• Bolder, David “Affine Term Structure Models: Theory and
Implementation “Bank of Canada Working Paper 2001-15
• 北川源四郎 「時系列解析入門」 岩波書店
35