コード例 #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);

            if (!(dimensionality > 0))
            {
                throw new ArgumentException("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
ファイル: rngtraits.cs プロジェクト: jmptrader/QLNet-1
        // factory
        public object make_sequence_generator(int dimension, ulong seed)
        {
            RandomSequenceGenerator <URNG> g = new RandomSequenceGenerator <URNG>(dimension, seed);

            return(icInstance != null ? new InverseCumulativeRsg <RandomSequenceGenerator <URNG>, IC>(g, icInstance)
                                       : new InverseCumulativeRsg <RandomSequenceGenerator <URNG>, IC>(g));
        }
コード例 #3
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));
            }
        }