Library: | math |
See also: | locpol regestp volsurf vecimplvol |
Quantlet: | SurfaceInterpol | |
Description: | Given a surface on a regular 2-dimensional grid, SurfaceInterpol computes the surface value at unknown points by a local polynomial interpolation |
Usage: | z=SurfaceInterpol(surface,x{,h}) | |
Input: | ||
surface | Nx3 matrix, columns 1 and 2 contain x and y values of the grid, column 3 contains the z value | |
x | Mx2 matrix, containing M points at which the surface value is to be found | |
h | 2x1 vector, optional, containing the bandwidth for the local polynomial estimator; default is 30% of the range in the surface in each direction. | |
Output: | ||
z | Mx3 matrix, columns 1 and 2 contain the input parameter x, column 3 contains the computed surface values |
library("plot") library("math") x = grid(#(-1,-1), #(0.1,0.1), #(40,40)) f = exp(-0.5.*(x[,1]^2+x[,2]^2))./(2.*pi) surface=x~f y=(1~0.33)|(0.77~0.16)|(-0.51~0.1)|(2.3~1.3) z=SurfaceInterpol(surface,y) z surf=setmask(surface,"point","black","size","tiny") setmaskp(z,4,8,8) plot3d(1,surf,z)
Produces a surface from a function of 2 arguments. At some arbitrary points x, the surface is re-calculated by a local polynomial interpolation. Contents of z [1,] -0.51 0.1 0.13887 [2,] 0.77 0.16 0.11578 [3,] 1 0.33 0.091237 [4,] 2.3 1.3 0.0046608 where the first two columns contain x, the last one the respective estimates of x. A graphic shows the original surface (black) and the estimates (red points).
library("plot") library("finance") library("math") data=read("volsurfdata2.dat") stepwidth=70|(1/52) bandwidth=250|0.5 firstXF=3500 lastXF=7000 firstMat=0 lastMat=1 metric=1 AdjustToSurface=1 {IVSurface,IVpoints}=volsurf(data, stepwidth,firstXF,lastXF,firstMat,lastMat, metric,bandwidth,0) z=SurfaceInterpol(IVSurface,5000~0.15|(6000~0.16)) z IVSurface=setmask(IVSurface,"point","black","size","tiny") setmaskp(z,4,8,8) plot3d(1,IVSurface,z)
In this more complex example we first fit the so called implied volatility surface. Then the specific value of the surface at strike K=5000 and moneyness tau=0.15, and K=6000 and tau=0.16, is calculated: Contents of z [1,] 5000 0.15 0.35729 [2,] 6000 0.16 0.2995 As in the example above, a graphic shows the original surface (black) and the estimates (red points).