예제 #1
0
        /*! Returns an approximation of the covariance defined as
         *  \f$ \sigma(t_0, \mathbf{x}_0)^2 \Delta t \f$. */
        public Matrix covariance(StochasticProcess process, double t0, Vector x0, double dt)
        {
            Matrix sigma  = process.diffusion(t0, x0);
            Matrix result = sigma * Matrix.transpose(sigma) * dt;

            return(result);
        }
예제 #2
0
        // constructor
        public MCLookbackEngine(GeneralizedBlackScholesProcess process,
                                int?timeSteps,
                                int?timeStepsPerYear,
                                bool brownianBridge,
                                bool antitheticVariate,
                                int?requiredSamples,
                                double?requiredTolerance,
                                int?maxSamples,
                                ulong seed)
            : base(antitheticVariate, false)
        {
            process_           = process;
            timeSteps_         = timeSteps;
            timeStepsPerYear_  = timeStepsPerYear;
            requiredSamples_   = requiredSamples;
            maxSamples_        = maxSamples;
            requiredTolerance_ = requiredTolerance;
            brownianBridge_    = brownianBridge;
            seed_ = seed;

            Utils.QL_REQUIRE(timeSteps != null || timeStepsPerYear != null, () => "no time steps provided");
            Utils.QL_REQUIRE(timeSteps == null || timeStepsPerYear == null, () =>
                             "both time steps and time steps per year were provided");
            if (timeSteps != null)
            {
                Utils.QL_REQUIRE(timeSteps > 0, () => "timeSteps must be positive, " + timeSteps + " not allowed");
            }
            if (timeStepsPerYear != null)
            {
                Utils.QL_REQUIRE(timeStepsPerYear > 0, () =>
                                 "timeStepsPerYear must be positive, " + timeStepsPerYear + " not allowed");
            }

            process_.registerWith(update);
        }
예제 #3
0
 // constructors
 public PathGenerator(StochasticProcess process, double length, int timeSteps, GSG generator, bool brownianBridge)
 {
     brownianBridge_ = brownianBridge;
     generator_      = generator;
     dimension_      = generator_.dimension();
     timeGrid_       = new TimeGrid(length, timeSteps);
     process_        = process as StochasticProcess1D;
     next_           = new Sample <IPath>(new Path(timeGrid_), 1.0);
     temp_           = new InitializedList <double>(dimension_);
     bb_             = new BrownianBridge(timeGrid_);
     Utils.QL_REQUIRE(dimension_ == timeSteps, () =>
                      "sequence generator dimensionality (" + dimension_ + ") != timeSteps (" + timeSteps + ")");
 }
예제 #4
0
 protected MCVanillaEngine(StochasticProcess process,
                           int?timeSteps,
                           int?timeStepsPerYear,
                           bool brownianBridge,
                           bool antitheticVariate,
                           bool controlVariate,
                           int?requiredSamples,
                           double?requiredTolerance,
                           int?maxSamples,
                           ulong seed)
     : base(process, timeSteps, timeStepsPerYear, brownianBridge, antitheticVariate, controlVariate, requiredSamples,
            requiredTolerance, maxSamples, seed)
 {
 }
예제 #5
0
 protected MCLongstaffSchwartzEngine(StochasticProcess process,
                                     int?timeSteps,
                                     int?timeStepsPerYear,
                                     bool brownianBridge,
                                     bool antitheticVariate,
                                     bool controlVariate,
                                     int?requiredSamples,
                                     double?requiredTolerance,
                                     int?maxSamples,
                                     ulong seed,
                                     int nCalibrationSamples) :
     base(process, timeSteps, timeStepsPerYear, brownianBridge, antitheticVariate, controlVariate,
          requiredSamples, requiredTolerance, maxSamples, seed, nCalibrationSamples)
 {
 }
예제 #6
0
        public DiscretizedVanillaOption(VanillaOption.Arguments args, StochasticProcess process, TimeGrid grid)
        {
            arguments_ = args;

            stoppingTimes_ = new InitializedList <double>(args.exercise.dates().Count);
            for (int i = 0; i < stoppingTimes_.Count; ++i)
            {
                stoppingTimes_[i] = process.time(args.exercise.date(i));
                if (!grid.empty())
                {
                    // adjust to the given grid
                    stoppingTimes_[i] = grid.closestTime(stoppingTimes_[i]);
                }
            }
        }
예제 #7
0
        public MultiPathGenerator(StochasticProcess process, TimeGrid times, GSG generator, bool brownianBridge)
        {
            brownianBridge_ = brownianBridge;
            process_        = process;
            generator_      = generator;
            next_           = new Sample <IPath>(new MultiPath(process.size(), times), 1.0);

            Utils.QL_REQUIRE(generator_.dimension() == process.factors() * (times.size() - 1), () =>
                             "dimension (" + generator_.dimension()
                             + ") is not equal to ("
                             + process.factors() + " * " + (times.size() - 1)
                             + ") the number of factors "
                             + "times the number of time steps");
            Utils.QL_REQUIRE(times.size() > 1, () => "no times given");
        }
        public DiscretizedBarrierOption(BarrierOption.Arguments args, StochasticProcess process, TimeGrid grid = null)
        {
            arguments_ = args;
            vanilla_   = new DiscretizedVanillaOption(arguments_, process, grid);

            Utils.QL_REQUIRE(args.exercise.dates().Count > 0, () => "specify at least one stopping date");

            stoppingTimes_ = new InitializedList <double>(args.exercise.dates().Count);
            for (int i = 0; i < stoppingTimes_.Count; ++i)
            {
                stoppingTimes_[i] = process.time(args.exercise.date(i));
                if (grid != null && !grid.empty())
                {
                    // adjust to the given grid
                    stoppingTimes_[i] = grid.closestTime(stoppingTimes_[i]);
                }
            }
        }
 public DiscretizedDermanKaniBarrierOption(BarrierOption.Arguments args,
                                           StochasticProcess process, TimeGrid grid = null)
 {
     unenhanced_ = new DiscretizedBarrierOption(args, process, grid);
 }
예제 #10
0
 /*! Returns an approximation of the diffusion defined as
  *  \f$ \sigma(t_0, \mathbf{x}_0) \sqrt{\Delta t} \f$. */
 public Matrix diffusion(StochasticProcess process, double t0, Vector x0, double dt)
 {
     return(process.diffusion(t0, x0) * Math.Sqrt(dt));
 }
예제 #11
0
 /*! Returns an approximation of the drift defined as
  *  \f$ \mu(t_0, \mathbf{x}_0) \Delta t \f$. */
 public Vector drift(StochasticProcess process, double t0, Vector x0, double dt)
 {
     return(process.drift(t0, x0) * dt);
 }