本文整理汇总了C#中QLNet.Calendar.endOfMonth方法的典型用法代码示例。如果您正苦于以下问题:C# Calendar.endOfMonth方法的具体用法?C# Calendar.endOfMonth怎么用?C# Calendar.endOfMonth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QLNet.Calendar
的用法示例。
在下文中一共展示了Calendar.endOfMonth方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Schedule
public Schedule( Date effectiveDate, Date terminationDate, Period tenor, Calendar calendar,
BusinessDayConvention convention, BusinessDayConvention terminationDateConvention,
DateGeneration.Rule rule, bool endOfMonth, Date firstDate, Date nextToLastDate)
{
// first save the properties
fullInterface_ = true;
tenor_ = tenor;
calendar_ = calendar;
convention_ = convention;
terminationDateConvention_ = terminationDateConvention;
rule_ = rule;
endOfMonth_ = endOfMonth;
if ( firstDate == effectiveDate )
firstDate_ = null;
else
firstDate_ = firstDate;
if ( nextToLastDate == terminationDate )
nextToLastDate_ = null;
else
nextToLastDate_ = nextToLastDate;
// sanity checks
Utils.QL_REQUIRE(terminationDate != null, "null termination date");
// in many cases (e.g. non-expired bonds) the effective date is not
// really necessary. In these cases a decent placeholder is enough
if ( effectiveDate == null && firstDate == null && rule== DateGeneration.Rule.Backward)
{
Date evalDate = Settings.evaluationDate();
Utils.QL_REQUIRE(evalDate < terminationDate, "null effective date");
int y;
if (nextToLastDate != null)
{
y = (nextToLastDate - evalDate)/366 + 1;
effectiveDate = nextToLastDate - new Period(y,TimeUnit.Years);
}
else
{
y = (terminationDate - evalDate)/366 + 1;
effectiveDate = terminationDate - new Period(y,TimeUnit.Years);
}
}
else
Utils.QL_REQUIRE(effectiveDate != null, "null effective date");
if (tenor_.length() == 0)
rule_ = DateGeneration.Rule.Zero;
else
Utils.QL_REQUIRE(tenor.length()>0, "non positive tenor (" + tenor + ") not allowed");
if (firstDate_ != null)
{
switch (rule_)
{
case DateGeneration.Rule.Backward:
case DateGeneration.Rule.Forward:
Utils.QL_REQUIRE(firstDate_ > effectiveDate &&
firstDate_ < terminationDate,
"first date (" + firstDate_ + ") out of effective-termination date range [" +
effectiveDate + ", " + terminationDate + ")");
// we should ensure that the above condition is still verified after adjustment
break;
case DateGeneration.Rule.ThirdWednesday:
Utils.QL_REQUIRE(IMM.isIMMdate(firstDate_, false),"first date (" + firstDate_ + ") is not an IMM date");
break;
case DateGeneration.Rule.Zero:
case DateGeneration.Rule.Twentieth:
case DateGeneration.Rule.TwentiethIMM:
case DateGeneration.Rule.OldCDS:
case DateGeneration.Rule.CDS:
Utils.QL_FAIL("first date incompatible with " + rule_ + " date generation rule");
break;
default:
Utils.QL_FAIL("unknown rule (" + rule_ + ")");
break;
}
}
if (nextToLastDate_ != null)
{
switch (rule_)
{
case DateGeneration.Rule.Backward:
case DateGeneration.Rule.Forward:
Utils.QL_REQUIRE(nextToLastDate_ > effectiveDate && nextToLastDate_ < terminationDate,
"next to last date (" + nextToLastDate_ + ") out of effective-termination date range (" +
effectiveDate + ", " + terminationDate + "]");
// we should ensure that the above condition is still verified after adjustment
break;
case DateGeneration.Rule.ThirdWednesday:
Utils.QL_REQUIRE(IMM.isIMMdate(nextToLastDate_, false), "next-to-last date (" + nextToLastDate_ +
") is not an IMM date");
break;
case DateGeneration.Rule.Zero:
case DateGeneration.Rule.Twentieth:
case DateGeneration.Rule.TwentiethIMM:
case DateGeneration.Rule.OldCDS:
case DateGeneration.Rule.CDS:
//.........这里部分代码省略.........
示例2: Schedule
public Schedule(Date effectiveDate__, Date terminationDate__, Period tenor__, Calendar calendar__,
BusinessDayConvention convention__, BusinessDayConvention terminationDateConvention__,
DateGeneration.Rule rule__, bool endOfMonth__,
Date firstDate__, Date nextToLastDate__)
{
// first save the properties
fullInterface_ = true;
tenor_ = tenor__;
calendar_ = calendar__;
convention_ = convention__;
terminationDateConvention_ = terminationDateConvention__;
rule_ = rule__;
endOfMonth_ = endOfMonth__;
firstDate_ = firstDate__;
nextToLastDate_ = nextToLastDate__;
// sanity checks
if (effectiveDate__ == null) throw new ArgumentException("Null effective date");
if (terminationDate__ == null) throw new ArgumentException("Null termination date");
if (effectiveDate__ >= terminationDate__) throw new ArgumentException("Effective date (" + effectiveDate__ +
") is later than or equal to termination date (" + terminationDate__ + ")");
if (tenor_.length() == 0)
rule_ = DateGeneration.Rule.Zero;
else if (tenor_.length() < 0)
throw new ArgumentException("Non positive tenor (" + tenor_ + ") is not allowed");
if (firstDate_ != null) {
switch (rule_) {
case DateGeneration.Rule.Backward:
case DateGeneration.Rule.Forward:
if (!(firstDate_ > effectiveDate__ && firstDate_ < terminationDate__))
throw new ArgumentException("First date (" + firstDate_ + ") is out of range [effective date (" + effectiveDate__
+ "), termination date (" + terminationDate__ + ")]");
// we should ensure that the above condition is still verified after adjustment
break;
case DateGeneration.Rule.ThirdWednesday:
if (!IMM.isIMMdate(firstDate_, false))
throw new ArgumentException("first date (" + firstDate_ + ") is not an IMM date");
break;
case DateGeneration.Rule.Zero:
case DateGeneration.Rule.Twentieth:
case DateGeneration.Rule.TwentiethIMM:
case DateGeneration.Rule.OldCDS:
case DateGeneration.Rule.CDS:
throw new ArgumentException("First date is incompatible with " + rule_ + " date generation rule");
default:
throw new ArgumentException("Unknown DateGeneration rule: " + rule_);
}
}
if (nextToLastDate_ != null) {
switch (rule_) {
case DateGeneration.Rule.Backward:
case DateGeneration.Rule.Forward:
if (!(nextToLastDate_ > effectiveDate__ && nextToLastDate_ < terminationDate__))
throw new ArgumentException("Next to last date (" + nextToLastDate_ + ") out of range [effective date (" + effectiveDate__
+ "), termination date (" + terminationDate__ + ")]");
// we should ensure that the above condition is still verified after adjustment
break;
case DateGeneration.Rule.ThirdWednesday:
if (!IMM.isIMMdate(firstDate_, false))
throw new ArgumentException("first date (" + firstDate_ + ") is not an IMM date");
break;
case DateGeneration.Rule.Zero:
case DateGeneration.Rule.Twentieth:
case DateGeneration.Rule.TwentiethIMM:
case DateGeneration.Rule.OldCDS:
case DateGeneration.Rule.CDS:
throw new ArgumentException("next to last is incompatible with " + rule_ + " date generation rule");
default:
throw new ArgumentException("Unknown DateGeneration rule: " + rule_);
}
}
// calendar needed for endOfMonth adjustment
Calendar nullCalendar = new NullCalendar();
int periods = 1;
Date seed = new Date(), exitDate;
switch (rule_) {
case DateGeneration.Rule.Zero:
tenor_ = new Period(0, TimeUnit.Years);
originalDates_.Add(effectiveDate__);
originalDates_.Add(terminationDate__);
isRegular_.Add(true);
break;
case DateGeneration.Rule.Backward:
originalDates_.Add(terminationDate__);
seed = terminationDate__;
if (nextToLastDate_ != null) {
originalDates_.Insert(0, nextToLastDate_);
Date temp = nullCalendar.advance(seed, -periods * tenor_, convention_, endOfMonth_);
isRegular_.Insert(0, temp == nextToLastDate_);
seed = nextToLastDate_;
}
exitDate = effectiveDate__;
if (firstDate_ != null)
exitDate = firstDate_;
while (true) {
//.........这里部分代码省略.........