|
From: U.Mutlu <um...@mu...> - 2023-09-04 20:51:13
|
Hello, I've the following, possibly very old, code for generating GBM values. It practically requires that nIntervalls_in_t (ie. timeSteps) must be >= 2 b/c the first generated value always equals the passed startingPrice. Is this behavior hardcoded in QuantLib or can this be overridden via a setting or function call, so that it shall not return always the startingPrice as the first value : 2nd question is: can this code be simplified and modernized by using C++ methods of C++11, preferably w/o any Boost dependence, for example using std::normal_distribution instead of the Box-Muller kludge below? Cf. also the many distribtion types and the RNGs in C++11 at https://en.cppreference.com/w/cpp/numeric/random ... // instantiate Geometric Brownian Motion (GBM) stochastic process const auto& gbm = boost::shared_ptr<StochasticProcess>(new GeometricBrownianMotionProcess(startingPrice, drift_mu, vola_sigma)); // generate sequence of normally distributed random numbers from uniform distribution using Box-Muller transformation BigInteger seed = SeedGenerator::instance().get(); typedef BoxMullerGaussianRng<MersenneTwisterUniformRng> MersenneBoxMuller; MersenneTwisterUniformRng mersenneRng(seed); MersenneBoxMuller boxMullerRng(mersenneRng); RandomSequenceGenerator<MersenneBoxMuller> gsg(nIntervals_in_t, boxMullerRng); // generate simulated path of stock price PathGenerator<RandomSequenceGenerator<MersenneBoxMuller>> gbmPathGenerator(gbm, t, nIntervals_in_t, gsg, false); const Path& samplePath = gbmPathGenerator.next().value; for (size_t i = 1; i < nIntervals_in_t; ++i) // skipping 0th elem as it's startingPrice { const auto Sx = samplePath.at(i); ... |