示例#1
0
        //! basic calculate method provided to inherited pricing engines
        public void calculate(double requiredTolerance, int requiredSamples, int maxSamples)
        {
            if (!(requiredTolerance != 0 || requiredSamples != 0))
            {
                throw new ApplicationException("neither tolerance nor number of samples set");
            }

            //! Initialize the one-factor Monte Carlo
            if (this.controlVariate_)
            {
                double controlVariateValue = this.controlVariateValue();
                if (controlVariateValue == 0)
                {
                    throw new ApplicationException("engine does not provide control-variation price");
                }

                PathPricer <IPath> controlPP = this.controlPathPricer();
                if (controlPP == null)
                {
                    throw new ApplicationException("engine does not provide control-variation path pricer");
                }

                PathGenerator <IRNG> controlPG = this.controlPathGenerator();

                this.mcModel_ = new MonteCarloModel <MC, RNG, S>(pathGenerator(), pathPricer(), new S(), antitheticVariate_,
                                                                 controlPP, controlVariateValue, controlPG);
            }
            else
            {
                this.mcModel_ = new MonteCarloModel <MC, RNG, S>(pathGenerator(), pathPricer(), new S(), antitheticVariate_);
            }

            if (requiredTolerance != 0)
            {
                if (maxSamples != 0)
                {
                    value(requiredTolerance, maxSamples);
                }
                else
                {
                    value(requiredTolerance);
                }
            }
            else
            {
                valueWithSamples(requiredSamples);
            }
        }
示例#2
0
 public MonteCarloModel(PathGenerator <IRNG> pathGenerator, PathPricer <IPath> pathPricer, S sampleAccumulator,
                        bool antitheticVariate, PathPricer <IPath> cvPathPricer, double cvOptionValue,
                        PathGenerator <IRNG> cvPathGenerator)
 {
     pathGenerator_       = pathGenerator;
     pathPricer_          = pathPricer;
     sampleAccumulator_   = sampleAccumulator;
     isAntitheticVariate_ = antitheticVariate;
     cvPathPricer_        = cvPathPricer;
     cvOptionValue_       = cvOptionValue;
     cvPathGenerator_     = cvPathGenerator;
     if (cvPathPricer_ == null)
     {
         isControlVariate_ = false;
     }
     else
     {
         isControlVariate_ = true;
     }
 }
示例#3
0
 // constructor
 //public MonteCarloModel(PathGenerator<IRNG> pathGenerator, IPathPricer<Path> pathPricer, S sampleAccumulator,
 //          bool antitheticVariate,
 //          IPathPricer<Path> cvPathPricer = boost::shared_ptr<path_pricer_type>(),
 //          result_type cvOptionValue = result_type(),
 //          PathGenerator<IRNG> cvPathGenerator = path_generator_type()) {
 public MonteCarloModel(PathGenerator <IRNG> pathGenerator, PathPricer <IPath> pathPricer, S sampleAccumulator,
                        bool antitheticVariate)
     : this(pathGenerator, pathPricer, sampleAccumulator, antitheticVariate, null, 0, null)
 {
 }