Posted by
mike.parkerql on
Jun 07, 2004; 6:23am
URL: http://quantlib.414.s1.nabble.com/RandomNumberGenerator-tp2978p2981.html
Hopefully I'm interpreting you correctly.
I have the Glasserman book, but haven't had time to go through it in detail.
It indeed contains some things that I think you're looking for.
To paraphrase:
A d-dimensional normal distribution is characterized by a d-vector of means,u,
and a dxd covariance matrix SIGMA.
So, you want to generate random samples from N(u, SIGMA).
If (d-dimension) Z distributed N(0, I) where I is identity matrix (i.e. just
generate d independent standard normals), then apply the transformation X = u
+ A*Z, where A is some dxd matrix. Then X is distributed N(u, AA^T) where A^T
is the transpose of A.
So, the problem boils down to finding A such that AA^T = SIGMA.
If A is in lower triangular form then you reduce the number of multiplications
you need to make. This is called Cholesky factorization, and there is a simple
algorithm to find A from SIGMA.
If you want to work with correlation matrix, rather than covariance matrix
then:
If i-th component has standard deviation sigma_i, can express SIGMA in terms
of the correlation matrix rho_i_j by
SIGMA_i_j = sigma_i * rho_i_j * sigma_j
Of course, for Brownian motion, you need to ensure that covariance wrt time
scales like t-s. This is like transforming standard normals by a lower
triangular matrix which contains the terms sqrt(t_j - t_i) for i<j, zero
otherwise, which is implicit in the usual construction: W(t_j)=W(t_i)+sqrt(t_j-
t_i)*Z(t_j). Z(t_j) distributed N(0, SIGMA).
To see these things in action, then look at e.g. multipathgenerator.hpp in the
montecarlo namespace.
Mike
Quoting John Kiff <
[hidden email]>:
> Mike, thanks for that, but I was also wondering if there is something more
> fundamental that I
> should be looking at. I checked out my "Numerical Recipes" but so no obvious
> reference to
> dimensions and samples. Maybe I'm using the wrong function, in that I just
> want to generate a
> vector of random standard normals, and nothing much more than that. Anyways,
> perhaps the
> Glasserman and Jackel books go deeper into these nuances, and I have neither.
> Any opinions as to
> which will be the most helpful? John
>
> ---
[hidden email] wrote:
> > check out rngtraits.hpp and rngtypedefs.hpp
> >
> > The default pseudo random generator is Mersenne Twister Uniform generator
> with
> > inverse cumulative normal to convert to gaussian. See typedef
> PseudoRandom.
> >
> > e.g.
> > Size dim1 = 20; //sequence length.
> > long seed = 12345;
> >
> > GaussianRandomSequenceGenerator grsg =
> > PseudoRandom::make_sequence_generator(dim1, seed);
> > Sample<Array> res = grsg.nextSequence();
> > std::cout << res.value <<std::endl;
> > std::cout << std::endl;
> >
> >
> >
> > Examples of usage in e.g. mcvanillaengine.hpp
> >
> > or could try,
> > typedef GenericPseudoRandom<KnuthUniformRng,
> > InverseCumulativeNormal> fred;
> > fred::rsg_type gen = fred::make_sequence_generator(dim1, seed);
> > std::cout << gen.nextSequence().value <<std::endl;
> >
> > Also, check out random numbers namespace. Example below uses Box-Mueller
> > method of transforming uniforms into gaussians.
> >
> > BoxMullerGaussianRng<MersenneTwisterUniformRng> bm_grsg(seed);
> > for (Size sim=0; sim<10; sim++)
> > std::cout << bm_grsg.next().value << std::endl;
> >
> > BoxMullerGaussianRng<KnuthUniformRng> bm_grsg(seed); etc.
> >
> > Hope this helps
> >
> > Quoting John Kiff <
[hidden email]>:
> >
> > > Could someone please give me some pointers to where I can find out more
> about
> > > setting the key
> > > parameters of the RandomNumberGenerator function: "dimension",
> "samples",
> > > "RNGType" and "seed"?
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Friends. Fun. Try the all-new Yahoo! Messenger.
>
http://messenger.yahoo.com/
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the new InstallShield X.
> From Windows to Linux, servers to mobile, InstallShield X is the one
> installation-authoring solution that does it all. Learn more and
> evaluate today!
http://www.installshield.com/Dev2Dev/0504> _______________________________________________
> Quantlib-users mailing list
>
[hidden email]
>
https://lists.sourceforge.net/lists/listinfo/quantlib-users>
--