Skip to Content
Mastering Python for Finance - Second Edition
book

Mastering Python for Finance - Second Edition

by James Ma Weiming
April 2019
Intermediate to advanced
426 pages
11h 13m
English
Packt Publishing
Content preview from Mastering Python for Finance - Second Edition

General nonlinear solvers

The scipy.optimize module also contains multidimensional general solvers that we can use to our advantage. The root and fsolve functions are some examples with the following function properties:

  • root(fun, x0[, args, method, jac, tol, ...]): This finds a root of a vector function.
  • fsolve(func, x0[, args, fprime, ...]): This finds the roots of a function.

The outputs are returned as dictionary objects. Using our example as input to these functions, we will get the following output:

In [ ]:    import scipy.optimize as optimize    y = lambda x: x**3 + 2.*x**2 - 5.    dy = lambda x: 3.*x**2 + 4.*x    print(optimize.fsolve(y, 5., fprime=dy))Out[ ]:        [1.24189656]In [ ]:    print(optimize.root(y, 5.))Out[ ]: fjac: array([[-1.]]) fun: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python for Finance - Second Edition

Python for Finance - Second Edition

Yuxing Yan
Python for Finance

Python for Finance

Yves Hilpisch

Publisher Resources

ISBN: 9781789346466Supplemental Content