# Setting up Schedule for an amortizing floater in QuantLib

I am unsure as to the exact arguments required for the Schedule function for an amortizing floater - my code is listed below. Specifically, my question pertains to whether the schedule should always start from the issue date of the bond or should it start from the settlement date if the bond is seasoned. I seem to have seen usage both ways in some of the examples on the web so I am a bit confused.

I would expect that the NPV functions index into the right cashflow based on the settlement date provided but just checking.

Also, if anyone has a working example of an AmortizingFloatingRateBond which calculates the DM given a price (or vice versa) using a notional schedule,that'd be much appreciated.

Code Snippet:

QuantLib::JointCalendar calendar = QuantLib::JointCalendar(QuantLib::UnitedStates(),QuantLib::UnitedKingdom(),
QuantLib::DayCounter dayCounter = QuantLib::Actual360();

QuantLib::Integer fixingDays = 1;
QuantLib::Natural settlementDays = 3;

QuantLib::Date issueDate(25,QuantLib::July,2013);

QuantLib::Period p1m = QuantLib::Period(1,QuantLib::Months);

// Number of payments
int num_cashflows = 120;
QuantLib::Date maturityDate = issueDate + num_cashflows * p1m;

QuantLib::Schedule mySchedule(issueDate,
maturityDate,
QuantLib::Period(QuantLib::Monthly),
calendar,
QuantLib::DateGeneration::Forward,
false);

QuantLib::AmortizingFloatingRateBond MyFloater(settlementDays,
Notional,
mySchedule,
libor,
QuantLib::Actual360(),
fixingDays,
std::vector<QuantLib::Real>(1,1.0),
std::vector<QuantLib::Rate>(),
std::vector<QuantLib::Rate>(),
true,
issueDate);

MyFloater.setPricingEngine(bondEngine);

std::vector<QuantLib::Date> paySchedule = mySchedule.dates();
std::vector<QuantLib::Date>::iterator pIter;
QuantLib::Date priorDate;

for (pIter = paySchedule.begin(); pIter != paySchedule.end() && *pIter < settlementDate; ++pIter){
priorDate = *pIter;
}


As for the first question, the schedule should start from the issue date. The bond will manage cash flows correctly based on the evaluation date.

The second is a bit trickier, and I don't think I have working code handy. The general idea is: if you want to add a spread to the rate of the bond (to go from discount margin to price) you'll have to modify the term structure you pass to your Libor instance. Instead of linking the term-structure handle to the Libor curve, create an instance of ForwardSpreadedTermStructure passing the Libor curve and a quote holding the spread; something like

boost::shared_ptr<SimpleQuote> spread(new SimpleQuote(0.0));
libor = boost::shared_ptr<IborIndex>(
new USDLibor(1*Months,


If you initialize the bond with the Libor instance above, you should be able to write:

spread->setValue(0.002);


and see the bond price change accordingly.

To go from price to DM, you have to invert the above in some way. The easiest is probably to create a function object that takes a spread and returns the difference between the target price and the price calculated with the current DM (it will probably have to hold a reference to the bond and perform the calculation I outlined). Once you have the function object, you can pass it to any of the 1-D solvers available in the library. The solver will return the spread that gives a null price difference; that is, the spread for which the price equals the target price.

Update: as per Calculating Discount Margin on a floating rate bond using QuantLib, you should use the original LIBOR curve for forecast and the curve plus spread for discounting; thus, something like

shared_ptr<SimpleQuote> spread = make_shared<SimpleQuote>(0.0);