• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

Cubic spline interpolation

Joined
11/5/14
Messages
295
Points
53
Hi everyone,

Having studied calculus and linear algebra in my first year of undergraduate math, I created a small notebook - put together the intuition, the math and a python code snippet of cubic spline interpolation. Thought of sharing it with you all.

Have a great day,

Quasar.
 
Other possible boundary conditions are here.

Cubic Spline Interpolation - Wikiversity

BTW how does your code work on



. (Cubic Spline Overshoots)

Consider the test data x = {1,2,3,3.1,5.1,6,7,8} and y = {1.8, 1.9, 1.7,1.1, 1.1, 1.7,1.4,1.9}. Apply cubic spline interpolation to this data set with the two end/boundary conditions that we discussed in this chapter. Determine those subintervals in [1,8] where negative values are produced. This is obviously an undesirable situation. In particular, what is the interpolated value when x = 4?

Carry out the same experiment with the data:

std::vector<double> x{ 0,10,30.50,70,90,100 };

std::vector<double> y{ 30,130,150,150,170,220,320};
 
Quasar,
Another idea for testing your solver..

.. we see that both the Crank Nicolson and cubic spline interpolator produce similar results for delta while the interpolator’s accuracy for gamma is less accurate than the Crank Nicolson method. What is the reason? For smooth functions centred divided difference approximation to the first and second derivatives result in second order accuracy. This approach is based on Taylor expansions. Cubic splines are polynomials and they are a third-order accurate approximation to a smooth function. The first derivative of the spline is a second-order approximation to the exact delta while the second derivative of the spline is a first-order approximation to the exact gamma. This theoretical result is proven mathematically in Alberg, Nilson and Walsh 1967, Theorem 3.11.1, page 94. But cubic spline interpolators can overshoot in order to always create a visually pleasing curves and this might account for the fact that the values for gamma are larger than the exact gamma or even the Crank Nicolson gamma.

When approximations to the second derivatives of a smooth function are needed, we can first approximate it by using the values of the first derivative as input in order to compute an approximation to the second derivative. This is called spline-on-spline computation (Hildebrand 1974, page 492 and Alberg, Nilson and Walsh 1967, pages 48-50) and the improvements in accuracy are visible. In the current case a useful exercise would be to compare the values for gamma based on this variant and the original approach taken to produce the results ..
 
Last edited:
Back
Top