/// <summary> /// Computes today's value of an annuity factor for a vanilla /// interest rate swap. /// </summary> /// <param name="forwardSwapRate">Forward swap rate, expressed as a /// decimal. /// Example: if the forward swap rate is 6.820177%, call the function /// with the value 0.006820177.</param> /// <param name="dfSwapStart">Discount factor from today to the start /// of the swap. /// Example: 6M option into a 2YR quarterly swap. /// The appropriate discount factor is for the tenor 6M.</param> /// <param name="dfSwapEnd">Discount factor from today to the end of /// the swap. /// Example: 6M option into a 2YR quarterly swap. /// The appropriate discount factor is for the tenor (6M + 2YR).</param> /// <returns>Annuity factor for a vanilla interest rate swap.</returns> public double ComputeAnnuityFactor(double forwardSwapRate, double dfSwapStart, double dfSwapEnd) { return(SwapAnalytics.ComputeAnnuityFactor(forwardSwapRate, dfSwapStart, dfSwapEnd)); }
/// <summary> /// Gets the delta0 for a collection of coupon cashflows provided. /// </summary> /// <param name="paymentDiscountFactors">The discount factors.</param> /// <param name="yearFractions">The year fractions.</param> /// <param name="notionals">The notionals</param> /// <param name="fixedFlag">Delta0 is zero for fixed coupons.</param> /// <returns>The break even rate.</returns> public double Delta0(Excel.Range notionals, Excel.Range paymentDiscountFactors, Excel.Range yearFractions, bool fixedFlag) { var unqNotionals = DataRangeHelper.StripDoubleRange(notionals); var unqPaymentDiscountFactors = DataRangeHelper.StripDoubleRange(paymentDiscountFactors); var unqYearFractions = DataRangeHelper.StripDoubleRange(yearFractions); return(SwapAnalytics.Delta0(unqNotionals.ToArray(), unqPaymentDiscountFactors.ToArray(), unqYearFractions.ToArray(), fixedFlag)); }
public void TestDelta0discountCoupon() { for (var i = 1; i < 10; i++) { var delta0 = SwapAnalytics.Delta0DiscountCoupon(1000000.0, 0.25, 0.07, Math.Exp(-0.07 * i)); Debug.WriteLine(String.Format("Delta1 : {0} Time: {1}", delta0, i)); } }
public void TestDelta1Amount() { for (var i = 1; i < 10; i++) { var delta1 = SwapAnalytics.Delta1ForAnAmount(10000000.0, Math.Exp(-0.1 * i), 0.25, i); Debug.WriteLine(String.Format("Delta1 : {0} Time: {1}", delta1, i)); } }
/// <summary> /// Gets the delta0 for a collection of coupon cashflows provided. /// </summary> /// <param name="paymentDiscountFactors">The discount factors.</param> /// <param name="amounts">The amounts</param> /// <param name="curveYearFractions">The curve year fractions.</param> /// <param name="periodAsTimesPerYears">Delta1 compounding Frequency.</param> /// <returns>The break even rate.</returns> public double Delta1(Excel.Range amounts, Excel.Range paymentDiscountFactors, Excel.Range curveYearFractions, double periodAsTimesPerYears) { var unqNotionals = DataRangeHelper.StripDoubleRange(amounts); var unqCouponPaymentDiscountFactors = DataRangeHelper.StripDoubleRange(paymentDiscountFactors); var unqYearFractions = DataRangeHelper.StripDoubleRange(curveYearFractions); return(SwapAnalytics.Delta1(unqNotionals.ToArray(), unqCouponPaymentDiscountFactors.ToArray(), unqYearFractions.ToArray(), periodAsTimesPerYears)); }
/// <summary> /// Gets the break even rate for a collection of coupon cashflows provided. /// </summary> /// <param name="paymentDiscountFactors">The discount factors.</param> /// <param name="yearFractions">The year fractions.</param> /// <param name="forwardRates">The forward rates.</param> /// <param name="notionals">The notionals</param> /// <returns>The break even rate.</returns> public double BreakEvenRate(Excel.Range notionals, Excel.Range forwardRates, Excel.Range paymentDiscountFactors, Excel.Range yearFractions) { var unqNotionals = DataRangeHelper.StripDoubleRange(notionals); var unqForwardRates = DataRangeHelper.StripDoubleRange(forwardRates); var unqPaymentDiscountFactors = DataRangeHelper.StripDoubleRange(paymentDiscountFactors); var unqYearFractions = DataRangeHelper.StripDoubleRange(yearFractions); return(SwapAnalytics.BreakEvenRate(unqNotionals.ToArray(), unqForwardRates.ToArray(), unqPaymentDiscountFactors.ToArray(), unqYearFractions.ToArray())); }
public void ComputeAnnuityFactorTest() { const double forwardSwapRate = 0.0615; // 6.15% const double dfSwapStart = 0.95; const double dfSwapEnd = 0.80; const double Expected = 2.43902439; double actual = SwapAnalytics.ComputeAnnuityFactor(forwardSwapRate, dfSwapStart, dfSwapEnd); Assert.AreEqual(Expected, actual, 0.00000001); }
public void Delta0CouponTest() { const double notional = 100; const double dayFraction = 0.5; // 6 months const double rate = 0.0615; // 6.15% const double paymentDiscountFactor = 0.92; const double expected = -0.0046; double actual = SwapAnalytics.Delta0Coupon(notional, dayFraction, rate, paymentDiscountFactor); Assert.AreEqual(expected, actual); }
public void Delta1ForAnAmountTest() { const double amount = 100000; const double paymentDiscountFactor = 0.92; const double periodAsTimesPerYear = 6; // ie every 2 months const double curveYearFraction = 0.5; // ie every 6 months const double expected = 2.29933398; double actual = SwapAnalytics.Delta1ForAnAmount(amount, paymentDiscountFactor, periodAsTimesPerYear, curveYearFraction); Assert.AreEqual(expected, actual, 1e-8); }
/// <summary> /// Evaluates the delta wrt the discount rate R. /// </summary> /// <param name="notionals">The notionals.</param> /// <param name="yearfractions">The daycount fractions.</param> /// <param name="rates">The rates.</param> /// <param name="paymentDiscountFactors">The payment discount factors.</param> /// <param name="periodAsTimesPerYears">The compounding year fractions.</param> /// <param name="curveYearFractions">The time to payment year fractions.</param> /// <returns></returns> public double Delta1Arrays2(Excel.Range notionals, Excel.Range yearfractions, Excel.Range rates, Excel.Range paymentDiscountFactors, Excel.Range curveYearFractions, double periodAsTimesPerYears) { var unqNotionals = DataRangeHelper.StripDoubleRange(notionals); var unqRates = DataRangeHelper.StripDoubleRange(rates); var unqCouponPaymentDiscountFactors = DataRangeHelper.StripDoubleRange(paymentDiscountFactors); var unqYearFractions = DataRangeHelper.StripDoubleRange(yearfractions); var unqCurveYearFractions = DataRangeHelper.StripDoubleRange(curveYearFractions); return(SwapAnalytics.Delta1Arrays(unqNotionals.ToArray(), unqYearFractions.ToArray(), unqRates.ToArray(), unqCouponPaymentDiscountFactors.ToArray(), unqCurveYearFractions.ToArray(), periodAsTimesPerYears)); }
/// <summary> /// Gets the delta0 for a collection of coupon cashlows provided. /// </summary> /// <param name="paymentDiscountFactors">The discount factors.</param> /// <param name="yearFractions">The year fractions.</param> /// <param name="notionals">The notionals</param> /// <param name="principalPaymentDiscountFactors">The dfs for the principal exchanges.</param> /// <param name="fixedFlag">Delta0 is zero for fixed coupons.</param> /// <param name="principalNotionals">The principal Exchanges.</param> /// <returns>The break even rate.</returns> public double Delta0WithExchanges(Excel.Range notionals, Excel.Range paymentDiscountFactors, Excel.Range yearFractions, Excel.Range principalNotionals, Excel.Range principalPaymentDiscountFactors, Boolean fixedFlag) { var unqNotionals = DataRangeHelper.StripDoubleRange(notionals); var unqCouponPaymentDiscountFactors = DataRangeHelper.StripDoubleRange(paymentDiscountFactors); var unqYearFractions = DataRangeHelper.StripDoubleRange(yearFractions); var unqPrincipalNotionals = DataRangeHelper.StripDoubleRange(principalNotionals); var unqPrincipalPaymentDiscountFactors = DataRangeHelper.StripDoubleRange(principalPaymentDiscountFactors); return(SwapAnalytics.Delta0WithExchanges(unqNotionals.ToArray(), unqCouponPaymentDiscountFactors.ToArray(), unqYearFractions.ToArray(), unqPrincipalNotionals.ToArray(), unqPrincipalPaymentDiscountFactors.ToArray(), fixedFlag)); }
public void Delta1ForNotionalTest() { const double notional = 100; const double yearfraction = 0.5; const double rate = 0.0615; const double paymentDiscountFactor = 0.92; const double periodAsTimesPerYear = 6; const double curveYearFraction = 0.5; const double expected = 0.00007070; double actual = SwapAnalytics.Delta1ForNotional(notional, yearfraction, rate, paymentDiscountFactor, periodAsTimesPerYear, curveYearFraction); Assert.AreEqual(expected, actual, 1e-8); }
/// <summary> /// Gets the npv for a collection of coupons and principal exchanges provided. /// </summary> /// <param name="couponPaymentDiscountFactors">The discount factors.</param> /// <param name="yearFractions">The year fractions.</param> /// <param name="forwardRates">The forward rates.</param> /// <param name="couponNotionals">The notionals of the coupons.</param> /// <param name="principalNotionals">The principal exchange notionals.</param> /// <param name="principalPaymentDiscountFactors">The payment discount factors for the principal exchanges.</param> /// <returns>The break even rate.</returns> public double NPVWithExchanges(Excel.Range couponNotionals, Excel.Range forwardRates, Excel.Range couponPaymentDiscountFactors, Excel.Range yearFractions, Excel.Range principalNotionals, Excel.Range principalPaymentDiscountFactors) { var unqCouponNotionals = DataRangeHelper.StripDoubleRange(couponNotionals); var unqForwardRates = DataRangeHelper.StripDoubleRange(forwardRates); var unqCouponPaymentDiscountFactors = DataRangeHelper.StripDoubleRange(couponPaymentDiscountFactors); var unqYearFractions = DataRangeHelper.StripDoubleRange(yearFractions); var unqPrincipalNotionals = DataRangeHelper.StripDoubleRange(principalNotionals); var unqPrincipalPaymentDiscountFactors = DataRangeHelper.StripDoubleRange(principalPaymentDiscountFactors); return(SwapAnalytics.NPVWithExchanges(unqCouponNotionals.ToArray(), unqForwardRates.ToArray(), unqCouponPaymentDiscountFactors.ToArray(), unqYearFractions.ToArray(), unqPrincipalNotionals.ToArray(), unqPrincipalPaymentDiscountFactors.ToArray())); }
/// <summary> /// Gets the delta0 for a collection of coupon cashflows provided. /// </summary> /// <param name="paymentDiscountFactors">The discount factors.</param> /// <param name="yearFractions">The year fractions.</param> /// <param name="notionals">The notionals</param> /// <param name="principalPaymentDiscountFactors">The dfs for the principal exchanges.</param> /// <param name="principalCurveYearFractions">The principal exchange curve year fractions.</param> /// <param name="compoundingFrequency">Delta1 compounding Frequency.</param> /// <param name="couponCurveYearsFractions">The coupon time to payments.</param> /// <param name="principalNotionals">The principal Exchanges.</param> /// <returns>The break even rate.</returns> public double Delta1WithExchanges(Excel.Range notionals, Excel.Range paymentDiscountFactors, Excel.Range yearFractions, Excel.Range couponCurveYearsFractions, Excel.Range principalNotionals, Excel.Range principalPaymentDiscountFactors, Excel.Range principalCurveYearFractions, double compoundingFrequency) { var unqNotionals = DataRangeHelper.StripDoubleRange(notionals); var unqCouponPaymentDiscountFactors = DataRangeHelper.StripDoubleRange(paymentDiscountFactors); var unqYearFractions = DataRangeHelper.StripDoubleRange(yearFractions); var unqCouponCurveYearsFractions = DataRangeHelper.StripDoubleRange(couponCurveYearsFractions); var unqPrincipalNotionals = DataRangeHelper.StripDoubleRange(principalNotionals); var unqPrincipalPaymentDiscountFactors = DataRangeHelper.StripDoubleRange(principalPaymentDiscountFactors); var unqPrincipalCurveYearFractions = DataRangeHelper.StripDoubleRange(principalCurveYearFractions); return(SwapAnalytics.Delta1WithExchanges(unqNotionals.ToArray(), unqCouponPaymentDiscountFactors.ToArray(), unqYearFractions.ToArray(), unqCouponCurveYearsFractions.ToArray(), unqPrincipalNotionals.ToArray(), unqPrincipalPaymentDiscountFactors.ToArray(), unqPrincipalCurveYearFractions.ToArray(), compoundingFrequency)); }
public void TestComputeAnnuityFactor() { // Test #1: 2M option into a 3YR swap. _forwardSwapRate = 6.820177 / 100.0; _dfSwapStart = 0.99437584934; _dfSwapEnd = 0.81178430567; _expected = 2.67723; _actual = SwapAnalytics.ComputeAnnuityFactor(_forwardSwapRate, _dfSwapStart, _dfSwapEnd); Assert.AreEqual(_expected, _actual, _tolerance); // Test #2: 6M option into a 4YR swap. _forwardSwapRate = 6.824469 / 100.0; _dfSwapStart = 0.96673145605; _dfSwapEnd = 0.73858756401; _expected = 3.33348; _actual = SwapAnalytics.ComputeAnnuityFactor(_forwardSwapRate, _dfSwapStart, _dfSwapEnd); // Test #3: 5YR option into a 10YR swap. _forwardSwapRate = 6.352136 / 100.0; _dfSwapStart = 0.73016181577; _dfSwapEnd = 0.39069662207; _expected = 5.34411; _actual = SwapAnalytics.ComputeAnnuityFactor(_forwardSwapRate, _dfSwapStart, _dfSwapEnd); // Test #4: 3YR option into a 7YR swap. _forwardSwapRate = 6.507184 / 100.0; _dfSwapStart = 0.81864063634; _dfSwapEnd = 0.52290276017; _expected = 4.54479; _actual = SwapAnalytics.ComputeAnnuityFactor(_forwardSwapRate, _dfSwapStart, _dfSwapEnd); }
/// <summary> /// Evaluates the delta wrt the forward rate R for discount coupon. /// </summary> /// <param name="notional">The notional for that period.</param> /// <param name="paymentDiscountFactor">The payment discount factor.</param> /// <param name="dayFraction">The year fraction.</param> /// <param name="rate">The rate.</param> /// <returns></returns> public double Delta0DiscountCoupon(double notional, double dayFraction, double rate, double paymentDiscountFactor) { return(SwapAnalytics.Delta0DiscountCoupon(notional, dayFraction, rate, paymentDiscountFactor)); }
/// <summary> /// Evaluates the delta wrt the discount rate R. /// </summary> /// <param name="amount">The amount for that period.</param> /// <param name="paymentDiscountFactor">The payment discount factor.</param> /// <param name="periodAsTimesPerYear">the compounding year fraction.</param> /// <param name="curveYearFraction">The time to payment year fraction.</param> /// <returns></returns> public double Delta1ForAnAmount(double amount, double paymentDiscountFactor, double periodAsTimesPerYear, double curveYearFraction) { return(SwapAnalytics.Delta1ForAnAmount(amount, paymentDiscountFactor, periodAsTimesPerYear, curveYearFraction)); }
/// <summary> /// Evaluates the delta wrt the discount rate R. /// </summary> /// <param name="notional">The notional for that period.</param> /// <param name="yearFraction">the day count fraction for that coupon.</param> /// <param name="rate">The rate for that period.</param> /// <param name="paymentDiscountFactor">The payment discount factor.</param> /// <param name="periodAsTimesPerYear">the compounding year fraction.</param> /// <param name="curveYearFraction">The time to payment year fraction.</param> /// <returns></returns> public double Delta1ForNotional(double notional, double yearFraction, double rate, double paymentDiscountFactor, double periodAsTimesPerYear, double curveYearFraction) { return(SwapAnalytics.Delta1ForNotional(notional, yearFraction, rate, paymentDiscountFactor, periodAsTimesPerYear, curveYearFraction)); }