本文整理汇总了C#中QLNet.DayCounter.yearFraction方法的典型用法代码示例。如果您正苦于以下问题:C# DayCounter.yearFraction方法的具体用法?C# DayCounter.yearFraction怎么用?C# DayCounter.yearFraction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QLNet.DayCounter
的用法示例。
在下文中一共展示了DayCounter.yearFraction方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DiscretizedCallableFixedRateBond
public DiscretizedCallableFixedRateBond(CallableBond.Arguments args,
Date referenceDate,
DayCounter dayCounter)
{
arguments_ = args;
redemptionTime_ = dayCounter.yearFraction(referenceDate, args.redemptionDate);
for (int i = 0; i < args.couponDates.Count ; ++i)
couponTimes_.Add(dayCounter.yearFraction(referenceDate, args.couponDates[i]));
for (int i = 0; i < args.callabilityDates.Count ; ++i)
callabilityTimes_.Add( dayCounter.yearFraction(referenceDate, args.callabilityDates[i]));
// similar to the tree swaption engine, we collapse similar coupon
// and exercise dates to avoid mispricing. Delete if unnecessary.
for (int i = 0; i < callabilityTimes_.Count; i++)
{
double exerciseTime = callabilityTimes_[i];
for (int j = 0; j < couponTimes_.Count ; j++)
{
if (withinNextWeek(exerciseTime, couponTimes_[j]))
couponTimes_[j] = exerciseTime;
}
}
}
示例2: DiscretizedSwap
public DiscretizedSwap(VanillaSwap.Arguments args,
Date referenceDate,
DayCounter dayCounter)
{
arguments_ = args;
fixedResetTimes_ = new InitializedList<double>(args.fixedResetDates.Count);
for (int i = 0; i < fixedResetTimes_.Count; ++i)
fixedResetTimes_[i] =
dayCounter.yearFraction(referenceDate,
args.fixedResetDates[i]);
fixedPayTimes_ = new InitializedList<double>(args.fixedPayDates.Count);
for (int i = 0; i < fixedPayTimes_.Count; ++i)
fixedPayTimes_[i] =
dayCounter.yearFraction(referenceDate,
args.fixedPayDates[i]);
floatingResetTimes_ = new InitializedList<double>(args.floatingResetDates.Count);
for (int i = 0; i < floatingResetTimes_.Count; ++i)
floatingResetTimes_[i] =
dayCounter.yearFraction(referenceDate,
args.floatingResetDates[i]);
floatingPayTimes_ = new InitializedList<double>(args.floatingPayDates.Count);
for (int i = 0; i < floatingPayTimes_.Count; ++i)
floatingPayTimes_[i] =
dayCounter.yearFraction(referenceDate,
args.floatingPayDates[i]);
}
示例3: DiscretizedSwaption
public DiscretizedSwaption(Swaption.Arguments args,
Date referenceDate,
DayCounter dayCounter)
: base(new DiscretizedSwap(args, referenceDate, dayCounter), args.exercise.type(), new List<double>())
{
arguments_=args;
exerciseTimes_ = new InitializedList<double>(arguments_.exercise.dates().Count);
for (int i = 0; i < exerciseTimes_.Count; ++i)
exerciseTimes_[i] =
dayCounter.yearFraction(referenceDate,
arguments_.exercise.date(i));
// Date adjustments can get time vectors out of synch.
// Here, we try and collapse similar dates which could cause
// a mispricing.
for (int i=0; i<arguments_.exercise.dates().Count; i++) {
Date exerciseDate = arguments_.exercise.date(i);
for (int j = 0; j < arguments_.fixedPayDates.Count; j++) {
if (withinNextWeek(exerciseDate,
arguments_.fixedPayDates[j])
// coupons in the future are dealt with below
&& arguments_.fixedResetDates[j] < referenceDate)
arguments_.fixedPayDates[j] = exerciseDate;
}
for (int j = 0; j < arguments_.fixedResetDates.Count; j++) {
if (withinPreviousWeek(exerciseDate,
arguments_.fixedResetDates[j]))
arguments_.fixedResetDates[j] = exerciseDate;
}
for (int j = 0; j < arguments_.floatingResetDates.Count; j++) {
if (withinPreviousWeek(exerciseDate,
arguments_.floatingResetDates[j]))
arguments_.floatingResetDates[j] = exerciseDate;
}
}
double lastFixedPayment =
dayCounter.yearFraction(referenceDate,
arguments_.fixedPayDates.Last() );
double lastFloatingPayment =
dayCounter.yearFraction(referenceDate,
arguments_.floatingPayDates.Last());
lastPayment_ = Math.Max(lastFixedPayment,lastFloatingPayment);
underlying_ = new DiscretizedSwap(arguments_,
referenceDate,
dayCounter);
}
示例4: DiscretizedCapFloor
public DiscretizedCapFloor(CapFloor.Arguments args,
Date referenceDate,
DayCounter dayCounter)
{
arguments_ = args;
startTimes_= new InitializedList<double>(args.startDates.Count);
for (int i = 0; i < startTimes_.Count; ++i)
startTimes_[i] = dayCounter.yearFraction(referenceDate,
args.startDates[i]);
endTimes_ = new InitializedList<double>(args.endDates.Count);
for (int i = 0; i < endTimes_.Count; ++i)
endTimes_[i] = dayCounter.yearFraction(referenceDate,
args.endDates[i]);
}
示例5: inflationYearFraction
public static double inflationYearFraction(Frequency f, bool indexIsInterpolated,
DayCounter dayCounter,
Date d1, Date d2)
{
double t=0;
if (indexIsInterpolated)
{
// N.B. we do not use linear interpolation between flat
// fixing forecasts for forecasts. This avoids awkwardnesses
// when bootstrapping the inflation curve.
t = dayCounter.yearFraction(d1, d2);
}
else
{
// I.e. fixing is constant for the whole inflation period.
// Use the value for half way along the period.
// But the inflation time is the time between period starts
KeyValuePair<Date,Date> limD1 = inflationPeriod(d1, f);
KeyValuePair<Date,Date> limD2 = inflationPeriod(d2, f);
t = dayCounter.yearFraction(limD1.Key, limD2.Key);
}
return t;
}
示例6: impliedYield
/*! Simple yield calculation based on underlying spot and
forward values, taking into account underlying income.
When \f$ t>0 \f$, call with:
underlyingSpotValue=spotValue(t),
forwardValue=strikePrice, to get current yield. For a
repo, if \f$ t=0 \f$, impliedYield should reproduce the
spot repo rate. For FRA's, this should reproduce the
relevant zero rate at the FRA's maturityDate_;
*/
public InterestRate impliedYield(double underlyingSpotValue, double forwardValue, Date settlementDate,
Compounding compoundingConvention, DayCounter dayCounter) {
double tenor = dayCounter.yearFraction(settlementDate,maturityDate_) ;
double compoundingFactor = forwardValue/ (underlyingSpotValue-spotIncome(incomeDiscountCurve_)) ;
return InterestRate.impliedRate(compoundingFactor,
tenor,
dayCounter,
compoundingConvention);
}
示例7: FuturesRateHelper
// overloaded constructors
public FuturesRateHelper(double price, Date immDate, int nMonths, Calendar calendar, BusinessDayConvention convention,
bool endOfMonth, DayCounter dayCounter, double convAdj)
: base(price)
{
convAdj_ = new Handle<Quote>(new SimpleQuote(convAdj));
if (!IMM.isIMMdate(immDate, false)) throw new ArgumentException(immDate + "is not a valid IMM date");
earliestDate_ = immDate;
latestDate_ = calendar.advance(immDate, new Period(nMonths, TimeUnit.Months), convention, endOfMonth);
yearFraction_ = dayCounter.yearFraction(earliestDate_, latestDate_);
}
示例8: seasonalityCorrection
protected virtual double seasonalityCorrection(double rate, Date atDate, DayCounter dc,
Date curveBaseDate, bool isZeroRate)
{
// need _two_ corrections in order to get: seasonality = factor[atDate-seasonalityBase] / factor[reference-seasonalityBase]
// i.e. for ZERO inflation rates you have the true fixing at the curve base so this factor must be normalized to one
// for YoY inflation rates your reference point is the year before
double factorAt = this.seasonalityFactor(atDate);
//Getting seasonality correction for either ZC or YoY
double f;
if (isZeroRate)
{
double factorBase = this.seasonalityFactor(curveBaseDate);
double seasonalityAt = factorAt / factorBase;
double timeFromCurveBase = dc.yearFraction(curveBaseDate, atDate);
f = Math.Pow(seasonalityAt, 1 / timeFromCurveBase);
}
else
{
double factor1Ybefore = this.seasonalityFactor(atDate - new Period(1, TimeUnit.Years));
f = factorAt / factor1Ybefore;
}
return (rate + 1) * f - 1;
}
示例9: equivalentRate
//! equivalent rate for a compounding period between two dates
/*! The resulting rate is calculated taking the required
day-counting rule into account.
*/
public InterestRate equivalentRate(DayCounter resultDC, Compounding comp, Frequency freq, Date d1, Date d2,
Date refStart = null,Date refEnd = null)
{
Utils.QL_REQUIRE(d2>=d1, "d1 (" + d1 + ") later than d2 (" + d2 + ")");
double t1 = dc_.yearFraction(d1, d2, refStart, refEnd);
double t2 = resultDC.yearFraction(d1, d2, refStart, refEnd);
return impliedRate(compoundFactor(t1), resultDC, comp, freq, t2);
}
示例10: impliedRate
//! implied rate for a given compound factor between two dates.
/*! The resulting rate is calculated taking the required
day-counting rule into account.
*/
public static InterestRate impliedRate(double compound, DayCounter resultDC, Compounding comp, Frequency freq, Date d1, Date d2,
Date refStart = null, Date refEnd = null)
{
Utils.QL_REQUIRE(d2>=d1, "d1 (" + d1 + ") later than d2 (" + d2 + ")");
double t = resultDC.yearFraction(d1, d2, refStart, refEnd);
return impliedRate(compound, resultDC, comp, freq, t);
}
示例11: equivalentRate
public InterestRate equivalentRate(Date d1, Date d2, DayCounter resultDC, Compounding comp, Frequency freq) {
if (!(d2 > d1)) throw new ArgumentException("d1 (" + d1 + ") " +
"later than or equal to d2 (" + d2 + ")");
double t1 = dc_.yearFraction(d1, d2);
double t2 = resultDC.yearFraction(d1, d2);
return impliedRate(compoundFactor(t1), t2, resultDC, comp, freq);
}
示例12: impliedRate
public static InterestRate impliedRate(double compound, Date d1, Date d2,
DayCounter resultDC, Compounding comp, Frequency freq) {
if (!(d2 > d1))
throw new ArgumentException("d1 (" + d1 + ") " + "later than or equal to d2 (" + d2 + ")");
double t = resultDC.yearFraction(d1, d2);
return impliedRate(compound, t, resultDC, comp, freq);
}