Cubic smooth spline plot in 3d for several layers

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 Comments

Hello darova, thanks for feedback. Still looking at your proposes. If I have a draft on this, may I come back to you on this? Many thanks and have a great day!
Do you have data?
Hello I did something plus provided data, see below.
Thanks

Sign in to comment.

 Accepted Answer

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 Comments

Can't you just change limits of interpolation?
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

Sign in to comment.

More Answers (2)

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 Comments

Hello,
your approach looks great thanks! Unfortunately a smooth spline must be applied.This is due to NO ARBITRAGE conditions out of options pricing theory (check for "butterly arbitrage" or "calendar arbitrage"). Basically the natural cubic smooth spline guarantees that the options volatility (or price) is holding the necessary conditions (fair priced, no riskless return or law of one price), otherwise you would misprice the option. The data given definitely breaks the NO ARBITRAGE law (data contains lots of noise), now the target is to produce smooth splines in order to have a fair/correct estimation of the iv. Smooth splines guarantee this, due to their features (1st & 2nd order derivatives).
You can also check these two links if it interests you further Implied Volatility Correct Pricing and Implied Volatility Smoothing Idea .
I will come back to you hopefully with the right plot.
Thank you!
Gabriel
  • I will come back to you hopefully with the right plot.
I will be waiting infinitely
Hello, can you check below please? Thank you.

Sign in to comment.

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 Comments

you mean you want to see the output data?
  • I would like to smooth again over the time axis,with a smooth spline interpolation, so that i have a smooth surface
I mean that you can use griddata to create surface or smooth your data along time axis
Ah ok, thanks. Will check for that and figure out. But do you know if it has the same features as csaps() (for example providing a smoothing parameter λ?
Cant I apply caps() again over the fittedn data in 3d?
Thanks
I don't think griddata has that property/feature
But you can try different types of interpolation: 'linear', 'natural', 'cubic' and so on
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?
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

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!