Cubic smooth spline plot in 3d for several layers

6 visualizaciones (últimos 30 días)
Gabriel Fouillon
Gabriel Fouillon el 19 de Feb. de 2020
Comentada: darova el 24 de Feb. de 2020
Hello I have vectors
iv3,iv28,iv48,iv68,iv133,iv268,iv398 (each of length 83x1 - positive real numbers)
and one vector named strikes (length 83x1 - positive real numbers)
The iv3 vector refers to implied volatility data from day 3, the iv28 from day 28 and so on (this means we have a time axis of 7 days with day 3,day 28,...,day 398)
I need to do smooth spline interpolation for each pair (strikes,iv3) ,(strikes,iv28), ...,(strikes,iv398) and I use csaps().
csaps() works totally fine in 2d. Problem is I need to put all 2d plots in one 3d plot. But I do not need one surface over the whole observations in 3d, rather for each day and each pair (strikes,iv28), (strikes,iv48), ....(strikes,iv398) one smoothing spline (in total 7 splines per pair and time) -
spline1 one on (strikes,iv3, day3) ,
spline2 one on (strikes,iv28, day28)
,...,
spline7 one on (strikes,iv398, day398)
I came so far to plot the (unsmoothed) 3d observation graph (without the splines).
Now i need to do the smoothing for each observation pair in 3d.
Since csaps() and fnplt() do not work for 3d I need a workaround for 3d.
Also important is that I would like to have a smoothing parameter (lambda) which determines the smoothnes of the spline. As mentioned csaps does this perfectly, but does unfortunately not work for 3d graphics!
--------------------
To the graphic below! Every dot line needs to get its spline that smooths the data. Splines are missing in the graphic!
Plot command was (here for day 3) plot3(repmat(3,length(strikes),1),strikes,iv3,'.')
This was commanded then for each data tripel (days,strikes, iv), hence the other lines.
And here the day3 data with yellow=spline(via csaps(strikes,iv3,0.001)) and blue=real observations
Kind Regards
Gabriel
  5 comentarios
darova
darova el 20 de Feb. de 2020
Do you have data?
Gabriel Fouillon
Gabriel Fouillon el 21 de Feb. de 2020
Hello I did something plus provided data, see below.
Thanks

Iniciar sesión para comentar.

Respuesta aceptada

Gabriel Fouillon
Gabriel Fouillon el 21 de Feb. de 2020
Editada: Gabriel Fouillon el 21 de Feb. de 2020
Hello I have an approach, but another questions opens now (see below).
Approach:
1) I plotted the observation data via plot3(timeslice,strikes,iv) for each of the seven timeslices/iv vectors (blue dots)
2) Then I build 8 splines via spline_i=csaps(strikes,iv,lambda) for each of the seven iv vectors
3) Then I evaluated every spline via fnval(csaps(),strikes) or each of the seven iv vectors/timeslices
4) Then i plotted the splines via plot3(timeslice,strikes,fnval(cspsn())) (red lines)
Question:
Problem is in the new plot (see below) the splines look unnatural, I assume that every spline should only smooth from the first non NaN value (real number) to the last non NaN value (real number) and no more further, otherwise it oszillates (as you can see good on spline for maturity round about 133).Please notice that all iv vectors had entries which were empty, these were then set to NaN in order to have same length as strikes (y axis ). Do you have an idea how i could smooth only up to the last non NaN value?
The data for the timeslices (time axis) is
You can produce each timeslice (time axis or x axis) via the formula below - 8 layers given here
maturity_3=3*ones(1,83)
maturity_28=28*ones(1,83)
maturity_48=48*ones(1,83)
maturity_68=68*ones(1,83)
maturity_133=133*ones(1,83)
maturity_198=198*ones(1,83)
maturity_263=263*ones(1,83)
maturity_398=398*ones(1,83)
The data for all iv vektors and strikes
is given in the text document I attached, you can easily read it in via Matlab, sorry could not copy paste here due to formating problems. The text document tells you: First colum is strikes, second column is iv3, third column is iv28, fourth column is iv48, fifth column is iv68, sixth column is iv133, seventh colum is iv198, eigth column is iv263 and nineth column is iv398.
My interpolation plot is
Would appreciate any feedback, many thanks for your help.
Kind Regards
Gabriel
  2 comentarios
darova
darova el 21 de Feb. de 2020
Can't you just change limits of interpolation?
Gabriel Fouillon
Gabriel Fouillon el 21 de Feb. de 2020
You mean I limit the fnval() on the desired range of the spline? And then i run my plot over these limited values? Makes absolutely sense! Will try and come back. Many thanks

Iniciar sesión para comentar.

Más respuestas (2)

darova
darova el 21 de Feb. de 2020
Maybe you don't need interpolation. I just removed NaN numbers
D = importdata('Data.txt');
A = D.data;
x = A(:,1);
cla
hold on
for i = 2:size(A,2)
ix = ~isnan(A(:,i));
x1 = x(ix);
y1 = A(ix,i);
plot3(x,x*0+i,A(:,i),'.b')
plot3(x1,x1*0+i,y1)
end
hold off
  3 comentarios
darova
darova el 21 de Feb. de 2020
  • I will come back to you hopefully with the right plot.
I will be waiting infinitely
Gabriel Fouillon
Gabriel Fouillon el 23 de Feb. de 2020
Hello, can you check below please? Thank you.

Iniciar sesión para comentar.


Gabriel Fouillon
Gabriel Fouillon el 23 de Feb. de 2020
Hello hope you are fine!
I have this approach.
It worked, but it was a bit tricky, had to built dynamical read ins of the first and last non NaN value in each vector.
Now I have another question, I would like to smooth again over the time axis,with a smooth spline interpolation, so that i have a smooth surface (this time smoothing over time axis).Do you have an idea how to implement this?
Here the result
Thanks for your help.
Kind Regards
Gabriel
  7 comentarios
Gabriel Fouillon
Gabriel Fouillon el 24 de Feb. de 2020
Editada: Gabriel Fouillon el 24 de Feb. de 2020
I have seen that there exists a thin-plate smoothing via tpaps(), but it only goes in 2d. Again I need to move to 3d. Any thaughts on that?
darova
darova el 24 de Feb. de 2020
This is how your data looks like (XY plane)
If you want to interpolate along time axis (Y) you need red points. Sometimes you have NaN
So you can't interpolate curve there

Iniciar sesión para comentar.

Categorías

Más información sobre Spline Postprocessing en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by