shared_ptr<VanillaSwap> SwapIndex::underlyingSwap(const Date& fixingDate) const { QL_REQUIRE(fixingDate!=Date(), "null fixing date"); // caching mechanism if (lastFixingDate_!=fixingDate) { Rate fixedRate = 0.0; if (exogenousDiscount_) lastSwap_ = MakeVanillaSwap(tenor_, iborIndex_, fixedRate) .withEffectiveDate(valueDate(fixingDate)) .withFixedLegCalendar(fixingCalendar()) .withFixedLegDayCount(dayCounter_) .withFixedLegTenor(fixedLegTenor_) .withFixedLegConvention(fixedLegConvention_) .withFixedLegTerminationDateConvention(fixedLegConvention_) .withDiscountingTermStructure(discount_); else lastSwap_ = MakeVanillaSwap(tenor_, iborIndex_, fixedRate) .withEffectiveDate(valueDate(fixingDate)) .withFixedLegCalendar(fixingCalendar()) .withFixedLegDayCount(dayCounter_) .withFixedLegTenor(fixedLegTenor_) .withFixedLegConvention(fixedLegConvention_) .withFixedLegTerminationDateConvention(fixedLegConvention_); lastFixingDate_ = fixingDate; } return lastSwap_; }
Rate IborIndex::forecastFixing(const Date& fixingDate) const { Date d1 = valueDate(fixingDate); Date d2 = maturityDate(d1); Time t = dayCounter_.yearFraction(d1, d2); QL_REQUIRE(t>0.0, "\n cannot calculate forward rate between " << d1 << " and " << d2 << ":\n non positive time (" << t << ") using " << dayCounter_.name() << " daycounter"); return forecastFixing(d1, d2, t); }
Rate IborIndex::forecastFixing(const Date& fixingDate) const { QL_REQUIRE(!termStructure_.empty(), "null term structure set to this instance of " << name()); Date fixingValueDate = valueDate(fixingDate); Date endValueDate = maturityDate(fixingValueDate); DiscountFactor fixingDiscount = termStructure_->discount(fixingValueDate); DiscountFactor endDiscount = termStructure_->discount(endValueDate); Time fixingPeriod = dayCounter_.yearFraction(fixingValueDate, endValueDate); return (fixingDiscount/endDiscount-1.0) / fixingPeriod; }
boost::shared_ptr<OvernightIndexedSwap> OvernightIndexedSwapIndex::underlyingSwap(const Date& fixingDate) const { QL_REQUIRE(fixingDate!=Date(), "null fixing date"); // caching mechanism if (lastFixingDate_!=fixingDate) { Rate fixedRate = 0.0; lastSwap_ = MakeOIS(tenor_, overnightIndex_, fixedRate) .withEffectiveDate(valueDate(fixingDate)) .withFixedLegDayCount(dayCounter_); lastFixingDate_ = fixingDate; } return lastSwap_; }
/* register a deposit for curve fitting */ DLLEXPORT xloper * xlInitiateDepositBootstrapHelper2 (const char * objectId_, const char * tenor_, const xloper * calendar_, const xloper * settlementDays_, const double * depositYield_, const xloper * annualBasis_, const xloper * trigger_) { boost::shared_ptr<ObjectHandler::FunctionCall> functionCall( new ObjectHandler::FunctionCall("xlInitiateDepositBootstrapHelper2")) ; try { QL_ENSURE(! functionCall->calledByFunctionWizard(), ""); // range validation ObjectHandler::validateRange(trigger_ , "trigger" ); ObjectHandler::validateRange(calendar_ , "calendar" ); ObjectHandler::validateRange(settlementDays_, "settlement days"); ObjectHandler::validateRange(annualBasis_ , "annual basis" ); // OPER management ObjectHandler::ConvertOper myOper1(* calendar_ ), myOper2(* settlementDays_), myOper3(* annualBasis_ ); // creates a value object boost::shared_ptr<QuantLibAddin::ValueObjects::depositBootstrapHelperValueObject> depositValueObject( new QuantLibAddin::ValueObjects::depositBootstrapHelperValueObject( objectId_, true)) ; // quantlib objects QuantLib::Natural settlementDays( myOper2.missing() ? 2 : static_cast<long>(myOper2)) ; QuantLib::Calendar calendar( myOper1.missing() ? QuantLib::UnitedStates( QuantLib::UnitedStates::Settlement) : ObjectHandler::calendarFactory()( static_cast<std::string>(myOper1))); QuantLib::Date valueDate( calendar.advance( QuantLib::Settings::instance().evaluationDate().value(), settlementDays, QuantLib::Days)) ; QuantLib::DayCounter annualBasis( myOper3.missing() ? QuantLib::Actual360() : ObjectHandler::daycountFactory()( static_cast<std::string>(myOper3))); // creates the deposit boost::shared_ptr<QuantLib::deposit> myDepositPtr ( new QuantLib::deposit( valueDate, calendar.advance(valueDate, ObjectHandler::periodFactory()(tenor_)), calendar, settlementDays, QuantLib::Unadjusted)); // creates the helper boost::shared_ptr<QuantLibAddin::depositBootstrapHelperObject> depositBootstrapObject( new QuantLibAddin::depositBootstrapHelperObject( depositValueObject, myDepositPtr, QuantLib::Handle<QuantLib::Quote>( boost::shared_ptr<QuantLib::Quote>( new QuantLib::SimpleQuote( myDepositPtr->cleanPrice( *depositYield_, annualBasis, QuantLib::Simple, QuantLib::Once, QuantLib::Unadjusted, valueDate)))), true)); // storage of the object std::string returnValue = ObjectHandler::RepositoryXL::instance().storeObject( objectId_, depositBootstrapObject, true); static XLOPER returnOper ; ObjectHandler::scalarToOper(returnValue, returnOper) ; return & returnOper ; } catch (std::exception & e) { ObjectHandler::RepositoryXL::instance().logError(e.what(), functionCall) ; static XLOPER returnOper ; ObjectHandler::scalarToOper(e.what(), returnOper) ; return & returnOper ; } };