Beispiel #1
0
        private Sample <IPath> next(bool antithetic)
        {
            Sample <List <double> > sequence_ =
                antithetic
            ? generator_.lastSequence()
            : generator_.nextSequence();

            if (brownianBridge_)
            {
                bb_.transform(sequence_.value, temp_);
            }
            else
            {
                temp_ = new List <double>(sequence_.value);
            }

            next_.weight = sequence_.weight;

            Path path = (Path)next_.value;

            path.setFront(process_.x0());

            for (int i = 1; i < path.length(); i++)
            {
                double t  = timeGrid_[i - 1];
                double dt = timeGrid_.dt(i - 1);
                path[i] = process_.evolve(t, path[i - 1], dt,
                                          antithetic
                                      ? -temp_[i - 1]
                                      : temp_[i - 1]);
            }
            return(next_);
        }
        public FdmSimpleProcess1DMesher(int size,
                                        StochasticProcess1D process,
                                        double maturity, int tAvgSteps = 10,
                                        double epsilon        = 0.0001,
                                        double?mandatoryPoint = null)
            : base(size)
        {
            locations_ = new InitializedList <double>(locations_.Count, 0.0);
            for (int l = 1; l <= tAvgSteps; ++l)
            {
                double t = (maturity * l) / tAvgSteps;

                double mp = (mandatoryPoint != null) ? mandatoryPoint.Value
                                                 : process.x0();

                double qMin = Math.Min(Math.Min(mp, process.x0()),
                                       process.evolve(0, process.x0(), t,
                                                      new InverseCumulativeNormal().value(epsilon)));
                double qMax = Math.Max(Math.Max(mp, process.x0()),
                                       process.evolve(0, process.x0(), t,
                                                      new InverseCumulativeNormal().value(1 - epsilon)));

                double dp = (1 - 2 * epsilon) / (size - 1);
                double p  = epsilon;
                locations_[0] += qMin;

                for (int i = 1; i < size - 1; ++i)
                {
                    p             += dp;
                    locations_[i] += process.evolve(0, process.x0(), t,
                                                    new InverseCumulativeNormal().value(p));
                }
                locations_[locations_.Count - 1] += qMax;
            }
            locations_ = locations_.Select(x => x / tAvgSteps).ToList();
            for (int i = 0; i < size - 1; ++i)
            {
                dminus_[i + 1] = dplus_[i] = locations_[i + 1] - locations_[i];
            }

            dplus_[dplus_.Count - 1] = null;
            dminus_[0] = null;
        }