Login  Register

Re: RandomNumberGenerator

Posted by mike.parkerql on Jun 09, 2004; 5:46am
URL: http://quantlib.414.s1.nabble.com/RandomNumberGenerator-tp2978p2983.html

Yeah, never trust an implementation of a random number generator unless you
can verify its properties. I don't know how good or bad Excel Rand() is, but I
was told that its cycle length/period is something around 13 million, compared
to 2^Huge for Mersenne + 623 equi-distributed.

I've used QuantLibXL and XLW, and it's easy to implement - just follow the
examples ....
I did have a problem with it going to calculation mode as soon as the final
piece of data is put into the wizard (i.e. before clicking OK on the wizard),
but that's about it.
I'm not sure, but maybe the QuantLibXL has an rng already implemented?

You may also like to compare values with NTRand (search the net).

Have fun! And if you can contribute to the development of QuantLib, then come
on and join the party!

BTW, you always mentioned normal random variates rather than Brownian random
variates. Don't forget (forgive me if I'm stating the obvious) the sqrt(t-s)
bits in the latter.

Mike

Quoting John Kiff <[hidden email]>:

> Actually Mike, your answer goes beyond my question, albeit in a very
> interesting way. I am indeed
> trying to simulate correlated Gaussian random numbers, but I'm doing it the
> long winded way. That
> is, I have been generating uncorrelated simple random numbers [0,1] using the
> Excel RAND(0)
> function, and multiplying this vector by the matrix created via the Cholesky
> factorization of the
> correlation matrix, etc. From what you've told me QuantLib has a nice way of
> accomplishing most of
> what takes me a number of steps in one step.
>
> However, I'm quite satisfied to plod along for now, for pedagogic reasons, so
> I was just looking
> for a better RAND(). I thought that RandomNumberGenerator() was just that,
> but I'm thrown by the
> need for specifying not only a seed, but also an RNGType, "dimension" and
> "samples". I figure that
> "RNGType", which appears to be numeric value, corresponds to some numbering
> scheme that specifies
> a particular generator (e.g., Mersenne Twister) but I can't find the legend.
> However, if my need
> is to produce a single random number [0,1] I can't figure out where
> "dimension" and "samples"
> comes in.
>
> BTW, I think that QuantLib, and particularly QuantLibXL, looks like a very
> promising structure. I
> work in the risk management area at a G-10 central bank, and I'm particularly
> interested in using
> open source software to develop central-bank-specific trading and risk
> management software. Other
> central banks are interested, although they are tending to lean in favour of
> using MatLab as the
> foundation. I'm hoping I can drum up some support to set out in a very
> different direction, and I
> think that QuantLib could be part of that "road".
>
> John
>
> --- [hidden email] wrote:
> > 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.
>
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Friends.  Fun.  Try the all-new Yahoo! Messenger.
> http://messenger.yahoo.com/ 
>


--