Is it possible to change the interpolation methods used in a function?

1 visualización (últimos 30 días)
Helena
Helena el 16 de Abr. de 2018
Editada: John D'Errico el 16 de Abr. de 2018
I'm looking specifically at the zbtyield function which uses bootstrapping to create a zero rate curve. The function uses linear interpolation to determine the interest rates from cash flows and I was wondering if it would be possible to change this to a cubic spline instead? Thanks

Respuestas (1)

John D'Errico
John D'Errico el 16 de Abr. de 2018
Editada: John D'Errico el 16 de Abr. de 2018

No. You cannot somehow magically change the way code is written. Just wanting it to be different is not sufficient. A quick read of the documentation for that function does not offer such an option. And there is no way to merely set an external preference that somehow changes all interpolations from linear into cubic splines.

https://www.mathworks.com/help/finance/zbtyield.html

IF the code is provided as an m-file, you MIGHT IN THEORY be able to modify the code to use a different interpolation. However, the chances are very good that you would create bugs in the code by so doing. Even if you managed to write the code so that you changed only the interpolation, and created no overt bugs in the code, you still might easily have created a bug in it. Why do I say this?

A spline has the property that it can easily be oscillatory. A spline can achieve extremal values that are higher or lower than any data point provided. A linear interpolant can never do so however. I'd bet that this is important here. There may be other issues too.

So, unless you know enough about exactly how the code was written, AND you know enough about all of the numerical methods that you might change that you could have written it from scratch yourself, making changes like this are a bad idea. And if you do have that sufficiently complete knowledge of the problem, then writing your own version should be easy. So if you really, desperately need this capability, then I'd suggest you start writing code.

Of course, you could suggest it to The MathWorks as a feature request. Contact them directly, by clicking on the "Contact Us" link on the top right corner of your browser page. While my guess is this would be deemed a low priority change, one might be surprised.

Categorías

Más información sobre Splines 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