Use of R in Actuarial Works

1,339 views

Published on

Presented in IAJ annual meeting at November 6th, 2012

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,339
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
26
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Use of R in Actuarial Works

  1. 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. 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
  3. 3. Development of VAR Model for StressTesting of Macro Economy 2
  4. 4. VAR ModelFlow 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. 5. VAR ModelVAR(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. 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. 7. VAR ModelGVAR(Global Vector AutoRegression) model • VARX(VAR with eXogenous variables) model (Model by region with exogenous variable (Y: X withweighted average of region other than i)X ti  C i  A1i X ti1  A2 X ti2   Aip X ti p  G0Yt k  G1iYt 1   GqYt q   t i i k i kIndex 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 t11   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. 8. VAR modelImplementation 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. 9. VAR ModelPast Data Used【Equity Price Index】 【10-year LIBOR Swap Rate】20,000 7.00018,000 6.00016,00014,000 5.000 NKY225 JPY12,000 4.00010,000 SP500 USD 8,000 FTSE100 3.000 EUR 6,000 2.000 4,000 1.000 2,000 0 0.000 8
  10. 10. VAR ModelOutput 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. 11. VAR ModelOutput 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
  12. 12. Interest Rate Model 11
  13. 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. 14. Interest Rate ModelEstimation 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. 15. Interest Rate ModelEstimation 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. 16. Interest Rate ModelEstimation 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. 17. Interest Rate ModelEstimation 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
  18. 18. PCA of interest rate changes 17
  19. 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. 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.4Weight寄与率 74.85% 17.47% 4.16% 0.3Accm. 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. 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. 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
  23. 23. 0.5 1.5 2.5 0 1 2 3 2002/07/01 2003/02/01 2003/09/01 2004/04/01 2004/11/01 2005/06/01 2006/01/01 2006/08/01 2007/03/01 Historical JGB yield 2007/10/01 2008/05/01 JGB 2008/12/01 2009/07/01 2010/02/01 2010/09/01 2011/04/01 2011/11/01 JGB 2Y JGB 20Y JGB 10Y22
  24. 24. 0 1 2 3 4 5 6 7 8 2002/07/01 2003/02/01 2003/09/01 2004/04/01 2004/11/01 2005/06/01 2006/01/01 2006/08/01 2007/03/01 2007/10/01 2008/05/01 2008/12/01 2009/07/01 2010/02/01 2010/09/01 2011/04/01 2011/11/01 Italian Government Bonds Historical Italian Government Bonds yield IT Gov 2Y IT Gov 20Y IT Gov 10Y23
  25. 25. Result (WLL, JGB Yield) WLL Observation Actual Change vs Assumption25000  Assumption returns a constant risk2000015000 amount irrelevant to the timing.10000 |Actual Chg|  ActualChange varies significantly when 5000 0 Assumption the histrical rate experiences huge 2007/01/01 2007/07/01 2008/01/01 2008/07/01 2009/01/01 2009/07/01 2010/01/01 2010/07/01 2011/01/01 2011/07/01 changes. Histgram 0.35 0.3  Assumption captures the 0.25 Actual/Assumption 0.2 Average 0.11 ActuarlChange in fairly good manner. Actuarl/Assump 0.15 NormalDistribution Stdev 0.87 0.1 0.05 0 ‐5 ‐4 ‐3 ‐2 ‐1 0 1 2 3 4 5 Risk Resource Distribution 100% 90% 80% 70% Others 60% 50% 40% PC3  PC1(Parallel) contributes to PC2 30% 20% 10% PC1 ActualChange largely. 0% 2007/01/01 2007/07/01 2008/01/01 2008/07/01 2009/01/01 2009/07/01 2010/01/01 2010/07/01 2011/01/01 2011/07/01
  26. 26. Result (WLA, JGB Yield) WLA Observation Actual Change vs Assumption9000080000  Assumption returns a constant risk7000060000 amount irrelevant to the timing.50000400003000020000 |Actual Chg|  ActualChange varies significantly when10000 0 Assumption the histrical rate experiences huge 2007/01/01 2007/07/01 2008/01/01 2008/07/01 2009/01/01 2009/07/01 2010/01/01 2010/07/01 2011/01/01 2011/07/01 changes. Histgram0.25 0.2  Assumption somewhat underestimates Actual/Assumption0.15 Average (0.07) but captures ActuarlChange in fairly good manner. Actuarl/Assump 0.1 NormalDistribution Stdev 1.220.05 0 ‐5 ‐4 ‐3 ‐2 ‐1 0 1 2 3 4 5 Risk Resource Distribution100% 90% 80% 70% Others 60% 50% 40% PC3 PC2  PC2(Twist) contributes to ActualChange largely. 30% 20% PC1 10% 0% 2007/01/01 2007/07/01 2008/01/01 2008/07/01 2009/01/01 2009/07/01 2010/01/01 2010/07/01 2011/01/01 2011/07/01 25
  27. 27. Result (WLL, Italian Government Bonds Yield) WLL Observation Actual Change/Assumption6000050000  Assumption misses to capture40000 ActualChange at the time of Euro crisis (2011-).3000020000 |Actual Chg|10000 Assumption 0 2007/01/01 2007/07/01 2008/01/01 2008/07/01 2009/01/01 2009/07/01 2010/01/01 2010/07/01 2011/01/01 2011/07/01 Histgram0.25  Assumption underestimates the risk. Actual/Assumption 0.20.15 Average (0.10) Stdev 1.60 Actuarl/Assump 0.1 NormalDistribution0.05 0 ‐5 ‐4 ‐3 ‐2 ‐1 0 1 2 3 4 5 Risk Resource Distribution 100% 90% 80% Like JGB, PC1(Parallel) contributes to 70% Others 60% 50% PC3  40% 30% 20% PC2 the variances most. PC1 10% 0% 2007/01/01 2007/07/01 2008/01/01 2008/07/01 2009/01/01 2009/07/01 2010/01/01 2010/07/01 2011/01/01 2011/07/01
  28. 28. Result (WLA, Italian Government Bonds Yield) WLA Observation Actual Change vs Assumption7000060000  Assumption misses to capture5000040000 ActualChange at the time of Euro crisis30000 |Actual Chg| (2011-).20000 Assumption10000 0 2007/01/01 2007/06/01 2007/11/01 2008/04/01 2008/09/01 2009/02/01 2009/07/01 2009/12/01 2010/05/01 2010/10/01 2011/03/01 2011/08/01 2012/01/01 Histgram 0.25  Assumption significantly 0.2 Actual/Assumption 0.15 Average 0.31 underestimates the risk. 0.1 Actuarl/Assump Stdev 2.83 NormalDistribution 0.05 0 Risk Resource Distribution 100% 90% 80% 70% 60% 50% Others PC3  PC2(Twist) and PC3 (Butterfly) largely 40% 30% PC2 contributes to the variances . 20% PC1 10% 0% 2007/01/01 2007/05/01 2007/09/01 2008/01/01 2008/05/01 2008/09/01 2009/01/01 2009/05/01 2009/09/01 2010/01/01 2010/05/01 2010/09/01 2011/01/01 2011/05/01 2011/09/01
  29. 29. Parameter Estimation of Vasicek ModelAnd Risk Measurement 28
  30. 30. Vasicek modelOutline 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 i1 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. 31. Vasicek modelParameter 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. 32. Vasicek modelParameter estimation1. Express Vasicek model in “state space model”2. Use Kalman filter algorithm and conditioned probability distribution of state variables3. Calculate the log likelihood4. 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 t1|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. 33. Vasicek modelImplementation in R and risk measurement Parameter estimate1. Calculate coefficients in state space2. Calculate log likelihood (using function “fkf” in package “FKF”)3. Estimate parameters maximizing log likelihood (using function “optim”) Measure interest risk4. Generate random variables and yield curves 1 yr later5. 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. 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. 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. 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

×