[R] Bug in myintegrate in Elliptic package

Rolf Turner r.turner at auckland.ac.nz
Thu Oct 9 23:17:42 CEST 2014



(1) The example is not reproducible since we don't have "psi" or know 
what it is.

(2) The package is called "elliptic" *NOT* "Elliptic".  The R language 
(unlike Micro$oft crap) is case sensitive.

(3) The code was given in a chaotic manner, making it impossible to copy 
and paste it into an R console.

(4) That being said, it's pretty obvious what's going on.  ***Look at
the code*** for "myintegrate()".  It uses "x" as the dummy variable for
the function "f(x,...)" that is its first argument.  If you use "x" as
the name of one of the "..." arguments you wind up getting a call of
the form "f(x,x=0.1,psi_measure=psi)" --- no wonder the poor damned 
thing gets confused and gets it wrong.

Try:

    melvin <- function(x,...){x^2}
    melvin(2)
    melvin(2,x=5)

and you'll see the sort of thing that happens.

cheers,

Rolf Turner

-- 
Rolf Turner
Technical Editor ANZJS

On 10/10/14 03:30, Luis Felipe Parra wrote:
> Hello,
>
> I was using my integrate today and spend a couple of hours trying to figure
> out why I was getting some weird results in my code when using myintegrate
> function to do complex integration, after some time decided just to change
> the name of the integration dummy variable in the code from 'x' to 'y' and
> the code worked perfectly, here is the outpus of what I was using:
>
>>    #Find the CDF to find the call prices
>>    CDF_Merton = function(y,psi_measure){
> +     integrand_cdf = function(u_vec,y,psi_measure)
> Im(exp(-1i*u_vec*y)*psi_measure(u_vec))/u_vec
> +   return(1/2 -
> 1/pi*Re(myintegrate(integrand_cdf,0,100,y=y,psi_measure=psi_measure)))
> +   }
>>    CDF_Merton(y=0.1,psi_measure=psi)
> [1] 0.9368239
>
>>
>>    CDF_Merton = function(x,psi_measure){
> +     integrand_cdf = function(u_vec,x,psi_measure)
> Im(exp(-1i*u_vec*x)*psi_measure(u_vec))/u_vec
> +   return(1/2 -
> 1/pi*Re(myintegrate(integrand_cdf,0,100,x=x,psi_measure=psi_measure)))
> +   }
>>    CDF_Merton(x=0.1,psi_measure=psi)
> [1] 59.03344
>
> where you can see that both codes are exactly the same except for the dummy
> variable used to integrate, does any body know what might be going on here?



More information about the R-help mailing list