コード例 #1
0
 @Test
 public void methodVsCalculator() {
   double yield1 = METHOD_SECURITY.yieldFromCurves(BILL_IAM_SEC, CURVE_BUNDLE);
   double yield2 = BILL_IAM_SEC.accept(YFCC, CURVE_BUNDLE);
   assertEquals(
       "Bill Security: discounting method - yield from curves", yield1, yield2, TOLERANCE_YIELD);
   yield1 = METHOD_SECURITY.yieldFromPrice(BILL_IAM_SEC, PRICE);
   yield2 = BILL_IAM_SEC.accept(YFPC, PRICE);
   assertEquals(
       "Bill Security: discounting method - yield from price", yield1, yield2, TOLERANCE_YIELD);
 }
コード例 #2
0
 @Test
 public void yieldFromPrice() {
   final double yieldComputedIAM = METHOD_SECURITY.yieldFromPrice(BILL_IAM_SEC, PRICE);
   final double yieldExpectedIAM = (1.0 / PRICE - 1.0) / BILL_IAM_SEC.getAccrualFactor();
   assertEquals(
       "Bill Security: discounting method - yield",
       yieldExpectedIAM,
       yieldComputedIAM,
       TOLERANCE_YIELD);
   final double yieldComputedDSC = METHOD_SECURITY.yieldFromPrice(BILL_DSC_SEC, PRICE);
   final double yieldExpectedDSC = (1.0 - PRICE) / BILL_DSC_SEC.getAccrualFactor();
   assertEquals(
       "Bill Security: discounting method - yield",
       yieldExpectedDSC,
       yieldComputedDSC,
       TOLERANCE_YIELD);
 }
コード例 #3
0
 @Test
 /** Tests the present value: Method vs Calculator */
 public void presentValueMethodVsCalculator() {
   final CurrencyAmount pvMethod = METHOD_SECURITY.presentValue(BILL_IAM_SEC, CURVE_BUNDLE);
   final double pvCalculator = BILL_IAM_SEC.accept(PVC, CURVE_BUNDLE);
   assertEquals(
       "Bill Security: discounting method - present value",
       pvMethod.getAmount(),
       pvCalculator,
       TOLERANCE_PV);
 }
コード例 #4
0
 @Test
 public void presentValueCurveSensitivity() {
   final InterestRateCurveSensitivity pvcsComputed =
       METHOD_SECURITY.presentValueCurveSensitivity(BILL_IAM_SEC, CURVE_BUNDLE);
   assertEquals(
       "Bill Security: present value curve sensitivity",
       1,
       pvcsComputed.getSensitivities().size());
   assertEquals(
       "Bill Security: present value curve sensitivity",
       1,
       pvcsComputed.getSensitivities().get(NAME_CURVES[1]).size());
   final double deltaTolerancePrice = 1.0E+2;
   // Testing note: Sensitivity is for a movement of 1. 1E+2 = 0.01 unit for a 1 bp move.
   final double deltaShift = 1.0E-6;
   // Credit curve sensitivity
   final String bumpedCurveName = "Bumped Curve";
   final BillSecurity billBumped =
       BILL_IAM_SEC_DEFINITION.toDerivative(REFERENCE_DATE, NAME_CURVES[0], bumpedCurveName);
   final double[] nodeTimes = new double[] {billBumped.getEndTime()};
   final double[] sensi =
       SensitivityFiniteDifference.curveSensitivity(
           billBumped,
           CURVE_BUNDLE,
           NAME_CURVES[1],
           bumpedCurveName,
           nodeTimes,
           deltaShift,
           METHOD_SECURITY);
   final List<DoublesPair> sensiPv = pvcsComputed.getSensitivities().get(NAME_CURVES[1]);
   for (int loopnode = 0; loopnode < sensi.length; loopnode++) {
     final DoublesPair pairPv = sensiPv.get(loopnode);
     assertEquals(
         "Bill Security: curve sensitivity - Node " + loopnode,
         nodeTimes[loopnode],
         pairPv.getFirst(),
         1E-8);
     AssertJUnit.assertEquals(
         "Bill Security: curve sensitivity", pairPv.second, sensi[loopnode], deltaTolerancePrice);
   }
 }
コード例 #5
0
 @Test
 public void presentValueCurveSensitivityMethodVsCalculator() {
   final InterestRateCurveSensitivity pvcsMethod =
       METHOD_SECURITY.presentValueCurveSensitivity(BILL_IAM_SEC, CURVE_BUNDLE);
   final InterestRateCurveSensitivity pvcsCalculator =
       new InterestRateCurveSensitivity(BILL_IAM_SEC.accept(PVCSC, CURVE_BUNDLE));
   AssertSensivityObjects.assertEquals(
       "Bill Security: discounting method - curve sensitivity",
       pvcsMethod,
       pvcsCalculator,
       TOLERANCE_PV);
 }
コード例 #6
0
 @Test
 /** Tests the present value against explicit computation. */
 public void presentValue() {
   final CurrencyAmount pvComputed = METHOD_SECURITY.presentValue(BILL_IAM_SEC, CURVE_BUNDLE);
   final double pvExpected =
       NOTIONAL
           * CURVE_BUNDLE.getCurve(NAME_CURVES[1]).getDiscountFactor(BILL_IAM_SEC.getEndTime());
   assertEquals(
       "Bill Security: discounting method - present value",
       pvExpected,
       pvComputed.getAmount(),
       TOLERANCE_PV);
 }
コード例 #7
0
 @Test
 public void priceFromCurves() {
   final double priceComputed = METHOD_SECURITY.priceFromCurves(BILL_IAM_SEC, CURVE_BUNDLE);
   final CurrencyAmount pvComputed = METHOD_SECURITY.presentValue(BILL_IAM_SEC, CURVE_BUNDLE);
   final double priceExpected =
       pvComputed.getAmount()
           / (NOTIONAL
               * CURVE_BUNDLE
                   .getCurve(NAME_CURVES[0])
                   .getDiscountFactor(BILL_IAM_SEC.getSettlementTime()));
   assertEquals(
       "Bill Security: discounting method - price", priceExpected, priceComputed, TOLERANCE_PRICE);
 }
コード例 #8
0
 @Test
 public void priceFromYield() {
   final double[] yields = new double[] {0.0010, 0.0, -0.0010};
   for (final double yield2 : yields) {
     final double priceComputed = METHOD_SECURITY.priceFromYield(BILL_IAM_SEC, yield2);
     final double priceExpected = 1.0 / (1 + BILL_IAM_SEC.getAccrualFactor() * yield2);
     assertEquals(
         "Bill Security: discounting method - price",
         priceExpected,
         priceComputed,
         TOLERANCE_PRICE);
   }
 }
コード例 #9
0
 @Test
 public void presentValueFromYield() {
   final CurrencyAmount pvComputed =
       METHOD_SECURITY.presentValueFromYield(BILL_IAM_SEC, YIELD, CURVE_BUNDLE);
   final double price = METHOD_SECURITY.priceFromYield(BILL_IAM_SEC, YIELD);
   final double pvExpected =
       NOTIONAL
           * price
           * CURVE_BUNDLE
               .getCurve(NAME_CURVES[0])
               .getDiscountFactor(BILL_IAM_SEC.getSettlementTime());
   assertEquals(
       "Bill Security: discounting method - present value",
       pvExpected,
       pvComputed.getAmount(),
       TOLERANCE_PV);
 }