|
From: Jonathan S. <sw...@gm...> - 2023-09-05 12:53:12
|
Hello, 1. Could you provide a bit more info on why you want a path containing a single step? The typical use case for PathGenerator is for many steps, with the value at the first step (i.e. at t_0) being equal to the starting price. Maybe what you're looking for isn't a path, but something else. 2. It might be possible to reimplement the RNG classes using the C++11 standard library <random> header but it's a risky change in my opinion because there might be numerical differences on different platforms, which users could be sensitive to. Also in terms of Boost dependence, the only part of your code snippet that depends on boost is boost::shared_ptr, which should be replaced with QuantLib::ext::shared_ptr. None of the RNG classes in your snippet themselves depend on Boost directly. On Tue, Sep 5, 2023 at 5:53 AM U.Mutlu <um...@mu...> wrote: > 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); > ... > > > > > _______________________________________________ > QuantLib-users mailing list > Qua...@li... > https://lists.sourceforge.net/lists/listinfo/quantlib-users > |