I am trying to create a function that returns two correlated random numbers. here is my RNG function:
float simulation::RANDOM_G(float mean, float std) // RNG for GBM & GARCH
{
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); // using internal clock to create seed for RNG
static std::mt19937_64 generator(seed); // 64 bit Mersenne Twister pseudo-random generator
std::normal_distribution<float> RAND(mean, std);
rand = RAND(generator);
return rand;
}
and here is the function that I have written for returning two random correlated numbers.*rnum is a class member in the header file.
float simulation::RANDOM_H(float mean, float std)
{
if (-1.0 <= rho && rho <= 1.0)
{
if (sigmaX > 0.0 && sigmaY > 0.0)
{
float x = *rnum;
float y = *rnum;
y = rho * x * sqrt(1.0 - pow(rho, 2)) *y;
this->cor_randx = muX + sigmaX * x;
this->cor_randy = muY + sigmaY * y;
return (cor_randx,cor_randy);
}
}
}
Aucun commentaire:
Enregistrer un commentaire