예제 #1
0
        public HaltonRsg(int dimensionality,
                         ulong seed       = 0,
                         bool randomStart = true,
                         bool randomShift = false)
        {
            dimensionality_  = dimensionality;
            sequenceCounter_ = 0;
            sequence_        = new Sample <List <double> >(new InitializedList <double>(dimensionality), 1.0);
            randomStart_     = new InitializedList <ulong>(dimensionality, 0UL);
            randomShift_     = new InitializedList <double>(dimensionality, 0.0);

            Utils.QL_REQUIRE(dimensionality > 0, () => "dimensionality must be greater than 0");

            if (randomStart || randomShift)
            {
                RandomSequenceGenerator <MersenneTwisterUniformRng> uniformRsg =
                    new RandomSequenceGenerator <MersenneTwisterUniformRng>(dimensionality_, seed);
                if (randomStart)
                {
                    randomStart_ = uniformRsg.nextInt32Sequence();
                }
                if (randomShift)
                {
                    randomShift_ = uniformRsg.nextSequence().value;
                }
            }
        }
예제 #2
0
        protected override PathPricer <IPath> pathPricer()
        {
            PlainVanillaPayoff payoff = arguments_.payoff as PlainVanillaPayoff;

            Utils.QL_REQUIRE(payoff != null, () => "non-plain payoff given");

            TimeGrid      grid      = timeGrid();
            List <double> discounts = new InitializedList <double>(grid.size());

            for (int i = 0; i < grid.size(); i++)
            {
                discounts[i] = process_.riskFreeRate().currentLink().discount(grid[i]);
            }

            // do this with template parameters?
            if (isBiased_)
            {
                return(new BiasedBarrierPathPricer(arguments_.barrierType,
                                                   arguments_.barrier,
                                                   arguments_.rebate,
                                                   payoff.optionType(),
                                                   payoff.strike(),
                                                   discounts));
            }
            else
            {
                IRNG sequenceGen = new RandomSequenceGenerator <MersenneTwisterUniformRng>(grid.size() - 1, 5);
                return(new BarrierPathPricer(arguments_.barrierType,
                                             arguments_.barrier,
                                             arguments_.rebate,
                                             payoff.optionType(),
                                             payoff.strike(),
                                             discounts,
                                             process_,
                                             sequenceGen));
            }
        }