//! \name Protected interface //{@ //! Return time grid used by Monte Carlo Simulation virtual TimeGrid timeGrid() const { Time maturity = endTime_; if (timeSteps_ != Null<Size>()) { return TimeGrid(maturity, timeSteps_); } else if (timeStepsPerYear_ != Null<Size>()) { Size steps = (Size)std::round(timeStepsPerYear_* maturity); return TimeGrid(maturity, std::max<Size>(static_cast<std::size_t>(std::round(maturity)), steps)); } else { QL_FAIL("time steps not specified"); } }
inline TimeGrid MCVanillaEngine<MC,RNG,S,Inst>::timeGrid() const { Date lastExerciseDate = this->arguments_.exercise->lastDate(); Time t = process_->time(lastExerciseDate); if (this->timeSteps_ != Null<Size>()) { return TimeGrid(t, this->timeSteps_); } else if (this->timeStepsPerYear_ != Null<Size>()) { Size steps = static_cast<Size>(this->timeStepsPerYear_*t); return TimeGrid(t, std::max<Size>(steps, 1)); } else { QL_FAIL("time steps not specified"); } }
inline TimeGrid MCVarianceSwapEngine<RNG,S>::timeGrid() const { Time t = this->process_->time(this->arguments_.maturityDate); if (timeSteps_ != Null<Size>()) { return TimeGrid(t, this->timeSteps_); } else if (timeStepsPerYear_ != Null<Size>()) { Size steps = static_cast<Size>(timeStepsPerYear_*t); return TimeGrid(t, std::max<Size>(steps, 1)); } else { QL_FAIL("time steps not specified"); } }
inline TimeGrid MCEuropeanBasketEngine<RNG,S>::timeGrid() const { Time residualTime = processes_->time( this->arguments_.exercise->lastDate()); if (timeSteps_ != Null<Size>()) { return TimeGrid(residualTime, timeSteps_); } else if (timeStepsPerYear_ != Null<Size>()) { Size steps = static_cast<Size>(timeStepsPerYear_*residualTime); return TimeGrid(residualTime, std::max<Size>(steps, 1)); } else { QL_FAIL("time steps not specified"); } }
TimeGrid MCELSNotionalProtectedEngine::timeGrid() const { const std::vector<Date> & fixings = this->arguments_.fixingDates; const Size numberOfFixings = fixings.size(); std::vector<Date> remainfixings; Date today = Settings::instance().evaluationDate(); for(Size i=0;i<numberOfFixings;++i){ if(fixings[i]>today){ remainfixings.push_back(fixings[i]); } } const Size numberOfRemainFixings = remainfixings.size(); std::vector<Time> fixingTimes;//(numberOfFixings); //이거 내가 추가한건가..? for (Size i = 0; i < numberOfRemainFixings; ++i) { //fixingTimes[i] = this->process_->time(fixings[i]); if(fixings[i]>today){ fixingTimes.push_back(discountTS_->dayCounter().yearFraction( today, remainfixings[i])); } } const Size numberOfTimeSteps = numberOfRemainFixings;//timeSteps_ != Null<Size>() ? timeSteps_ : timeStepsPerYear_ * static_cast<int>(fixingTimes.back()); //return TimeGrid(fixingTimes.begin(), fixingTimes.end(), numberOfTimeSteps); return TimeGrid(fixingTimes.begin(), fixingTimes.end(), numberOfTimeSteps); }
TimeGrid MCEngine::timeGrid() const { const std::vector<Date> & fixings = this->arguments_.fixingDates; const Size numberOfFixings = fixings.size(); std::vector<Date> remainfixings; Date today = Settings::instance().evaluationDate(); for(Size i=0;i<numberOfFixings;++i){ if(fixings[i]>today){ remainfixings.push_back(fixings[i]); } } const Size numberOfRemainFixings = remainfixings.size(); std::vector<Time> fixingTimes;//(numberOfFixings); //이거 내가 추가한건가..? for (Size i = 0; i < numberOfRemainFixings; ++i) { //fixingTimes[i] = this->process_->time(fixings[i]); if(fixings[i]>today){ fixingTimes.push_back(discountTS_->dayCounter().yearFraction( today, remainfixings[i])); } } return TimeGrid(fixingTimes.begin(), fixingTimes.end(), timeSteps_); }
BlackScholesLattice<T>::BlackScholesLattice( const boost::shared_ptr<T>& tree, Rate riskFreeRate, Time end, Size steps) : TreeLattice1D<BlackScholesLattice<T> >(TimeGrid(end, steps), 2), tree_(tree), riskFreeRate_(riskFreeRate), dt_(end/steps), discount_(std::exp(-riskFreeRate*(dt_))) { pd_ = tree->probability(0, 0, 0); pu_ = tree->probability(0, 0, 1); }
inline TimeGrid MCPagodaEngine<RNG,S>::timeGrid() const { std::vector<Time> fixingTimes; for (Size i=0; i<arguments_.fixingDates.size(); i++) { Time t = processes_->time(arguments_.fixingDates[i]); QL_REQUIRE(t >= 0.0, "seasoned options are not handled"); if (i > 0) { QL_REQUIRE(t > fixingTimes.back(), "fixing dates not sorted"); } fixingTimes.push_back(t); } return TimeGrid(fixingTimes.begin(), fixingTimes.end()); }
inline TimeGrid MCPathBasketEngine<RNG,S>::timeGrid() const { const std::vector<Date> & fixings = this->arguments_.fixingDates; const Size numberOfFixings = fixings.size(); std::vector<Time> fixingTimes(numberOfFixings); for (Size i = 0; i < numberOfFixings; ++i) { fixingTimes[i] = this->process_->time(fixings[i]); } const Size numberOfTimeSteps = timeSteps_ != Null<Size>() ? timeSteps_ : timeStepsPerYear_ * fixingTimes.back(); return TimeGrid(fixingTimes.begin(), fixingTimes.end(), numberOfTimeSteps); }
inline TimeGrid MCDiscreteAveragingAsianEngine<RNG,S>::timeGrid() const { Date referenceDate = process_->riskFreeRate()->referenceDate(); DayCounter voldc = process_->blackVolatility()->dayCounter(); std::vector<Time> fixingTimes; Size i; for (i=0; i<arguments_.fixingDates.size(); i++) { if (arguments_.fixingDates[i]>=referenceDate) { Time t = voldc.yearFraction(referenceDate, arguments_.fixingDates[i]); fixingTimes.push_back(t); } } return TimeGrid(fixingTimes.begin(), fixingTimes.end()); }
TimeGrid timeGrid() const { Date referenceDate = model_->termStructure()->referenceDate(); DayCounter dayCounter = model_->termStructure()->dayCounter(); // only add future fixing times... std::vector<Time> times; for (Size i=0; i<arguments_.fixingDates.size(); i++) { if (arguments_.fixingDates[i] > referenceDate) times.push_back( dayCounter.yearFraction(referenceDate, arguments_.fixingDates[i])); } // ...and maturity. times.push_back( dayCounter.yearFraction(referenceDate, arguments_.endDates.back())); return TimeGrid(times.begin(), times.end()); }