当前位置: 首页>>代码示例>>C++>>正文


C++ TimeGrid::size方法代码示例

本文整理汇总了C++中TimeGrid::size方法的典型用法代码示例。如果您正苦于以下问题:C++ TimeGrid::size方法的具体用法?C++ TimeGrid::size怎么用?C++ TimeGrid::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TimeGrid的用法示例。


在下文中一共展示了TimeGrid::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: MultiPath

PathGeneratorFactory::PathGeneratorFactory(const boost::shared_ptr<StochasticProcessArray>& processes,
										   const TimeGrid& timeGrid)
: processes_(processes), grid_(timeGrid)
{
	unsigned long myseed = static_cast<unsigned long>(1);
	rand_ = std::tr1::mt19937(myseed);

	this->numAssets_ = processes->size();
	this->pathSize_ = timeGrid.size();

	PseudoRandom::rsg_type gen =
		PseudoRandom::make_sequence_generator(numAssets_*(timeGrid.size()-1),1);

	gen_ = boost::shared_ptr<MultiVariate<PseudoRandom>::path_generator_type>(new MultiVariate<PseudoRandom>::path_generator_type(processes,
                                timeGrid, gen, false));
				
	this->next_ = MultiPath(numAssets_,this->grid_);

	S0_ = std::valarray<double>(numAssets_);
	randArrs_ = std::valarray<double>(numAssets_);

	//this->testRandom_ = Array(numAssets_ * pathSize_);
	previousRand_ = Matrix(numAssets_, pathSize_);

	Matrix corr = processes->correlation();
	chol_=CholeskyDecomposition(corr);

	random_ = MultiPath(numAssets_,timeGrid);

	// num - 1
	this->muGrid_ = Matrix(numAssets_, timeGrid.size() - 1);
	this->volGrid_ = Matrix(numAssets_,timeGrid.size() - 1);

	antitheticFlag_ = false;

	for (Size asset = 0 ; asset<numAssets_ ;++asset)
	{
		//초기화 수익률 or 절대값
		S0_[asset] = processes->process(asset)->x0() / processes->process(asset)->basePrice();

		for (Size t = 0 ; t < pathSize_ - 1 ;++t)
		{
			double mu_t = processes->process(asset)->drift(timeGrid[t],1.0);
			double sigma_t = processes->process(asset)->diffusion(timeGrid[t],1.0);
			double dt_t = timeGrid.dt(t);

			// exp( ( mu[t] - 0.5 * vol[t] * vol[t] ) * dt[t] )
			muGrid_[asset][t] = std::exp( ( mu_t - 0.5 * sigma_t * sigma_t ) * dt_t );

			//  vol[t] * sqrt(dt[t]) 
			volGrid_[asset][t] = sigma_t * std::sqrt(dt_t);
		}

	}
}
开发者ID:minikie,项目名称:OTCDerivativesCalculatorModule,代码行数:55,代码来源:PathGeneratorFactory_backup.cpp

示例2: phi

    boost::shared_ptr<Lattice> HullWhite::tree(const TimeGrid& grid) const {

        TermStructureFittingParameter phi(termStructure());
        boost::shared_ptr<ShortRateDynamics> numericDynamics(
                                             new Dynamics(phi, a(), sigma()));
        boost::shared_ptr<TrinomialTree> trinomial(
                         new TrinomialTree(numericDynamics->process(), grid));
        boost::shared_ptr<ShortRateTree> numericTree(
                         new ShortRateTree(trinomial, numericDynamics, grid));

        typedef TermStructureFittingParameter::NumericalImpl NumericalImpl;
        boost::shared_ptr<NumericalImpl> impl =
            boost::dynamic_pointer_cast<NumericalImpl>(phi.implementation());
        impl->reset();
        for (Size i=0; i<(grid.size() - 1); i++) {
            Real discountBond = termStructure()->discount(grid[i+1]);
            const Array& statePrices = numericTree->statePrices(i);
            Size size = numericTree->size(i);
            Time dt = numericTree->timeGrid().dt(i);
            Real dx = trinomial->dx(i);
            Real x = trinomial->underlying(i,0);
            Real value = 0.0;
            for (Size j=0; j<size; j++) {
                value += statePrices[j]*std::exp(-x*dt);
                x += dx;
            }
            value = std::log(value/discountBond)/dt;
            impl->set(grid[i], value);
        }
        return numericTree;
    }
开发者ID:androidYibo,项目名称:documents,代码行数:31,代码来源:hullwhite.cpp

