Popular recipes tagged "laplace_inversion"http://code.activestate.com/recipes/tags/laplace_inversion/2010-03-22T05:00:20-07:00ActiveState Code RecipesA new method for computing the hypergeometric function 1F1(a,b,t) (Python)
2010-03-22T05:00:20-07:00Fernando Nieuwveldthttp://code.activestate.com/recipes/users/4172088/http://code.activestate.com/recipes/577133-a-new-method-for-computing-the-hypergeometric-func/
<p style="color: grey">
Python
recipe 577133
by <a href="/recipes/users/4172088/">Fernando Nieuwveldt</a>
(<a href="/recipes/tags/function/">function</a>, <a href="/recipes/tags/hypergeometric/">hypergeometric</a>, <a href="/recipes/tags/laplace_inversion/">laplace_inversion</a>).
Revision 3.
</p>
<p>I present a method of computing the 1F1(a,b,x) function using a contour integral. The method is based on a numerical inversion, basically the Laplace inversion. Integral is 1F1(a,b,x) = Gamma(b)/2\pi i \int_\rho exp(zx)z^(-b)(1+x/z)^(-a)dz, \rho is taken as a Talbot contour. The Talbot method is applied with the use of the midpoint rule for numerical integration. Here the user must give the number of function evaluations and this may vary from problem to problem. It is very easy to implement with only a few lines of code and it is very accurate even for large arguments.</p>
Pricing Asian options using mpmath with automatic precision control (Python)
2009-11-24T01:20:56-08:00Dieter Kadelkahttp://code.activestate.com/recipes/users/4172107/http://code.activestate.com/recipes/576964-pricing-asian-options-using-mpmath-with-automatic-/
<p style="color: grey">
Python
recipe 576964
by <a href="/recipes/users/4172107/">Dieter Kadelka</a>
(<a href="/recipes/tags/computational_finance/">computational_finance</a>, <a href="/recipes/tags/laplace_inversion/">laplace_inversion</a>, <a href="/recipes/tags/mpmath/">mpmath</a>).
</p>
<p>In <a href="http://code.activestate.com/recipes/576954/">Recipe 576954</a> presented a numerical method for pricing Asian options using mpmath and some code from <a href="http://code.activestate.com/recipes/576938/">Recipe 576938</a>: Numerical Inversion of the Laplace Transform with mpmath. The code in <a href="http://code.activestate.com/recipes/576954/">Recipe 576954</a> seems to have problems with the precision required for accurate computation of the integrals. To solve this problem, I changed the code in <a href="http://code.activestate.com/recipes/576938/">Recipe 576938</a> and the code in <a href="http://code.activestate.com/recipes/576954/">Recipe 576954</a>, which now uses mp_laplace.py.</p>
<p>The new mp_laplace.py and asian.py are in the code section.</p>