Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
 public MonteCarloModel(IPathGenerator <IRNG> pathGenerator, PathPricer <IPath> pathPricer,
                        S sampleAccumulator, bool antitheticVariate, PathPricer <IPath> cvPathPricer = null,
                        double cvOptionValue = 0, IPathGenerator <IRNG> cvPathGenerator = null)
 {
     pathGenerator_       = pathGenerator;
     pathPricer_          = pathPricer;
     sampleAccumulator_   = sampleAccumulator;
     isAntitheticVariate_ = antitheticVariate;
     cvPathPricer_        = cvPathPricer;
     cvOptionValue_       = cvOptionValue;
     cvPathGenerator_     = cvPathGenerator;
     if (cvPathPricer_ == null)
     {
         isControlVariate_ = false;
     }
     else
     {
         isControlVariate_ = true;
     }
 }
Ejemplo n.º 3
0
        //! basic calculate method provided to inherited pricing engines
        public void calculate(double?requiredTolerance, int?requiredSamples, int?maxSamples)
        {
            Utils.QL_REQUIRE(requiredTolerance != null ||
                             requiredSamples != null, () => "neither tolerance nor number of samples set");

            //! Initialize the one-factor Monte Carlo
            if (this.controlVariate_)
            {
                double?controlVariateValue = this.controlVariateValue();
                Utils.QL_REQUIRE(controlVariateValue != null, () => "engine does not provide control-variation price");

                PathPricer <IPath> controlPP = this.controlPathPricer();
                Utils.QL_REQUIRE(controlPP != null, () => "engine does not provide control-variation path pricer");

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

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

            if (requiredTolerance != null)
            {
                if (maxSamples != null)
                {
                    value(requiredTolerance.Value, maxSamples.Value);
                }
                else
                {
                    value(requiredTolerance.Value);
                }
            }
            else
            {
                valueWithSamples(requiredSamples.GetValueOrDefault());
            }
        }
Ejemplo n.º 4
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)
 {
 }