I'm trying to implement a Monte Carlo PricingEngine that stores multidimensional statistics.

I have done the following:

  1. Defined a Monte Carlo Trait that among other things stores as the path_pricer_type PathPricer<MultiPath,Array> (my process is one dimensional but has 2 factors). let's call this struct MyMCTrait.
  2. Implemented a class that derives from both McSimulation<MyMCTrait,PseudoRandom,SequenceStatistics> and VanillaOption::engine.
  3. Implemented a PathPricer<MultiPath,Array> in which the first element of the Array returned by the operator() is the price of the option.

I'm getting compiling errors because in methods value() and valueWithSamples() of class McSimulation we have the following initializations:

a. result_type(mcModel_->sampleAccumulator().mean());

b. result_type error(mcModel_->sampleAccumulator().errorEstimate());

that are trying to cast from std::vector<Real> (returned by the SequenceStatistics methods) to Array (result_type).

I doubt that the right way to go is to implement the cast (if it's possible), could anyone point me to the right direction? Thanks.


I got the Pricing Engine working by using a derived class from SequenceStatistics. I just overrode the inspectors mean() and errorEstimate() and made them return an Array. To do this I used the base class methods + the Array constructor that takes begin and end iterators.

I'm still wondering though if this is the right way to proceed. Thanks for any thoughts.


Yes, your solution is correct, given the implementation of McSimulation and the interface of SequenceStatistics. We should probably have defined SequenceStatistics as returning instances of Array...

As you might have seen, trying to return std::vector<Real> from the path pricer wouldn't work; the result type needs to define arithmetic operations such as addition and subtraction.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.