The following code generates a discretized Brownian path:
std::vector<double> brownian_path(double t, std::size_t n)
{
std::random_device rd;
std::mt19937 gen(rd());
std::normal_distribution<> dis;
std::vector<double> bm(n + 1);
auto const sqrt_dt = std::sqrt(t / n);
for (std::size_t i = 1; i <= n; ++i)
bm[i] = bm[i - 1] + sqrt_dt * dis(gen);
return bm;
}
However, it yields the same Brownian path, each time it's called. So, what do I need to do, to generate a new Brownian path at each call?
Aucun commentaire:
Enregistrer un commentaire