|
From: Jonathan S. <sw...@gm...> - 2023-09-07 12:08:07
|
Hi David,
I think what you should do is implement IIDPathGenerator with the same
public interface as PathGenerator but without inheriting from it, and then
define your own MC traits like so:
template <class RNG = PseudoRandom>
struct IIDSingleVariate {
typedef RNG rng_traits;
typedef Path path_type;
typedef PathPricer<path_type> path_pricer_type;
typedef typename RNG::rsg_type rsg_type;
typedef IIDPathGenerator<rsg_type> path_generator_type;
enum { allowsErrorEstimate = RNG::allowsErrorEstimate };
};
Then you can use those traits when setting up the McSimulation like so:
typedef IIDSingleVariate<LowDiscrepancy>::path_generator_type
generator_type;
MonteCarloModel<IIDSingleVariate, LowDiscrepancy>
McSimulation(myPathGenerator, myPathPricer, statisticsAccumulator, false);
I haven't tested this but hope it helps.
On Thu, Aug 31, 2023 at 11:56 PM David Klein <dk...@gm...> wrote:
> I would like to run a MC simulation, something like:
> ext::shared_ptr<StochasticProcess1D> diffusion(new
> GeometricBrownianMotionProcess(1.0, 0.0, sigma_));
> LowDiscrepancy::rsg_type RSG =
> LowDiscrepancy::make_sequence_generator(nTimeSteps, seed);
> typedef SingleVariate<LowDiscrepancy>::path_generator_type
> generator_type;
> ext::shared_ptr<generator_type> myPathGenerator(new
> generator_type(diffusion, T, nTimeSteps, RSG, brownianBridge));
> MonteCarloModel<SingleVariate,
> LowDiscrepancy>McSimulation(myPathGenerator, myPathPricer,
> statisticsAccumulator, false);
> McSimulation.addSamples(nSamples);
>
> But instead of using a GeometricBrownianMotionProcess I just want a simple
> IID process. I managed to fake it out by setting my time steps to be of
> length 1 and then defining a StochasticProcess1D where the drift term is
> drift(t, x) = -x. Ugly kludge.
>
> Instead I tried to define my own IIDPathGenerator as a derived class from
> PathGenerator in a way that would allow me to define IID paths (the term
> "path" is obviously a misnomer in this case). But this doesn't work since
> the "next()" method of PathGenerator isn't virtual, so when I pass it as an
> argument to MCSimulation the base class's "next()" method is called.
>
> Note: I am a total newbie to QuantLib and my C++ is rusty, so please be
> patient...
>
> Thanks,
>
> David Klein
> _______________________________________________
> QuantLib-users mailing list
> Qua...@li...
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>
|