I want to simulate some random variables distributed as a Variance Gamma.
I know the pdf ( http://en.wikipedia.org/wiki/Variance-gamma_distribution ) but I don't know the inverse of the cumulative function F: so I can't generate a random uniform variable U and compute x=F^(-1)(U).
I have to do this in MATLAB.
Thank you!
Stefano
The next natural alternative to look into is Von Neumann's "acceptance-rejection method".
If you can find a density g
defined on the same space as your f
such that
g
, and then you are good to go.
If you search the literature, people must have done this. The VG is widely used in pricing options.
Following @Drake 's idea: for the first step you can use Marsaglia and Tsang's Method from here .
This is the code to generate gamma random numbers:
function x=gamrand(alpha,lambda)
% Gamma(alpha,lambda) generator using Marsaglia and Tsang method
% Algorithm 4.33
if alpha>1
d=alpha-1/3; c=1/sqrt(9*d); flag=1;
while flag
Z=randn;
if Z>-1/c
V=(1+c*Z)^3; U=rand;
flag=log(U)>(0.5*Z^2+d-d*V+d*log(V));
end
end
x=d*V/lambda;
else
x=gamrand(alpha+1,lambda);
x=x*rand^(1/alpha);
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.