Tolga Uzuner
2005-Apr-14 23:33 UTC
[R] Inverse of the Laplace Transform/Gaver Stehfest algorithm
Hi there, Is there an implementation of the Gaveh Stehfest algorithm in R somewhere ? Or some other inversion ? Thanks, Tolga
Tolga Uzuner
2005-Apr-16 16:54 UTC
[R] Re: Inverse of the Laplace Transform/Gaver Stehfest algorithm
Tolga Uzuner wrote:> Hi there, > > Is there an implementation of the Gaveh Stehfest algorithm in R > somewhere ? Or some other inversion ? > > Thanks, > Tolga >Well, at least here is Zakian's algorithm, for anyone who needs it: Zakian<-function(Fs,t){ # Fs is the function to be inverted and evaluated at t a = c(12.83767675+1.666063445i, 12.22613209+5.012718792i,10.93430308+8.409673116i, 8.776434715+11.92185389i,5.225453361+15.72952905i) K = c(-36902.08210+196990.4257i, 61277.02524-95408.62551i,-28916.56288+18169.18531i, +4655.361138-1.901528642i,-118.7414011-141.3036911i) ssum = 0.0 # Zakian's method does not work for t=0. Check that out. if(t == 0){ print("ERROR: Inverse transform can not be calculated for t=0") print("WARNING: Routine zakian() exiting.") return("Error")} # The for-loop below is the heart of Zakian's Inversion Algorithm. for(j in 1:5){ssum = ssum + Re(K[j]*Fs(a[j]/t))} return (2.0*ssum/t) } # InvLap(1/(s-1))=exp(t) # check if Zakian(function(s){1/(s-1)},1)==exp(1) lapfunc<-function(s){1.0/(s-1.0)} # Function Zakian(functobeinverted,t) is invoked. Zakian(lapfunc,1.0)
How do I suppress the following ? Warning messages: 1: the condition has length > 1 and only the first element will be used in: if (strike == forward) atmvol(forward, t, alpha, beta, rho, upsilon) else { 2: the condition has length > 1 and only the first element will be used in: if (x(z) == 0) 1 else z/x(z)
Tolga Uzuner wrote:> How do I suppress the following ? > > Warning messages: > 1: the condition has length > 1 and only the first element will be used > in: if (strike == forward) atmvol(forward, t, alpha, beta, rho, upsilon) > else { > 2: the condition has length > 1 and only the first element will be used > in: if (x(z) == 0) 1 else z/x(z) > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > >Maybe better to understand what generates the warning! To assure you are uninformed, say options(warn=-1) Kjetil -- Kjetil Halvorsen. Peace is the most effective weapon of mass construction. -- Mahdi Elmandjra -- No virus found in this outgoing message. Checked by AVG Anti-Virus.
On 5/15/05, Tolga Uzuner <tolga at coubros.com> wrote:> How do I suppress the following ? > > Warning messages: > 1: the condition has length > 1 and only the first element will be used > in: if (strike == forward) atmvol(forward, t, alpha, beta, rho, upsilon) > else { > 2: the condition has length > 1 and only the first element will be used > in: if (x(z) == 0) 1 else z/x(z)Check out ?suppressWarnings
Kjetil Brinchmann Halvorsen wrote:> Tolga Uzuner wrote: > >> How do I suppress the following ? >> >> Warning messages: >> 1: the condition has length > 1 and only the first element will be used >> in: if (strike == forward) atmvol(forward, t, alpha, beta, rho, upsilon) >> else { >> 2: the condition has length > 1 and only the first element will be used >> in: if (x(z) == 0) 1 else z/x(z) >> >> ______________________________________________ >> R-help at stat.math.ethz.ch mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide! >> http://www.R-project.org/posting-guide.html >> >> >> > Maybe better to understand what generates the warning!Yes! In both cases you should really look why you are using *conditions of length > 1*! And if this is intended, you certainly want to use "ifelse()" rather than "if(){} else{}". Uwe Ligges> To assure you are uninformed, say > options(warn=-1) > > Kjetil >
>>>>> "UweL" == Uwe Ligges <ligges at statistik.uni-dortmund.de> >>>>> on Sun, 15 May 2005 16:41:22 +0200 writes:UweL> Kjetil Brinchmann Halvorsen wrote: >> Tolga Uzuner wrote: >> >>> How do I suppress the following ? >>> >>> Warning messages: 1: the condition has length > 1 and >>> only the first element will be used in: if (strike = >>> forward) atmvol(forward, t, alpha, beta, rho, upsilon) >>> else { 2: the condition has length > 1 and only the >>> first element will be used in: if (x(z) == 0) 1 else >>> z/x(z) >>> >>> ______________________________________________ >>> R-help at stat.math.ethz.ch mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do >>> read the posting guide! >>> http://www.R-project.org/posting-guide.html >>> >>> >>> >> Maybe better to understand what generates the warning! UweL> Yes! In both cases you should really look why you are UweL> using *conditions of length > 1*! yes, indeed! This is a bug almost always (my subjective probability : 0.995) Maybe you want to use if(any(...)) or if(all(...)) instead of the current if(...) UweL> And if this is intended, you certainly want to use "ifelse()" rather UweL> than "if(){} else{}". (from my above guess, the probability for this would be about 1:200) Martin >> To assure you are uninformed, say options(warn=-1) >> >> Kjetil