protected CallableBond(int settlementDays, Schedule schedule, DayCounter paymentDayCounter, Date issueDate = null, CallabilitySchedule putCallSchedule = null) : base(settlementDays, schedule.calendar(), issueDate) { if (putCallSchedule == null) { putCallSchedule = new CallabilitySchedule(); } paymentDayCounter_ = paymentDayCounter; putCallSchedule_ = putCallSchedule; maturityDate_ = schedule.dates().Last(); if (!putCallSchedule_.empty()) { Date finalOptionDate = Date.minDate(); for (int i = 0; i < putCallSchedule_.Count; ++i) { finalOptionDate = Date.Max(finalOptionDate, putCallSchedule_[i].date()); } Utils.QL_REQUIRE(finalOptionDate <= maturityDate_, () => "Bond cannot mature before last call/put date"); } // derived classes must set cashflows_ and frequency_ }
protected override void performCalculations() { Utils.QL_REQUIRE(!bondHelpers_.empty(), () => "no bondHelpers given"); maxDate_ = Date.minDate(); Date refDate = referenceDate(); // double check bond quotes still valid and/or instruments not expired for (int i = 0; i < bondHelpers_.Count; ++i) { Bond bond = bondHelpers_[i].bond(); Utils.QL_REQUIRE(bondHelpers_[i].quote().link.isValid(), () => (i + 1) + " bond (maturity: " + bond.maturityDate() + ") has an invalid price quote"); Date bondSettlement = bond.settlementDate(); Utils.QL_REQUIRE(bondSettlement >= refDate, () => (i + 1) + " bond settlemente date (" + bondSettlement + ") before curve reference date (" + refDate + ")"); Utils.QL_REQUIRE(BondFunctions.isTradable(bond, bondSettlement), () => (i + 1) + " bond non tradable at " + bondSettlement + " settlement date (maturity" + " being " + bond.maturityDate() + ")", QLNetExceptionEnum.NotTradableException); maxDate_ = Date.Max(maxDate_, bondHelpers_[i].pillarDate()); bondHelpers_[i].setTermStructure(this); } fittingMethod_.init(); fittingMethod_.calculate(); }
public static Date maturityDate(Leg leg) { Utils.QL_REQUIRE(!leg.empty(), () => "empty leg"); Date d = Date.minDate(); for (int i = 0; i < leg.Count; ++i) { Coupon c = leg[i] as Coupon; if (c != null) { d = Date.Max(d, c.accrualEndDate()); } else { d = Date.Max(d, leg[i].date()); } } return(d); }
public void add(ExchangeRate rate) { add(rate, Date.minDate(), Date.maxDate()); }
public AmericanExercise(Date latest, bool payoffAtExpiry = false) : base(Type.American, payoffAtExpiry) { dates_ = new InitializedList <Date>(2); dates_[0] = Date.minDate(); dates_[1] = latest; }
/*! returns the ECB date for the given ECB code * (e.g. March xxth, 2013 for MAR10). * * \warning It raises an exception if the input * string is not an ECB code */ public static Date date(string ecbCode, Date refDate = null) { Utils.QL_REQUIRE(isECBcode(ecbCode), () => ecbCode + " is not a valid ECB code"); string code = ecbCode.ToUpper(); string monthString = code.Substring(0, 3); Month m = Month.Jan; if (monthString == "JAN") { m = Month.January; } else if (monthString == "FEB") { m = Month.February; } else if (monthString == "MAR") { m = Month.March; } else if (monthString == "APR") { m = Month.April; } else if (monthString == "MAY") { m = Month.May; } else if (monthString == "JUN") { m = Month.June; } else if (monthString == "JUL") { m = Month.July; } else if (monthString == "AUG") { m = Month.August; } else if (monthString == "SEP") { m = Month.September; } else if (monthString == "OCT") { m = Month.October; } else if (monthString == "NOV") { m = Month.November; } else if (monthString == "DEC") { m = Month.December; } else { Utils.QL_FAIL("not an ECB month (and it should have been)"); } // lexical_cast causes compilation errors with x64 //Year y = boost::lexical_cast<Year>(code.substr(3, 2)); int y = int.Parse(code.Substring(3, 2)); Date referenceDate = (refDate ?? new Date(Settings.evaluationDate())); int referenceYear = (referenceDate.year() % 100); y += referenceDate.year() - referenceYear; if (y < Date.minDate().year()) { return(ECB.nextDate(Date.minDate())); } return(ECB.nextDate(new Date(1, m, y))); }