public void TestSelfConsistency() { var result = new double[Rates.Length]; for (var i = 0; i < Rates.Length; i++) { result[i] = Rates[i] * Times[i]; } var vectorRatesTimes = new DoubleVector(result); vectorRatesTimes.Multiply(-1.0d); vectorRatesTimes.Apply(Math.Exp); var index = 0; foreach (var pointvalue in vectorRatesTimes) { var yearFraction = (decimal)Times[index]; foreach (var comp in _compounding) { var result2 = RateAnalytics.DiscountFactorToZeroRate(1.0m, (decimal)pointvalue, yearFraction, comp); var result1 = RateAnalytics.ZeroRateToDiscountFactor(result2, yearFraction, comp); Debug.WriteLine($"DFIn : {pointvalue} DFOut: {(double) result1}"); Assert.AreEqual((double)result1, pointvalue, .000000001); } index++; } }
public void DiscountFactorToZeroRateTest() { var result = new double[Rates.Length]; for (var i = 0; i < Rates.Length; i++) { result[i] = Rates[i] * Times[i]; } var vectorRatesTimes = new DoubleVector(result); vectorRatesTimes.Multiply(-1.0d); vectorRatesTimes.Apply(Math.Exp); var index = 0; foreach (var pointvalue in vectorRatesTimes) { var yearFraction = (decimal)Times[index]; foreach (var comp in _compounding) { var result2 = RateAnalytics.DiscountFactorToZeroRate(1.0m, (decimal)pointvalue, yearFraction, comp); Debug.WriteLine($"Rate : {result2} Time: {yearFraction}"); } index++; } }
public void DiscountFactorToZeroRate5Test() { double result = (double)RateAnalytics.DiscountFactorToZeroRate(0.9m, 0.8m, 0.5m, 0.25m); Assert.AreEqual(0.24264068, result, 0.00000001); result = (double)RateAnalytics.DiscountFactorToZeroRate(0.9m, 0.8m, 0.5m, 0); Assert.AreEqual(0.23556607, result, 0.00000001); }
public void DiscountFactorToZeroRate3Test() { double result = RateAnalytics.DiscountFactorToZeroRate(0.9, 0.5, "Quarterly"); Assert.AreEqual(0.21637021, result, 0.00000001); result = RateAnalytics.DiscountFactorToZeroRate(0.9, 0.5, "SemiAnnual"); Assert.AreEqual(0.22222222, result, 0.00000001); }
internal static double GetAdjustedDiscountFactor(DateTime baseDate, DateTime baseCurveDate, IDayCounter dayCounter, double zeroRateSpread, IRateCurve baseCurve) { const double compoundingPeriod = 0.25; // Convert to Zero Rate double yearFraction = dayCounter.YearFraction(baseDate, baseCurveDate); double df0 = baseCurve.GetDiscountFactor(baseCurveDate); double z0 = RateAnalytics.DiscountFactorToZeroRate(df0, yearFraction, compoundingPeriod); // Add the spread double z = z0 + zeroRateSpread; // Change back double discountFactor = RateAnalytics.ZeroRateToDiscountFactor(z, yearFraction, compoundingPeriod); return(discountFactor); }
public void DiscountFactorToZeroRate2Test() { double result = RateAnalytics.DiscountFactorToZeroRate(0.9, 0.5, "Quarterly"); Assert.AreEqual(0.21637021, result, 0.00000001); result = RateAnalytics.DiscountFactorToZeroRate(0.9, 0.5, "Continuous"); Assert.AreEqual(0.21072103, result, 0.00000001); result = RateAnalytics.DiscountFactorToZeroRate(0.9, 0.5, "Weekly"); Assert.AreEqual(0.21114856, result, 0.00000001); result = RateAnalytics.DiscountFactorToZeroRate(0.9, 0.5, "Daily"); Assert.AreEqual(0.21078186, result, 0.00000001); result = RateAnalytics.DiscountFactorToZeroRate(0.9, 0.5, "Annual"); Assert.AreEqual(0.23456790, result, 0.00000001); }
public double ShortEndTargetFunction(double guess) { DateTime baseDate = _baseCurve.GetBaseDate(); DateTime date0 = _assetDates.First(); DateTime date1 = _assetDates.Last(); double d0 = _baseCurve.GetDiscountFactor(date0); double d1 = _baseCurve.GetDiscountFactor(date1); double y = _dayCounter.YearFraction(date0, date1); double y0 = _dayCounter.YearFraction(baseDate, date0); double y1 = _dayCounter.YearFraction(baseDate, date1); double z0 = RateAnalytics.DiscountFactorToZeroRate(d0, y0, _compoundingPeriod); double z1 = RateAnalytics.DiscountFactorToZeroRate(d1, y1, _compoundingPeriod); double projectedRate = 1 / y * (d0 / d1 - 1); double basisSpread = (double)_asset.MarketQuote.value; double term1 = Math.Pow(1 + 0.25 * (z0 + guess), -4 * y0); double term2 = Math.Pow(1 + 0.25 * (z1 + guess), -4 * y1); double term3 = y * term2 * (projectedRate + basisSpread); double result = -term1 + term2 + term3; return(result); }
/// <summary> /// Evaluates the implied quote. /// </summary> /// <returns></returns> protected virtual Decimal EvaluateImpliedQuote()//TODO this won't work. { return(RateAnalytics.DiscountFactorToZeroRate(AnalyticParameters.StartDiscountFactor, AnalyticParameters.EndDiscountFactor, AnalyticParameters.YearFraction, AnalyticParameters.PeriodAsTimesPerYear)); }
///<summary> /// Converts a discount factor to a compounding zero rate. ///</summary> ///<param name="yearFraction">The year Fraction.</param> ///<param name="discountFactor">The discount factor.</param> ///<param name="frequency">The compounding frequency. Can take: Continuous, Daily, Quarterly, /// Semi-Annual,SemiAnnual,Semi and Annual</param> ///<returns>The compounded zero rate requested.</returns> public double DiscountFactorToZeroRate3(double yearFraction, double discountFactor, String frequency) { return(RateAnalytics.DiscountFactorToZeroRate(discountFactor, yearFraction, frequency)); }
/// <summary> /// Converts from the zero rate to a terminal wealth. /// </summary> /// <param name="startDiscountFactor"></param> /// <param name="endDiscountFactor"></param> /// <param name="yearFraction"></param> /// <param name="compoundingPeriod"></param> /// <returns></returns> public decimal DiscountFactorToZeroRate2(decimal startDiscountFactor, decimal endDiscountFactor, decimal yearFraction, decimal compoundingPeriod) { return(RateAnalytics.DiscountFactorToZeroRate(startDiscountFactor, endDiscountFactor, yearFraction, compoundingPeriod)); }
///<summary> /// Converts a discount factor to a compounding zero rate. ///</summary> ///<param name="targetDate">The target date.</param> ///<param name="discountFactor">The discount factor.</param> ///<param name="frequency">The compounding frequency. Can take: Continuous, Daily, Quarterly, /// Semi-Annual,SemiAnnual,Semi and Annual.</param> ///<param name="baseDate">The base date.</param> ///<returns>The compounded zero rate requested.</returns> public double DiscountFactorToZeroRate1(DateTime baseDate, DateTime targetDate, double discountFactor, String frequency) { double yearFraction = Actual365.Instance.YearFraction(baseDate, targetDate); return(RateAnalytics.DiscountFactorToZeroRate(discountFactor, yearFraction, frequency)); }