MakeCapFloor::operator shared_ptr<CapFloor>() const { VanillaSwap swap = makeVanillaSwap_; Leg leg = swap.floatingLeg(); if (firstCapletExcluded_) leg.erase(leg.begin()); // only leaves the last coupon if (asOptionlet_ && leg.size() > 1) { Leg::iterator end = leg.end(); // Sun Studio needs an lvalue leg.erase(leg.begin(), --end); } std::vector<Rate> strikeVector(1, strike_); if (strike_ == Null<Rate>()) { // temporary patch... // should be fixed for every CapFloor::Engine shared_ptr<BlackCapFloorEngine> temp = dynamic_pointer_cast<BlackCapFloorEngine>(engine_); QL_REQUIRE(temp, "cannot calculate ATM without a BlackCapFloorEngine"); Handle<YieldTermStructure> discountCurve = temp->termStructure(); strikeVector[0] = CashFlows::atmRate(leg, **discountCurve, false, discountCurve->referenceDate()); } shared_ptr<CapFloor> capFloor(new CapFloor(capFloorType_, leg, strikeVector)); capFloor->setPricingEngine(engine_); return capFloor; }
RcppExport SEXP cfamounts(SEXP params){ SEXP rl=R_NilValue; char* exceptionMesg=NULL; try{ RcppParams rparam(params); QuantLib::Date maturity(dateFromR(rparam.getDateValue("Maturity"))); QuantLib::Date settle(dateFromR(rparam.getDateValue("Settle"))); QuantLib::Date issue(dateFromR(rparam.getDateValue("IssueDate"))); double rate = rparam.getDoubleValue("CouponRate"); std::vector<double> rateVec(1, rate); double faceAmount = rparam.getDoubleValue("Face"); double period = rparam.getDoubleValue("Period"); double basis = rparam.getDoubleValue("Basis"); DayCounter dayCounter = getDayCounter(basis); Frequency freq = getFrequency(period); Period p(freq); double EMR = rparam.getDoubleValue("EMR"); Calendar calendar=UnitedStates(UnitedStates::GovernmentBond); Schedule sch(settle, maturity, p, calendar, Unadjusted, Unadjusted, DateGeneration::Backward, (EMR == 1)? true : false); FixedRateBond bond(1, faceAmount, sch, rateVec, dayCounter, Following, 100, issue); //cashflow int numCol = 2; std::vector<std::string> colNames(numCol); colNames[0] = "Date"; colNames[1] = "Amount"; RcppFrame frame(colNames); Leg bondCashFlow = bond.cashflows(); for (unsigned int i = 0; i< bondCashFlow.size(); i++){ std::vector<ColDatum> row(numCol); Date d = bondCashFlow[i]->date(); row[0].setDateValue(RcppDate(d.month(), d.dayOfMonth(), d.year())); row[1].setDoubleValue(bondCashFlow[i]->amount()); frame.addRow(row); } RcppResultSet rs; rs.add("cashFlow", frame); rl = rs.getReturnList(); } catch(std::exception& ex) { exceptionMesg = copyMessageToR(ex.what()); } catch(...) { exceptionMesg = copyMessageToR("unknown reason"); } if(exceptionMesg != NULL) Rf_error(exceptionMesg); return rl; }
void setCouponPricer( const Leg& leg, const boost::shared_ptr<FloatingRateCouponPricer>& pricer) { PricerSetter setter(pricer); for (Size i=0; i<leg.size(); ++i) { leg[i]->accept(setter); } }
MakeYoYInflationCapFloor::operator ext::shared_ptr<YoYInflationCapFloor>() const { Date startDate; if (effectiveDate_ != Date()) { startDate = effectiveDate_; } else { Date referenceDate = Settings::instance().evaluationDate(); Date spotDate = calendar_.advance(referenceDate, fixingDays_*Days); startDate = spotDate+forwardStart_; } Date endDate = calendar_.advance(startDate,length_*Years,Unadjusted); Schedule schedule(startDate, endDate, Period(Annual), calendar_, Unadjusted, Unadjusted, // ref periods & acc periods DateGeneration::Forward, false); Leg leg = yoyInflationLeg(schedule, calendar_, index_, observationLag_) .withPaymentAdjustment(roll_) .withPaymentDayCounter(dayCounter_) .withNotionals(nominal_) ; if (firstCapletExcluded_) leg.erase(leg.begin()); // only leaves the last coupon if (asOptionlet_ && leg.size() > 1) { Leg::iterator end = leg.end(); // Sun Studio needs an lvalue leg.erase(leg.begin(), --end); } std::vector<Rate> strikeVector(1, strike_); if (strike_ == Null<Rate>()) { // ATM on the forecasting curve Handle<YieldTermStructure> fc; if (!nominalTermStructure_.empty()) { fc = nominalTermStructure_; } else { QL_REQUIRE(!index_->yoyInflationTermStructure().empty(), "no forecasting yoy term structure set for " << index_->name()); fc = index_->yoyInflationTermStructure()->nominalTermStructure(); } strikeVector[0] = CashFlows::atmRate(leg,**fc, false, fc->referenceDate()); } ext::shared_ptr<YoYInflationCapFloor> capFloor(new YoYInflationCapFloor(capFloorType_, leg, strikeVector)); capFloor->setPricingEngine(engine_); return capFloor; }
void setCouponPricers( const Leg& leg, const std::vector<boost::shared_ptr<FloatingRateCouponPricer> >& pricers) { Size nCashFlows = leg.size(); QL_REQUIRE(nCashFlows>0, "no cashflows"); Size nPricers = pricers.size(); QL_REQUIRE(nCashFlows >= nPricers, "mismatch between leg size (" << nCashFlows << ") and number of pricers (" << nPricers << ")"); for (Size i=0; i<nCashFlows; ++i) { PricerSetter setter(i<nPricers ? pricers[i] : pricers[nPricers-1]); leg[i]->accept(setter); } }