Library: | gam |
See also: | DSFM gamfit gintest gintestpl intest interact intestpl pcad |
Quantlet: | DSFM4IV | |
Description: | estimates a dynamic semiparametric factor model from the form: yt = m0(u) + bt1*m1(u) + bt2*m2(u)... btL*mL(u), where m0 to mL are 2-dimensional invariant basis functions on the grid u and bt0=1. bt1 to btL are scalar weights depending on time T. After estimation, the functions m are orthogonalized under the empirical norm of the observed data points and ordered according to the maximal variance of b. The model only uses fits in the local neighbourhood of the design points. Thus, it is suited for data with degenerated design, like implied volatility data. |
Usage: | {beta,mhat,fitted} = DSFM4IV(x,L,h,u{,rmax{,L2tol{,startbeta}}}) | |
Input: | ||
x | nx4 matrix, column 1 contain moneyness, column 2 time to maturity, column 3 observed log-implied volatilities (logarithm has to be calculated outside this quantlet), column 4 contains a numeric vector with different T dates. T must be at least three times L (T >= 3L) | |
L | scalar, integer, number of basis functions to be estimated (1 < L <= 10) | |
h | 2x1 vector or mx2 matrix, contains the bandwidths. When h is a 2x1 vector the bandwiths are fixed and the first entry refers to column 1 in x, second entry to column 2 in x. When h is a mx2 matrix the local bandwiths are taken and the dimension needs to be the same as grid points u dimension. The first column of h refers to the first column of u, the second column of h refers to the second column of u | |
u | mx2 matrix, grid points on which the functions are to be estimated, (the stepwidth in each direction must be constant) | |
rmax | optional scalar, maximum number of iterations in the estimation, default=301. | |
L2tol | optional scalar, minimal L2 tolerance of the estimation criterion, default=10^-5. | |
startbeta | optional matrix, T (number of days) rows and L columns containing starting values for the algorithm. | |
Output: | ||
beta | Tx(L+1) matrix, column 1 contains date vector, column 2 weights bt1 corresponding to function m1, column 3 weights bt2 corresponding to m2, etc. | |
mhat | Mx(L+2) matrix, columns 1 and 2 contain the grid u, column 3 contains m0, column 4 m1, column 5 m2, etc. | |
fitted | Tx6 matrix, column 1 contains date vector, column 2 contains the number of observation in each day, column 3 contains mean of AIC1 criterion , column 4 contains variance of AIC1 criterion, column 5 contains mean of AIC2 criterion, column 6 contains variance of AIC2 criterion, |
library("xplore") library("plot") library("kernel") library("gam") L = 3 rmax = 800 L2tol = 10^-5 umax = 1.2|1.00 umin = 0.8|0.0 nsteps = 25|25 ; previously: 50|50 udelta =(umax-umin)./(nsteps-1) ; 0.01 und 0.02 gridtiefe ucub = prod(udelta) ; 2 dim. cuboid of udelta - necessary for integration u = grid(umin, udelta, nsteps) u = sort(u, 1|2) ; diese sortiererei ist maßlos wichtig!! m1 = u~matrix(rows(u)) m2 = u ~(-5.*u[,1] +5) m3 = u ~(-2.*u[,2] +1) obsperday = 1000 numofdays = 200 beta1 = genar(normal(numofdays), 3, 0.2 )/3 beta2 = genar(normal(numofdays), 0.01, 0.2)/100 beta3 = genar(normal(numofdays), 0.01, 0.2)/100 beta1= -(beta1 + min( beta1)) b1 = matrix(obsperday)*beta1' b1 = vec(b1) b2 = matrix(obsperday)*beta2' b2 = vec(b2) b3 = matrix(obsperday)*beta3' b3 = vec(b3) days = floor((0:(obsperday*numofdays -1))/obsperday) simiv = uniform(rows(days),2) simiv[,1]=(1-simiv[,1])*umin[1,1] + simiv[,1]*umax[1,1] simiv = simiv ~-( 0 + b1* 1 + b2 .*(-5 * simiv[,1] +5) + b3.*(-2 * simiv[,2] +1) ) ; m0 + b1 m1 + b2 m2 + b3 m3 simiv = simiv~days h = 0.02|0.02 {betahat,mhat,f}=DSFM4IV(simiv,L,h,u,rmax,L2tol) disp1=createdisplay(1,3) ppm1 = setmask(mhat[,1:2]~mhat[,4],"surface","blue") ppm2 = setmask(mhat[,1:2]~mhat[,5],"surface","blue") ppm3 = setmask(mhat[,1:2]~mhat[,6],"surface","blue") show(disp1,1,1,ppm1) show(disp1,1,2,ppm2) show(disp1,1,3,ppm3) disp2=createdisplay(3,1) ppb1 = setmask(betahat[,1]~betahat[,3],"line","blue") ppb2 = setmask(betahat[,1]~betahat[,4],"line","blue") ppb3 = setmask(betahat[,1]~betahat[,5],"line","blue") show(disp2,1,1,ppb1) show(disp2,2,1,ppb2) show(disp2,3,1,ppb3)
In this example an artificial model spanning 200 days is created and estimated. The estimated basis functions are plotted. An additional plot shows the estimated factor loadings