|
From: Luigi B. <lui...@gm...> - 2023-09-05 12:47:38
|
Hello,
the first point of the path corresponds to t=0, therefore it contains
the starting price. Passing timeSteps = 1 to the generator should give you
sample paths with 2 points, that is, the starting point and the one after
the time step.
Modernizing the code would be nice, but it must be done without breaking
backward compatibility with the current code (i.e., user code that uses
QuantLib and that compiles today should still compile with the next
version) so it's probably not worth the effort. I'd be happy to be proven
wrong, though.
Hope this helps,
Luigi
On Mon, Sep 4, 2023 at 10:54 PM 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
>
|