示例3: path_generator_type

        boost::shared_ptr<path_generator_type> pathGenerator() const {

            Size numAssets = processes_->size();

            TimeGrid grid = timeGrid();

			Calendar calendar = this->arguments_.sp_payoff->calendar();
			
            typename RNG::rsg_type gen =
                RNG::make_sequence_generator(numAssets*(grid.size()-1),seed_);

			boost::shared_ptr<path_generator_type> pgPtr 
				= boost::shared_ptr<path_generator_type>(
					       new path_generator_type(processes_,
                                                 grid, 
												 gen));

			PathInformation::instance().initialize(pgPtr->multiPath(),calendar);

			//history setting here..

			//index의 Calendar와 product의 Calendar(calculation Date Calendar)는 따로 가야함
			//과거 index fixing은 각각 클래스에서 fixing하는데 그 방법은 pathmanager가 indexHistory를 가지고 있어서 거기에 문의해서, 
			//따로 클래스 내에 가져와서 fixing 시켜놈. 결과만 저장해서 나중에 함침.
			//그러므로 path에 따로 무언가를 붙일 필요는 없음.
			//MultiPath Grid는 product calendar로 grid숫자 계산함.

            return pgPtr;
        }
开发者ID:minikie,项目名称:OTCDerivativesCalculatorModule,代码行数:29,代码来源:MCStructuredProductEngine.hpp

示例4: pathGenerator

		//! Return shared pointer to path generator who generates sample pathes in simulation
		virtual boost::shared_ptr<path_generator_type> pathGenerator() const {
			Size factors = this->process()->factors();
			TimeGrid grid = timeGrid();
			Size steps = grid.size() - 1;
			typename RNG::rsg_type gen = RNG::make_sequence_generator(factors * steps, seed_);
			return boost::make_shared<path_generator_type>(this->process(), grid, gen, false);
		}
开发者ID:eefelix,项目名称:MAFS5220,代码行数:8,代码来源:mctvaengine.hpp

示例5: sequenceGen

    inline
    ext::shared_ptr<typename MCDigitalEngine<RNG,S>::path_pricer_type>
    MCDigitalEngine<RNG,S>::pathPricer() const {

        ext::shared_ptr<CashOrNothingPayoff> payoff =
            ext::dynamic_pointer_cast<CashOrNothingPayoff>(
                this->arguments_.payoff);
        QL_REQUIRE(payoff, "wrong payoff given");

        ext::shared_ptr<AmericanExercise> exercise =
            ext::dynamic_pointer_cast<AmericanExercise>(
                this->arguments_.exercise);
        QL_REQUIRE(exercise, "wrong exercise given");

        ext::shared_ptr<GeneralizedBlackScholesProcess> process =
            ext::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
                                                              this->process_);
        QL_REQUIRE(process, "Black-Scholes process required");

        TimeGrid grid = this->timeGrid();
        PseudoRandom::ursg_type sequenceGen(grid.size()-1,
                                            PseudoRandom::urng_type(76));

        return ext::shared_ptr<
                        typename MCDigitalEngine<RNG,S>::path_pricer_type>(
          new DigitalPathPricer(payoff,
                                exercise,
                                process->riskFreeRate(),
                                process,
                                sequenceGen));
    }
开发者ID:SePTimO7,项目名称:QuantLib,代码行数:31,代码来源:mcdigitalengine.hpp

示例6: phi

    boost::shared_ptr<Lattice>
    BlackKarasinski::tree(const TimeGrid& grid) const {

        TermStructureFittingParameter phi(termStructure());

        boost::shared_ptr<ShortRateDynamics> numericDynamics(
                                             new Dynamics(phi, a(), sigma()));

        boost::shared_ptr<TrinomialTree> trinomial(
                         new TrinomialTree(numericDynamics->process(), grid));
        boost::shared_ptr<ShortRateTree> numericTree(
                         new ShortRateTree(trinomial, numericDynamics, grid));

        typedef TermStructureFittingParameter::NumericalImpl NumericalImpl;
        boost::shared_ptr<NumericalImpl> impl =
            boost::dynamic_pointer_cast<NumericalImpl>(phi.implementation());
        impl->reset();
        Real value = 1.0;
        Real vMin = -50.0;
        Real vMax = 50.0;
        for (Size i=0; i<(grid.size() - 1); i++) {
            Real discountBond = termStructure()->discount(grid[i+1]);
            Real xMin = trinomial->underlying(i, 0);
            Real dx = trinomial->dx(i);
            Helper finder(i, xMin, dx, discountBond, numericTree);
            Brent s1d;
            s1d.setMaxEvaluations(1000);
            value = s1d.solve(finder, 1e-7, value, vMin, vMax);
            impl->set(grid[i], value);
            // vMin = value - 10.0;
            // vMax = value + 10.0;
        }
        return numericTree;
    }
