|
From: <ni...@bi...> - 2003-05-14 20:46:03
|
Hi again
There is a small problem with the random number generator. When a Rng is
constructed, it initialises the generator with a seed based on the current
time. However, (at least in VC++) the resolution of the timer is only one
second. This means that the same sequence of random numbers will be
generated.
Normally, this is not a problem, as e.g. the PathGenerator next() method
will not be reseeded with the same seed. But the problems shows, when
PathGenerator is called repeatedly from an external program.
My particular program is in the QuantLibMma extension, where the following
code will give 5 identical paths.
model = BlackScholesModel[100, 0.10, 0.01, 0.15];
Table[MonteCarloPath[model, 1, 20], {5}]
Does anyone know how to solve this problem? Is there a seed with a higher
resolution the QL_TIME?
Cheers... Niels
|
|
From: <ma...@ni...> - 2003-05-14 20:28:45
|
Hi again
There is a small problem with the random number generator. When a Rng is
constructed, it initialises the generator with a seed based on the current
time. However, (at least in VC++) the resolution of the timer is only one
second. This means that the same sequence of random numbers will be
generated.
Normally, this is not a problem, as e.g. the PathGenerator next() method
will not be reseeded with the same seed. But the problems shows, when
PathGenerator is called repeatedly from an external program.
My particular program is in the QuantLibMma extension, where the following
code will give 5 identical paths.
model = BlackScholesModel[100, 0.10, 0.01, 0.15];
Table[MonteCarloPath[model, 1, 20], {5}]
Does anyone know how to solve this problem? Is there a seed with a higher
resolution the QL_TIME?
Cheers... Niels
|
|
From: Jens T. <Je...@Th...> - 2003-05-14 22:22:07
|
Hi,
Some quick ideas here:
- use high-resolution performance counters (QueryPerformanceCounter)
- use GUIDs (eg. CoCreateGuid) to get some 128 unique bits
- use a master RNG to deliver seeds (use a different alg. here)
- get a seed only once, and reseed with (++seed)
The last one may be the most portable and efficient...
Jens.
-----Original Message-----
From: qua...@li...
[mailto:qua...@li...] On Behalf Of Niels =
Elken
S=F8nderby
Sent: Wednesday, May 14, 2003 10:49 PM
To: QuantLib-dev
Subject: [Quantlib-dev] Problem with random seed
Hi again
There is a small problem with the random number generator. When a Rng is
constructed, it initialises the generator with a seed based on the =
current
time. However, (at least in VC++) the resolution of the timer is only =
one
second. This means that the same sequence of random numbers will be
generated.
Normally, this is not a problem, as e.g. the PathGenerator next() method
will not be reseeded with the same seed. But the problems shows, when
PathGenerator is called repeatedly from an external program.
My particular program is in the QuantLibMma extension, where the =
following
code will give 5 identical paths.
model =3D BlackScholesModel[100, 0.10, 0.01, 0.15];
Table[MonteCarloPath[model, 1, 20], {5}]
Does anyone know how to solve this problem? Is there a seed with a =
higher
resolution the QL_TIME?
Cheers... Niels
-------------------------------------------------------
Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara =
The
only event dedicated to issues related to Linux enterprise solutions
www.enterpriselinuxforum.com
_______________________________________________
Quantlib-dev mailing list
Qua...@li...
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
|
|
From: Luigi B. <lui...@fa...> - 2003-05-15 07:44:36
|
At 12:21 AM 5/15/03 +0200, Jens Thiel wrote:
>Some quick ideas here:
>
>- use high-resolution performance counters (QueryPerformanceCounter)
>- use GUIDs (eg. CoCreateGuid) to get some 128 unique bits
>- use a master RNG to deliver seeds (use a different alg. here)
>- get a seed only once, and reseed with (++seed)
Another quick one:
- Use a global RNG, instead of creating one each time you call MonteCarloPath.
Write another function to reinitialize it with a given seed if one wants to
do so.
This would also make your simulations more akin to what's usually
done---i.e., create a RNG, and make paths by using successive draws from
that one RNG. I don't think there's many people around reinitializing the
generator for each path.
Bye,
Luigi
|
|
From: <enr...@ri...> - 2003-05-15 08:30:20
|
>>>>> "Gigi" == Luigi Ballabio <lui...@fa...> writes:
>> - use high-resolution performance counters
>> (QueryPerformanceCounter) - use GUIDs (eg. CoCreateGuid) to get
>> some 128 unique bits - use a master RNG to deliver seeds (use a
>> different alg. here) - get a seed only once, and reseed with
>> (++seed)
Gigi> Another quick one:
Gigi> - Use a global RNG, instead of creating one each time you
Gigi> call MonteCarloPath. Write another function to reinitialize
Gigi> it with a given seed if one wants to do so.
Gigi> This would also make your simulations more akin to what's
Gigi> usually done---i.e., create a RNG, and make paths by using
Gigi> successive draws from that one RNG. I don't think there's
Gigi> many people around reinitializing the generator for each
Gigi> path.
The problem of using different independent RNG is typical in parallel
montecarlo applications, and using two different RNG algorithms (one
for generating seeds and one for generating paths) is a known
solution. One known approach is the "Lagged Fibonacci" method (try a
search with google and you'll find some implementations), anyway you
don't get generators with a huge period (I think something like 10E4 -
10E5) for the paths.
On the other side, using only one generator for generating all the
paths could not scale in the number of paths, anyway you could use a
very high period RNG (the mersenne-twister, which have a huge
period would probably fit financial applications needs).
The Mersenne-Twister inventors released a mersenne-twister variant
suitable for parallel montecarlo applications, anyway its code is GPL
so, unfortunately, impossible to include in QL. I can't remember the
authors' site URL (again, a google search should lead you there).
I hope this helps,
Enrico
--
Enrico Sirola <enr...@ri...>
"Random generators should noy be chosen at random" - D. Knuth
|
|
From: Ferdinando A. <fer...@am...> - 2003-05-15 08:50:16
|
Hi Enrico >The Mersenne-Twister inventors released a mersenne-twister variant >suitable for parallel montecarlo applications, anyway its code is GPL >so, unfortunately, impossible to include in QL. I can't remember the >authors' site URL (again, a google search should lead you there). are you sure? I've just checked http://www.math.keio.ac.jp/matumoto/emt.html and since april 2001 the code of MT is licensed under BSD. Besides I miss the variant for parallel Monte Carlo. Any direction is appreciated ------------ ciao -- Nando PS this thread started here on quantlib-dev and it might be too late to switch to quantlib-users. anyway whenever possible I would appreciate if such discussion would happen on quantlib-users since i do trust a larger audience could contribute useful suggestions. Let's keep quantlib-dev as back-channel for discussion we don't want to be public, as confessing ignorance or difficulties with stochastic calculus ;-) |
|
From: <enr...@ri...> - 2003-05-20 12:10:59
|
for ql-users subscribers: this is a follow-up to a discussion going on
on ql-dev... It could be of broader interest so nando suggested to
switch. here we go:
>>>>> "Nando" == Ferdinando Ametrano <fer...@am...> writes:
Nando> Hi Enrico
>> The Mersenne-Twister inventors released a mersenne-twister
>> variant suitable for parallel montecarlo applications, anyway
>> its code is GPL so, unfortunately, impossible to include in
>> QL. I can't remember the authors' site URL (again, a google
>> search should lead you there).
Nando> are you sure? I've just checked
Nando> http://www.math.keio.ac.jp/matumoto/emt.html and since
Nando> april 2001 the code of MT is licensed under BSD. Besides I
Nando> miss the variant for parallel Monte Carlo. Any direction is
Nando> appreciated
Yes, MT is BSD, but their dynamic creation code is LGPL. Please see
the content of the package at
http://www.math.h.kyoto-u.ac.jp/~matumoto/RAND/DC/dc.html
Nando> PS this thread started here on quantlib-dev and it might be
Nando> too late to switch to quantlib-users. anyway whenever
Nando> possible I would appreciate if such discussion would happen
Nando> on quantlib-users since i do trust a larger audience could
Nando> contribute useful suggestions. Let's keep quantlib-dev as
Nando> back-channel for discussion we don't want to be public, as
Nando> confessing ignorance or difficulties with stochastic
Nando> calculus ;-)
ok, this isn't related to stochastic calculus so i think i can
crosspost ;-)
ciao ciao
enrico
--
Enrico Sirola <enr...@ri...>
gpg public key available from www.keyserver.net, Key ID 0x377FE07F
Key fingerprint = B446 7332 ED55 BC68 5FE8 DE0F 98DF EC86 377F E07F
|