Popular recipes by Fernando Nieuwveldt http://code.activestate.com/recipes/users/4172088/popular/2010-04-06T13:26:02-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> Solving the Black-Scholes PDE with laplace inversion:Revised (Python) 2010-04-06T13:26:02-07:00Fernando Nieuwveldthttp://code.activestate.com/recipes/users/4172088/http://code.activestate.com/recipes/577142-solving-the-black-scholes-pde-with-laplace-inversi/ <p style="color: grey"> Python recipe 577142 by <a href="/recipes/users/4172088/">Fernando Nieuwveldt</a> (<a href="/recipes/tags/black/">black</a>, <a href="/recipes/tags/laplace/">laplace</a>, <a href="/recipes/tags/scholes/">scholes</a>, <a href="/recipes/tags/talbot/">talbot</a>). Revision 2. </p> <p>I originally posted this code in <a href="http://code.activestate.com/recipes/577132/">Recipe 577132</a> and this is a repost of that recipe with corrections since there was an error in the original recipe. Added here is an error analysis to show the effectiveness of the Laplace inversion method for pricing European options. One can test the accuracy of this method to the finite difference schemes. The laplace transform of Black-Scholes PDE was taken and the result was inverted using the Talbot method for numerical inversion. For a derivation of the laplace transform of the Black-Scholes PDE, see for instance <a href="http://www.wilmott.com/pdfs/020310_skachkov.pdf." rel="nofollow">www.wilmott.com/pdfs/020310_skachkov.pdf.</a></p> Numerical Inversion of the Laplace Transform using the Talbot method. (Python) 2009-10-27T04:53:30-07:00Fernando Nieuwveldthttp://code.activestate.com/recipes/users/4172088/http://code.activestate.com/recipes/576934-numerical-inversion-of-the-laplace-transform-using/ <p style="color: grey"> Python recipe 576934 by <a href="/recipes/users/4172088/">Fernando Nieuwveldt</a> (<a href="/recipes/tags/analysis/">analysis</a>, <a href="/recipes/tags/laplace/">laplace</a>, <a href="/recipes/tags/numerical/">numerical</a>). Revision 5. </p> <p>This is a fast and highly accurate numerical method for the inversion of the Laplace transform</p> Pricing Asian options using mpmath (Python) 2009-11-13T01:28:24-08:00Fernando Nieuwveldthttp://code.activestate.com/recipes/users/4172088/http://code.activestate.com/recipes/576954-pricing-asian-options-using-mpmath/ <p style="color: grey"> Python recipe 576954 by <a href="/recipes/users/4172088/">Fernando Nieuwveldt</a> (<a href="/recipes/tags/computational_finance/">computational_finance</a>, <a href="/recipes/tags/laplace/">laplace</a>, <a href="/recipes/tags/mpmath/">mpmath</a>). </p> <p>I present a numerical method for pricing Asian options. The method is based on the numerical inversion of the Laplace transform. The inversion method that is used is based on Talbot contours. It is known that Geman and Yor's formula is computational expensive for low volatility cases. By using Talbots method we can reduce the timing for the low volatility cases, at least to \sigma ~ 0.05. Afterwards the method start to converge slowly. In the literature for \sigma = 0.1 the Geman and Yor formula converges slowly.</p>