开发者ID:androidYibo,项目名称:documents,代码行数:34,代码来源:blackkarasinski.cpp

示例7:

    template <class PathType> inline
    LongstaffSchwartzPathPricer<PathType>::LongstaffSchwartzPathPricer(
        const TimeGrid& times,
        const boost::shared_ptr<EarlyExercisePathPricer<PathType> >&
            pathPricer,
        const boost::shared_ptr<YieldTermStructure>& termStructure)
    : calibrationPhase_(true),
      pathPricer_(pathPricer),
      coeff_     (new Array[times.size()-1]),
      dF_        (new DiscountFactor[times.size()-1]),
      v_         (pathPricer_->basisSystem()) {

        for (Size i=0; i<times.size()-1; ++i) {
            dF_[i] =   termStructure->discount(times[i+1])
                     / termStructure->discount(times[i]);
        }
    }
开发者ID:androidYibo,项目名称:documents,代码行数:17,代码来源:longstaffschwartzpathpricer.hpp

示例8: path_generator_type

        boost::shared_ptr<path_generator_type> pathGenerator() const {

            TimeGrid grid = this->timeGrid();
            typename RNG::rsg_type gen =
                RNG::make_sequence_generator(grid.size()-1,seed_);
            return boost::shared_ptr<path_generator_type>(
                         new path_generator_type(process_, grid,
                                                 gen, brownianBridge_));
        }
开发者ID:minikie,项目名称:OTCDerivativesCalculatorModule,代码行数:9,代码来源:mcdiscreteasianengine.hpp

示例9: path_generator_type

        boost::shared_ptr<path_generator_type> pathGenerator() const {

            Size dimensions = process_->factors();
            TimeGrid grid = this->timeGrid();
            typename RNG::rsg_type generator =
                RNG::make_sequence_generator(dimensions*(grid.size()-1),seed_);
            return boost::shared_ptr<path_generator_type>(
                   new path_generator_type(process_, grid,
                                           generator, brownianBridge_));
        }
开发者ID:androidYibo,项目名称:documents,代码行数:10,代码来源:mcvanillaengine.hpp

示例10: initializeImpl

void HifivePricer::initializeImpl(const TimeGrid& timeGrid,
									   const boost::shared_ptr<YieldTermStructure>& discountCurve,
									   const boost::shared_ptr<PathGeneratorFactory>& pathGenFactory)
{
	//this->discount_ = Array(eventTriggerList_.size(),1.0);

	//for ( Size i = 0 ; i < eventTriggerList_.size() ; i++ )
	//{
	//	eventTriggerList_[i]->initialize(timeGrid,discountCurve);

	//	if ( eventTriggerList_[i]->isExpired() )
	//	{
	//		remainEventPosition_ = i + 1;
	//		this->discount_[i] = 1.0;
	//	}else
	//	{
	//		this->discount_[i] = discountCurve_->discount(eventTriggerList_[i]->payoffDate());
	//	}
	//}

	Date today = Settings::instance().evaluationDate();

	remainEventPosition_ = 0;
	autoCallEventPosition_ = timeGrid.size() - 1;

	this->cf_results_ = std::vector<boost::shared_ptr<CashFlowResult>>( this->eventTriggerList_.size() );
	this->calcValue_results_ = std::vector<boost::shared_ptr<CalcValueResult>>(1);

	this->calcValue_results_[0] = boost::shared_ptr<CalcValueResult>(
									new CalcValueResult("NET","KRW"));

	for ( Size i = 0 ; i < eventTriggerList_.size() ; i++ )
	{
		this->eventTriggerList_[i]->initialize(timeGrid,discountCurve,pathGenFactory);
		this->cf_results_[i] =  boost::shared_ptr<CashFlowResult>( 
							new CashFlowResult(i+1,
											   this->eventTriggerList_[i]->getEventDate(),
											   this->eventTriggerList_[i]->getPayoffDate(),
											   "NET",
											   this->currency_,
											   this->payoffDateInfo_->discount()) );

		bool kk = eventTriggerList_[i]->isExpired();

		if ( eventTriggerList_[i]->isExpired() )
		{
			remainEventPosition_ = i + 1;
		}
	}

	this->kiBarrierEventTrigger_->initialize(timeGrid,discountCurve,pathGenFactory);
	//this->nonOccBarrierEventTrigger_->initialize(timeGrid,discountCurve,pathGenFactory);
	//pastkiBarrierEventOcc_ = kiBarrierEventTrigger_->pastEventOcc();

}
开发者ID:minikie,项目名称:OTCDerivativesCalculatorModule,代码行数:55,代码来源:hifivePricer.cpp

