public static bool eurliborEOM(Period p) { switch (p.units()) { case TimeUnit.Days: case TimeUnit.Weeks: return false; case TimeUnit.Months: case TimeUnit.Years: return true; default: throw new ArgumentException("Unknown TimeUnit: " + p.units()); } }
public static BusinessDayConvention eurliborConvention(Period p) { switch (p.units()) { case TimeUnit.Days: case TimeUnit.Weeks: return BusinessDayConvention.Following; case TimeUnit.Months: case TimeUnit.Years: return BusinessDayConvention.ModifiedFollowing; default: throw new ArgumentException("Unknown TimeUnit: " + p.units()); } }
private static BusinessDayConvention shiborConvention(Period p) { switch (p.units()) { case TimeUnit.Days: case TimeUnit.Weeks: return BusinessDayConvention.Following; case TimeUnit.Months: case TimeUnit.Years: return BusinessDayConvention.ModifiedFollowing; default: Utils.QL_FAIL("invalid time units"); return BusinessDayConvention.Unadjusted; } }
public override double seasonalityFactor(Date to) { int dir = 1; Date from = seasonalityBaseDate(); int fromMonth = from.month(); int toMonth = to.month(); Period factorPeriod = new Period(frequency()); if (toMonth < fromMonth) { int dummy = fromMonth; fromMonth = toMonth; toMonth = dummy; dir = 0; // We calculate invers Factor in loop } Utils.QL_REQUIRE(seasonalityFactors().Count == 12 && factorPeriod.units() == TimeUnit.Months, () => "12 monthly seasonal factors needed for Kerkhof Seasonality:" + " got " + seasonalityFactors().Count); double seasonalCorrection = 1.0; for (int i = fromMonth; i < toMonth; i++) { seasonalCorrection *= seasonalityFactors()[i]; } if (dir == 0) // invers Factor required { seasonalCorrection = 1 / seasonalCorrection; } return(seasonalCorrection); }
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() + ")"); } }
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()); } }
public static bool liborEOM(Period p) { switch (p.units()) { case TimeUnit.Days: case TimeUnit.Weeks: return false; case TimeUnit.Months: case TimeUnit.Years: return true; default: throw new ApplicationException("invalid time units"); } }
public static BusinessDayConvention liborConvention(Period p) { switch (p.units()) { case TimeUnit.Days: case TimeUnit.Weeks: return BusinessDayConvention.Following; case TimeUnit.Months: case TimeUnit.Years: return BusinessDayConvention.ModifiedFollowing; default: throw new ApplicationException("invalid time units"); } }
//! 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 = 0; 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) { Utils.QL_FAIL("seasonality period time unit is not allowed to be : " + factorPeriod.units()); } else { Utils.QL_FAIL("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]); }
public Date advance(Date d, Period p, BusinessDayConvention c, bool endOfMonth) { return(advance(d, p.length(), p.units(), c, endOfMonth)); }
//! 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]; }
private bool allowsEndOfMonth(Period tenor) { return((tenor.units() == TimeUnit.Months || tenor.units() == TimeUnit.Years) && tenor >= new Period(1, TimeUnit.Months)); }
//! 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; } }
/// <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)); }
public Date advance(Date d, Period p, BusinessDayConvention c, bool endOfMonth) { return advance(d, p.length(), p.units(), c, endOfMonth); }
/// <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); }