Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boundary condition of Cubic Spline interpolation #234

Closed
KalvinMa opened this issue Mar 22, 2024 · 3 comments · Fixed by #235
Closed

Boundary condition of Cubic Spline interpolation #234

KalvinMa opened this issue Mar 22, 2024 · 3 comments · Fixed by #235
Labels
question Further information is requested

Comments

@KalvinMa
Copy link

KalvinMa commented Mar 22, 2024

Hi,
May I ask what boundary condition are used in cubic spline interpolation function? I compared the interpolation results with SciPy and found the result is different with all cases with different boundary conditions in SciPy. It approaches the "natural" one, but still a little bit different. Thanks a lot.
image

@KalvinMa KalvinMa added the question Further information is requested label Mar 22, 2024
@sathvikbhagavan
Copy link
Member

Are you referring to extrapolation? It extrapolates the last cubic polynomial on both sides.

@KalvinMa
Copy link
Author

I don't think I use the extrapolation, here is the code.
In Julia:

# Cubic Spline for TBP curve
T = [310.217183796031 ,
341.254055958343 ,
369.798567124936 ,
387.403465409701 ,
406.403097762664 ,
433.370431885499 ,
480.578081202443 ,
]
V = [0.0, 10.0, 30.0, 50.0, 70.0, 90.0, 100.0]
CubicS = CubicSpline(T, V)
v = range(2.5, 100.0, step=5.0)
CubicS.(v)

In SciPy:

import numpy as np
from scipy.interpolate import CubicSpline
import matplotlib.pyplot as plt
T = [310.217183796031 ,
341.254055958343 ,
369.798567124936 ,
387.403465409701 ,
406.403097762664 ,
433.370431885499 ,
480.578081202443 ,
]
V = [0.0, 10.0, 30.0, 50.0, 70.0, 90.0, 100.0]
cs_natural = CubicSpline(Vols, TBPs, bc_type='natural')
cs_knot = CubicSpline(Vols, TBPs, bc_type='not-a-knot')
cs_clamped = CubicSpline(Vols, TBPs, bc_type='clamped')
v = np.array(range(25, 1000, 50)) / 10.0
cs_natural(v)
cs_knot(v)
cs_clamped(v)

@sathvikbhagavan
Copy link
Member

We use the natural boundary conditions. There was a bug which is fixed in #235

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants