std::vector<boost::shared_ptr<CashFlow> > RiskyBond::expectedCashflows() { std::vector<boost::shared_ptr<CashFlow> > expected; std::vector<boost::shared_ptr<CashFlow> > cf = cashflows(); Date today = Settings::instance().evaluationDate(); Date npvDate = calendar_.advance(today, settlementDays_, Days); Date d1 = effectiveDate(); for (Size i = 0; i < cf.size(); i++) { Date d2 = cf[i]->date(); if (d2 > npvDate) { d1 = max(npvDate, d1); Date defaultDate = d1 + (d2-d1)/2; Real coupon = cf[i]->amount() * defaultTS_->survivalProbability(d2); Real recovery = notional(defaultDate) * recoveryRate_ * (defaultTS_->survivalProbability(d1) -defaultTS_->survivalProbability(d2)); boost::shared_ptr<CashFlow> flow1(new SimpleCashFlow(coupon, d2)); expected.push_back(flow1); boost::shared_ptr<CashFlow> flow2(new SimpleCashFlow(recovery, defaultDate)); expected.push_back(flow2); } d1 = d2; } return expected; }
void RiskyBond::performCalculations() const { NPV_ = 0; Date today = Settings::instance().evaluationDate(); std::vector<boost::shared_ptr<CashFlow> > cf = cashflows(); Date d1 = effectiveDate(); for (Size i = 0; i < cf.size(); i++) { Date d2 = cf[i]->date(); if (d2 > today) { d1 = max(today , d1); Date defaultDate = d1 + (d2-d1)/2; // Mid-Point Rule Real coupon = cf[i]->amount() * defaultTS_->survivalProbability(d2); Real recovery = notional(defaultDate) * recoveryRate_ * (defaultTS_->survivalProbability(d1) -defaultTS_->survivalProbability(d2)); NPV_ += coupon * yieldTS()->discount(d2); NPV_ += recovery * yieldTS()->discount(defaultDate); } d1 = d2; } }
/* enregistre un TIPS */ DLLEXPORT xloper * xlInitiateAussieNote (const char * objectID_, const double * issueDate_, xloper * effectiveDate_, xloper * firstCouponDate_, xloper * lastCouponDate_, const double * maturityDate_, const double * couponRate_, xloper * trigger_) { boost::shared_ptr<ObjectHandler::FunctionCall> functionCall( new ObjectHandler::FunctionCall("xlInitiateAussieNote")) ; try { QL_ENSURE(! functionCall->calledByFunctionWizard(), "") ; // trigger pour provoquer le recalcul ObjectHandler::validateRange(trigger_, "trigger") ; ObjectHandler::validateRange(effectiveDate_, "effective Date") ; ObjectHandler::validateRange(firstCouponDate_, "first Coupon Date") ; ObjectHandler::validateRange(lastCouponDate_, "last Coupon Date") ; ObjectHandler::ConvertOper myOper1(* effectiveDate_) ; ObjectHandler::ConvertOper myOper2(* firstCouponDate_) ; ObjectHandler::ConvertOper myOper3(* lastCouponDate_) ; QuantLib::Date issueDate(static_cast<QuantLib::BigInteger>(* issueDate_)) ; QuantLib::Date effectiveDate(myOper1.missing() ? issueDate : static_cast<QuantLib::Date>(myOper1)) ; QuantLib::Date firstCouponDate(myOper2.missing() ? QuantLib::Date() : static_cast<QuantLib::Date>(myOper2)) ; QuantLib::Date lastCouponDate(myOper3.missing() ? QuantLib::Date() : static_cast<QuantLib::Date>(myOper3)) ; QuantLib::Date maturityDate(static_cast<QuantLib::BigInteger>(* maturityDate_)) ; // Construction du value object boost::shared_ptr<QuantLibAddin::ValueObjects::australianTreasuryNoteValueObject> myBondValueObject( new QuantLibAddin::ValueObjects::australianTreasuryNoteValueObject(objectID_, true)) ; // instanciation de l'instrument boost::shared_ptr<QuantLibAddin::australianTreasuryNoteObject> myBondObject( new QuantLibAddin::australianTreasuryNoteObject(myBondValueObject, issueDate, effectiveDate, firstCouponDate, lastCouponDate, maturityDate, QuantLib::Rate(* couponRate_), true)) ; // stockage de l'objet std::string returnValue = ObjectHandler::RepositoryXL::instance().storeObject(objectID_, myBondObject, true) ; // on force la réécriture 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 ; } } ;
/* enregistre une jambe à taux flottant */ DLLEXPORT xloper * xlInitiateFloatLegUnitedStates (const char * objectID_, const double * effectiveDate_, xloper * firstCouponDate_, xloper * lastCouponDate_, const double * maturityDate_, xloper * notional_, const char * indexId_, xloper * frequency_, xloper * daycounter_, xloper * spread_, xloper * trigger_) { boost::shared_ptr<ObjectHandler::FunctionCall> functionCall( new ObjectHandler::FunctionCall("xlInitiatefloatLegUnitedStates")) ; try { QL_ENSURE(! functionCall->calledByFunctionWizard(), "") ; // vérification des codes erreur ObjectHandler::validateRange(trigger_, "trigger") ; ObjectHandler::validateRange(firstCouponDate_, "first Coupon Date") ; ObjectHandler::validateRange(lastCouponDate_, "last Coupon Date") ; ObjectHandler::validateRange(notional_, "notional") ; ObjectHandler::validateRange(frequency_, "frequency") ; ObjectHandler::validateRange(daycounter_, "daycounter") ; ObjectHandler::validateRange(spread_, "spread") ; // Création des oper ObjectHandler::ConvertOper myOper1(* firstCouponDate_), myOper2(* lastCouponDate_), myOper3(* notional_), myOper4(* frequency_), myOper5(* daycounter_), myOper6(* spread_) ; // création des dates et contrôles sur les dates intermédiaires QuantLib::Date effectiveDate(QuantLib::Date(static_cast<QuantLib::BigInteger>(* effectiveDate_))) ; QuantLib::Date maturityDate(QuantLib::Date(static_cast<QuantLib::BigInteger>(* maturityDate_))) ; QuantLib::Date firstCouponDate(myOper1.missing() ? QuantLib::Date() : QuantLib::Date(static_cast<QuantLib::BigInteger>(myOper1))) ; QuantLib::Date lastCouponDate(myOper2.missing() ? QuantLib::Date() : QuantLib::Date(static_cast<QuantLib::BigInteger>(myOper2))) ; QuantLib::Real notional(myOper3.missing() ? 100.0 : static_cast<QuantLib::Real>(myOper3)) ; QuantLib::Frequency frequency(myOper4.missing() ? QuantLib::Quarterly : ObjectHandler::frequencyFactory()(static_cast<std::string>(myOper4))) ; QuantLib::DayCounter daycounter(myOper5.missing() ? QuantLib::Actual360() : ObjectHandler::daycountFactory()(static_cast<std::string>(myOper5))) ; QuantLib::Spread spread(myOper6.missing() ? 0.0 : static_cast<QuantLib::Spread>(myOper6)) ; // on récupère l'index libor OH_GET_REFERENCE(iborIndexPtr, std::string(indexId_), QuantLibAddin::iborIndexObject, QuantLib::IborIndex) // Construction du value object boost::shared_ptr<QuantLibAddin::ValueObjects::floatLegUnitedStatesValueObject> myLegValueObject( new QuantLibAddin::ValueObjects::floatLegUnitedStatesValueObject(objectID_, true)) ; // instanciation de l'instrument boost::shared_ptr<QuantLibAddin::floatLegUnitedStatesObject> myLegObject( new QuantLibAddin::floatLegUnitedStatesObject(myLegValueObject, effectiveDate, firstCouponDate, lastCouponDate, maturityDate, iborIndexPtr, 2, frequency, daycounter, notional, spread, QuantLib::ModifiedFollowing, QuantLib::ModifiedFollowing, true, true)) ; // stockage de l'objet std::string returnValue = ObjectHandler::RepositoryXL::instance().storeObject(objectID_, myLegObject, true) ; // on force la réécriture 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 ; } } ;
boost::shared_ptr<ObjectHandler::Object> create_fixedLegAustralia( const boost::shared_ptr<ObjectHandler::ValueObject> & valueObject) { //convert input datatypes to C++ datatypes QuantLib::DayCounter legDaycounter = ObjectHandler::daycountFactory()(ObjectHandler::convert2<std::string>(valueObject->getProperty("DayCounter"))) ; QuantLib::Compounding legCompounding = ObjectHandler::convert2<QuantLib::Compounding>(valueObject->getProperty("Compounding")) ; QuantLib::Frequency legFrequency = ObjectHandler::convert2<QuantLib::Frequency>(valueObject->getProperty("Frequency")) ; QuantLib::Date effectiveDate( ObjectHandler::convert2<QuantLib::BigInteger>(valueObject->getProperty("effectiveDate"))) ; QuantLib::Date firstCouponDate( ObjectHandler::convert2<QuantLib::BigInteger>(valueObject->getProperty("firstCouponDate"))) ; QuantLib::Date lastCouponDate( ObjectHandler::convert2<QuantLib::BigInteger>(valueObject->getProperty("lastCouponDate"))) ; QuantLib::Date maturityDate( ObjectHandler::convert2<QuantLib::BigInteger>(valueObject->getProperty("maturityDate"))) ; QuantLib::BusinessDayConvention paymentConvention = ObjectHandler::convert2<QuantLib::BusinessDayConvention >(valueObject->getProperty("paymentConvention")) ; QuantLib::BusinessDayConvention terminationPaymentConvention = ObjectHandler::convert2<QuantLib::BusinessDayConvention>(valueObject->getProperty("terminationPaymentConvention")) ; bool permanent = ObjectHandler::convert2<bool>(valueObject->getProperty("permanent")) ; bool endOfMonth = ObjectHandler::convert2<bool>(valueObject->getProperty("endOfMonth")) ; double fixedCouponRate = ObjectHandler::convert2<double>(valueObject->getProperty("fixedCouponRate")) ; double notional = ObjectHandler::convert2<double>(valueObject->getProperty("notional")) ; boost::shared_ptr<ObjectHandler::Object> object( new QuantLibAddin::fixedLegAustraliaObject( boost::dynamic_pointer_cast<QuantLibAddin::ValueObjects::fixedLegAustraliaValueObject>(valueObject), effectiveDate, firstCouponDate, lastCouponDate, maturityDate, fixedCouponRate, legFrequency, legDaycounter, legCompounding, notional, paymentConvention, terminationPaymentConvention, endOfMonth, permanent)) ; return object ; }