-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDataAnalysis.R
More file actions
59 lines (48 loc) · 1.77 KB
/
DataAnalysis.R
File metadata and controls
59 lines (48 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
source('Est_FDF.R')
source('hatK.R')
source('SmoothData.R')
# laod data FedYieldCurve.RData
timeYear <- c(3/12, 6/12,1,2,3,5,7,10) # time in years
tt <- c( (3/12)/10, (6/12)/10,1/10,2/10,3/10,5/10,7/10,10/10) # in (0,1)
N <- dim(MatYield)[2] # sample size
# plot data
matplot(timeYear, MatYield, type = 'l', xlab = 'maturities structure',
ylab = '', main= "Yield Curves")
# test for stationarity
library(ftsa)
T_stationary(MatYield, L=15) # not stationary
# estimate parameters for non stationary components
est_nst <- FDF(argvals=tt,
data=MatYield,
h=2,k=1,p=4,
nbasis=15,
basis='Bspline',
kern_type = "BT",
lambda = NULL,
stationary = FALSE,
plot = FALSE)
# subtract the nonstationary component
MatYield2 <- MatYield - est_nst$Xhat
# test
T_stationary(MatYield2, L=15)
# estimate parameters for stationary components
est_st <- FDF(argvals=tt,
data=MatYield2,
stationary=TRUE,
h=19,k=2,p=5,
nbasis=15,
basis='Bspline',
kern_type = "BT",
lambda = NULL,
plot = FALSE)
# plots
plot(est_nst$hat.F, ylim = c(-2.5,2), main='F 1', xlab='s', ylab='')
plot(est_st$hat.F[1], ylim=c(-2.5,2), main='F 2', xlab='s', ylab='' )
plot(-est_st$hat.F[2], ylim=c(-2.5,2), main='F 3', xlab='s', ylab='')
# plot of time series
plot(1:N,est_nst$hat.beta, type='l', main='Factor process 1',
xlab='n', ylab='')
plot(1:N,est_st$hat.beta[,1], type='l', main='Factor process 2',
xlab='n', ylab='')
plot(1:N,est_st$hat.beta[,2], type='l', main='Factor process 3',
xlab='n', ylab='')