示例11: MultiPath

    MultiPathGeneratorFixedPath<GSG>::MultiPathGeneratorFixedPath(
                   const boost::shared_ptr<StochasticProcess>& process,
                   const TimeGrid& times,
                   GSG generator,
                   bool brownianBridge)
    : brownianBridge_(brownianBridge), process_(process),
      generator_(generator), next_(boost::shared_ptr<MultiPath>(new MultiPath(process->size(), times)))
	{
		nextPtr_ = next_.get();

        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");
        QL_REQUIRE(times.size() > 1,
                   "no times given");
    }
开发者ID:minikie,项目名称:OTCDerivativesCalculatorModule,代码行数:20,代码来源:multipathgeneratorFixedPath.hpp

示例12: path_generator_type

        ext::shared_ptr<path_generator_type> pathGenerator() const {

            Size numAssets = processes_->size();

            TimeGrid grid = timeGrid();
            typename RNG::rsg_type gen =
                RNG::make_sequence_generator(numAssets*(grid.size()-1),seed_);

            return ext::shared_ptr<path_generator_type>(
                         new path_generator_type(processes_,
                                                 grid, gen, brownianBridge_));
        }
开发者ID:SePTimO7,项目名称:QuantLib,代码行数:12,代码来源:mcpagodaengine.hpp

示例13: path_generator_type

    inline
    boost::shared_ptr<typename
    MCLongstaffSchwartzEngine<GenericEngine,MC,RNG,S>::path_generator_type>
    MCLongstaffSchwartzEngine<GenericEngine,MC,RNG,S>::pathGenerator() const {

        Size dimensions = process_->factors();
        TimeGrid grid = this->timeGrid();
        typename RNG::rsg_type generator =
            RNG::make_sequence_generator(dimensions*(grid.size()-1),seed_);
        return boost::shared_ptr<path_generator_type>(
                   new path_generator_type(process_,
                                           grid, generator, brownianBridge_));
    }
开发者ID:AAthresh,项目名称:quantlib,代码行数:13,代码来源:mclongstaffschwartzengine.hpp

示例14: to

    MultiPathGenerator<GSG>::MultiPathGenerator(
                   const boost::shared_ptr<StochasticProcess>& process,
                   const TimeGrid& times,
                   GSG generator,
                   bool brownianBridge)
    : brownianBridge_(brownianBridge), process_(process),
      generator_(generator), next_(MultiPath(process->size(), times), 1.0) {

		//std::cout << "dimension (" << generator_.dimension()
		//	<< ") is not equal to ("
		//	<< process->factors() << " * " << times.size() - 1
		//	<< ") the number of factors "
		//	<< "times the number of time steps";

        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");
        QL_REQUIRE(times.size() > 1,
                   "no times given");
    }
开发者ID:minikie,项目名称:test,代码行数:24,代码来源:multipathgenerator.hpp

示例15: simulateMP

    void simulateMP(const boost::shared_ptr<StochasticProcess>& process,
                    int nbPaths, TimeGrid& grid, BigNatural seed,
                    bool antithetic_variates, double *res) {

        typedef PseudoRandom::rsg_type rsg_type;
        typedef MultiPathGenerator<rsg_type>::sample_type sample_type;
        Size assets = process->factors();
        rsg_type rsg = PseudoRandom::make_sequence_generator(
            (grid.size() - 1) * assets, seed);

        MultiPathGenerator<rsg_type> generator(process, grid, rsg, false);

        // fill simulated paths
        for (int i=0; i<nbPaths; ++i) {
            const bool antithetic = (i%2)==0 ? false : true;

            sample_type sample = antithetic_variates ?
                (antithetic ? generator.antithetic(): generator.next()) :
                generator.next();

            Path p1 = sample.value[0];
            std::copy(p1.begin(), p1.end(), res + i * grid.size());
        }
    }
开发者ID:enthought,项目名称:pyql,代码行数:24,代码来源:simulate_support_code.cpp


注:本文中的TimeGrid::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。