本文整理匯總了C#中QLNet.Period.length方法的典型用法代碼示例。如果您正苦於以下問題:C# Period.length方法的具體用法?C# Period.length怎麽用?C# Period.length使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類QLNet.Period
的用法示例。
在下文中一共展示了Period.length方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: AmortizingFixedRateBond
public AmortizingFixedRateBond(
int settlementDays,
Calendar calendar,
double faceAmount,
Date startDate,
Period bondTenor,
Frequency sinkingFrequency,
double coupon,
DayCounter accrualDayCounter,
BusinessDayConvention paymentConvention = BusinessDayConvention.Following,
Date issueDate = null)
:base(settlementDays, calendar, issueDate)
{
frequency_ = sinkingFrequency;
dayCounter_ = accrualDayCounter;
Utils.QL_REQUIRE( bondTenor.length() > 0,() =>
"bond tenor must be positive. "
+ bondTenor + " is not allowed." );
maturityDate_ = startDate + bondTenor;
maturityDate_ = startDate + bondTenor;
schedule_ = sinkingSchedule(startDate, bondTenor, sinkingFrequency, calendar);
cashflows_ = new FixedRateLeg(schedule_)
.withCouponRates(coupon, accrualDayCounter)
.withNotionals(sinkingNotionals(bondTenor, sinkingFrequency, coupon, faceAmount))
.withPaymentAdjustment(paymentConvention).value();
addRedemptionsToCashflows();
}
示例2: pair
public pair(Period p)
{
switch (p.units()) {
case TimeUnit.Days:
lo = hi = p.length(); break;
case TimeUnit.Weeks:
lo = hi = 7 * p.length(); break;
case TimeUnit.Months:
lo = 28 * p.length(); hi = 31 * p.length(); break;
case TimeUnit.Years:
lo = 365 * p.length(); hi = 366 * p.length(); break;
default:
throw new ArgumentException("Unknown TimeUnit: " + p.units());
}
}
示例3: daysMinMax
KeyValuePair<int, int> daysMinMax(Period p)
{
switch (p.units()) {
case TimeUnit.Days:
return new KeyValuePair<int, int>(p.length(), p.length());
case TimeUnit.Weeks:
return new KeyValuePair<int, int>(7*p.length(), 7*p.length());
case TimeUnit.Months:
return new KeyValuePair<int, int>(28*p.length(), 31*p.length());
case TimeUnit.Years:
return new KeyValuePair<int, int>(365 * p.length(), 366 * p.length());
default:
throw new ApplicationException("unknown time unit (" + p.units() + ")");
}
}
示例4: Schedule
public Schedule( Date effectiveDate, Date terminationDate, Period tenor, Calendar calendar,
BusinessDayConvention convention, BusinessDayConvention terminationDateConvention,
DateGeneration.Rule rule, bool endOfMonth, Date firstDate = null, Date nextToLastDate = null)
{
// first save the properties
fullInterface_ = true;
tenor_ = tenor;
if ( calendar == null )
calendar_ = new NullCalendar();
else
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:
//.........這裏部分代碼省略.........
示例5: initialize
public override void initialize(FloatingRateCoupon coupon)
{
coupon_ = coupon as CmsCoupon;
Utils.QL_REQUIRE( coupon_ != null, () => "CMS coupon needed" );
gearing_ = coupon_.gearing();
spread_ = coupon_.spread();
fixingDate_ = coupon_.fixingDate();
paymentDate_ = coupon_.date();
SwapIndex swapIndex = coupon_.swapIndex();
rateCurve_ = swapIndex.forwardingTermStructure().link;
Date today = Settings.evaluationDate();
if (paymentDate_ > today)
discount_ = rateCurve_.discount(paymentDate_);
else
discount_ = 1.0;
spreadLegValue_ = spread_ * coupon_.accrualPeriod() * discount_;
if (fixingDate_ > today) {
swapTenor_ = swapIndex.tenor();
VanillaSwap swap = swapIndex.underlyingSwap(fixingDate_);
swapRateValue_ = swap.fairRate();
double bp = 1.0e-4;
annuity_ = (swap.floatingLegBPS() / bp);
int q = (int)swapIndex.fixedLegTenor().frequency();
Schedule schedule = swap.fixedSchedule();
DayCounter dc = swapIndex.dayCounter();
//DayCounter dc = coupon.dayCounter();
double startTime = dc.yearFraction(rateCurve_.referenceDate(), swap.startDate());
double swapFirstPaymentTime = dc.yearFraction(rateCurve_.referenceDate(), schedule.date(1));
double paymentTime = dc.yearFraction(rateCurve_.referenceDate(), paymentDate_);
double delta = (paymentTime - startTime) / (swapFirstPaymentTime - startTime);
switch (modelOfYieldCurve_) {
case GFunctionFactory.YieldCurveModel.Standard:
gFunction_ = GFunctionFactory.newGFunctionStandard(q, delta, swapTenor_.length());
break;
case GFunctionFactory.YieldCurveModel.ExactYield:
gFunction_ = GFunctionFactory.newGFunctionExactYield(coupon_);
break;
case GFunctionFactory.YieldCurveModel.ParallelShifts: {
Handle<Quote> nullMeanReversionQuote = new Handle<Quote>(new SimpleQuote(0.0));
gFunction_ = GFunctionFactory.newGFunctionWithShifts(coupon_, nullMeanReversionQuote);
}
break;
case GFunctionFactory.YieldCurveModel.NonParallelShifts:
gFunction_ = GFunctionFactory.newGFunctionWithShifts(coupon_, meanReversion_);
break;
default:
throw new ApplicationException("unknown/illegal gFunction type");
}
vanillaOptionPricer_ = new BlackVanillaOptionPricer(swapRateValue_, fixingDate_, swapTenor_, swaptionVolatility().link);
}
}
示例6: checkSwapTenor
protected void checkSwapTenor(Period swapTenor, bool extrapolate)
{
if (!(swapTenor.length() > 0))
throw new ApplicationException("non-positive swap tenor (" + swapTenor + ") given");
if (!(extrapolate || allowsExtrapolation() || swapTenor <= maxSwapTenor()))
throw new ApplicationException("swap tenor (" + swapTenor + ") is past max tenor (" + maxSwapTenor() + ")");
}
示例7: checkRange
protected void checkRange(Date optionDate, Period bondTenor, double k, bool extrapolate)
{
base.checkRange(timeFromReference(optionDate),
extrapolate);
Utils.QL_REQUIRE( bondTenor.length() > 0, () =>
"negative bond tenor (" + bondTenor + ") given");
Utils.QL_REQUIRE(extrapolate || allowsExtrapolation() ||
bondTenor <= maxBondTenor(), () =>
"bond tenor (" + bondTenor + ") is past max tenor ("
+ maxBondTenor() + ")");
Utils.QL_REQUIRE(extrapolate || allowsExtrapolation() ||
( k >= minStrike() && k <= maxStrike() ), () =>
"strike (" + k + ") is outside the curve domain ["
+ minStrike() + "," + maxStrike()+ "]");
}
示例8: seasonalityFactor
//! The factor returned is NOT normalized relative to ANYTHING.
public virtual double seasonalityFactor(Date to)
{
Date from = seasonalityBaseDate();
Frequency factorFrequency = frequency();
int nFactors = seasonalityFactors().Count;
Period factorPeriod = new Period(factorFrequency);
int which = 0;
if (from==to)
{
which = 0;
}
else
{
// days, weeks, months, years are the only time unit possibilities
int diffDays = Math.Abs(to - from); // in days
int dir = 1;
if(from > to)dir = -1;
int diff;
if (factorPeriod.units() == TimeUnit.Days)
{
diff = dir*diffDays;
}
else if (factorPeriod.units() == TimeUnit.Weeks)
{
diff = dir * (diffDays / 7);
}
else if (factorPeriod.units() == TimeUnit.Months)
{
KeyValuePair<Date,Date> lim = Utils.inflationPeriod(to, factorFrequency);
diff = diffDays / (31*factorPeriod.length());
Date go = from + dir*diff*factorPeriod;
while ( !(lim.Key <= go && go <= lim.Value) )
{
go += dir*factorPeriod;
diff++;
}
diff=dir*diff;
}
else if (factorPeriod.units() == TimeUnit.Years)
{
throw new ApplicationException(
"seasonality period time unit is not allowed to be : " + factorPeriod.units());
}
else
{
throw new ApplicationException("Unknown time unit: " + factorPeriod.units());
}
// now adjust to the available number of factors, direction dependent
if (dir==1)
{
which = diff % nFactors;
}
else
{
which = (nFactors - (-diff % nFactors)) % nFactors;
}
}
return seasonalityFactors()[which];
}
示例9: swapLength
//@}
//! implements the conversion between swap tenor and swap (time) length
public double swapLength(Period p)
{
if (!(p.length()>0))
throw new ApplicationException("non-positive swap tenor (" + p + ") given");
// while using the reference date is arbitrary it is coherent between
// different swaption structures defined on the same reference date.
//
Date start = referenceDate();
Date end = start + p;
return swapLength(start, end);
}
示例10: checkSwapTenor
protected void checkSwapTenor(Period swapTenor, bool extrapolate)
{
Utils.QL_REQUIRE(swapTenor.length() > 0, "non-positive swap tenor (" + swapTenor + ") given");
Utils.QL_REQUIRE(extrapolate || allowsExtrapolation() || swapTenor <= maxSwapTenor(),
"swap tenor (" + swapTenor + ") is past max tenor (" + maxSwapTenor() + ")");
}
示例11: swapLength
//! implements the conversion between swap tenor and swap (time) length
public double swapLength(Period swapTenor)
{
Utils.QL_REQUIRE(swapTenor.length() > 0, "non-positive swap tenor (" + swapTenor + ") given");
switch (swapTenor.units())
{
case TimeUnit.Months:
return swapTenor.length() / 12.0;
case TimeUnit.Years:
return swapTenor.length();
default:
Utils.QL_FAIL("invalid Time Unit (" + swapTenor.units() + ") for swap length");
return 0;
}
}
示例12: advance
public Date advance(Date d, Period p, BusinessDayConvention c, bool endOfMonth)
{
return advance(d, p.length(), p.units(), c, endOfMonth);
}
示例13: advance
/// <summary>
/// Advances the given date as specified by the given period and
/// returns the result.
/// </summary>
/// <remarks>The input date is not modified.</remarks>
public Date advance( Date d, Period p, BusinessDayConvention c = BusinessDayConvention.Following, bool endOfMonth = false)
{
return advance(d, p.length(), p.units(), c, endOfMonth);
}
示例14: 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) {
//.........這裏部分代碼省略.........