本文整理匯總了C#中QLNet.Schedule.date方法的典型用法代碼示例。如果您正苦於以下問題:C# Schedule.date方法的具體用法?C# Schedule.date怎麽用?C# Schedule.date使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類QLNet.Schedule
的用法示例。
在下文中一共展示了Schedule.date方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: testBondFromScheduleWithDateVector
public void testBondFromScheduleWithDateVector()
{
// Testing South African R2048 bond price using Schedule constructor with Date vector
SavedSettings backup = new SavedSettings();
//When pricing bond from Yield To Maturity, use NullCalendar()
Calendar calendar = new NullCalendar();
int settlementDays = 3;
Date issueDate = new Date(29, Month.June, 2012);
Date today = new Date(7, Month.September, 2015);
Date evaluationDate = calendar.adjust(today);
Date settlementDate = calendar.advance(evaluationDate, new Period(settlementDays, TimeUnit.Days));
Settings.setEvaluationDate(evaluationDate);
// For the schedule to generate correctly for Feb-28's, make maturity date on Feb 29
Date maturityDate = new Date(29, Month.February, 2048);
double coupon = 0.0875;
Compounding comp = Compounding.Compounded;
Frequency freq = Frequency.Semiannual;
DayCounter dc = new ActualActual(ActualActual.Convention.Bond);
// Yield as quoted in market
InterestRate yield = new InterestRate(0.09185, dc, comp, freq);
Period tenor = new Period(6, TimeUnit.Months);
Period exCouponPeriod = new Period(10, TimeUnit.Days);
// Generate coupon dates for 31 Aug and end of Feb each year
// For leap years, this will generate 29 Feb, but the bond
// actually pays coupons on 28 Feb, regardsless of whether
// it is a leap year or not.
Schedule schedule = new Schedule(issueDate, maturityDate, tenor,
new NullCalendar(), BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
DateGeneration.Rule.Backward, true);
// Adjust the 29 Feb's to 28 Feb
List<Date> dates = new List<Date>();
for (int i = 0; i < schedule.Count; ++i)
{
Date d = schedule.date(i);
if (d.Month == 2 && d.Day == 29)
dates.Add(new Date(28, Month.February, d.Year));
else
dates.Add(d);
}
schedule = new Schedule(dates,
schedule.calendar(),
schedule.businessDayConvention(),
schedule.terminationDateBusinessDayConvention(),
schedule.tenor(),
schedule.rule(),
schedule.endOfMonth(),
schedule.isRegular());
FixedRateBond bond = new FixedRateBond(
0,
100.0,
schedule,
new List<double>() { coupon },
dc, BusinessDayConvention.Following, 100.0,
issueDate, calendar,
exCouponPeriod, calendar, BusinessDayConvention.Unadjusted, false);
double calculatedPrice = BondFunctions.dirtyPrice(bond, yield, settlementDate);
double expectedPrice = 95.75706;
double tolerance = 1e-5;
if (Math.Abs(calculatedPrice - expectedPrice) > tolerance)
{
Assert.Fail(string.Format("failed to reproduce R2048 dirty price\nexpected: {0}\ncalculated: {1}", expectedPrice, calculatedPrice));
}
}