Book Image

Mastering Python for Finance

Book Image

Mastering Python for Finance

Overview of this book

Table of Contents (17 chapters)
Mastering Python for Finance
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Combining root-finding methods


It is perfectly possible to write your own root-finding algorithms using a combination of the previously mentioned root-finding methods. For example, you may use the following implementation in the following order:

  1. Use the faster secant method to converge the problem to a prespecified error tolerance value or a maximum number of iterations.

  2. Once a prespecified tolerance level is reached, switch to using the bisection method to converge to the root by halving the search interval with each iteration until the root is found.

Brent's method or the Wijngaarden-Dekker-Brent method combines the bisection root-finding method, secant method, and inverse quadratic interpolation. The algorithm attempts to use either the secant method or inverse quadratic interpolation whenever possible, and uses the bisection method where necessary.

Brent's method can also be found in the scipy.optimize.brentq function of SciPy.