static {
   CurveInterpolator interp = CurveInterpolators.DOUBLE_QUADRATIC;
   DoubleArray time_gbp = DoubleArray.of(0.0, 0.1, 0.25, 0.5, 0.75, 1.0, 2.0);
   DoubleArray rate_gbp = DoubleArray.of(0.0160, 0.0165, 0.0155, 0.0155, 0.0155, 0.0150, 0.014);
   InterpolatedNodalCurve dscCurve =
       InterpolatedNodalCurve.of(
           Curves.zeroRates("GBP-Discount", DAY_COUNT), time_gbp, rate_gbp, interp);
   DoubleArray time_index = DoubleArray.of(0.0, 0.25, 0.5, 1.0);
   DoubleArray rate_index = DoubleArray.of(0.0180, 0.0180, 0.0175, 0.0165);
   InterpolatedNodalCurve indexCurve =
       InterpolatedNodalCurve.of(
           Curves.zeroRates("GBP-GBPIBOR3M", DAY_COUNT), time_index, rate_index, interp);
   IMM_PROV =
       ImmutableRatesProvider.builder()
           .valuationDate(VAL_DATE)
           .discountCurves(ImmutableMap.of(GBP, dscCurve))
           .indexCurves(ImmutableMap.of(GBP_LIBOR_3M, indexCurve))
           .build();
 }
示例#2
0
  /**
   * Creates a rates provider from a set of market data containing a single discounting curve, and
   * forward curves and fixing series for a given set of indices. All curves are overridden by a
   * given replacement.
   *
   * @param marketData the market data
   * @param currency the currency of the discounting curve
   * @param indices the indices
   * @param curveOverride the curve override
   * @return the rates provider
   */
  public static RatesProvider toSingleCurveRatesProvider(
      SingleCalculationMarketData marketData,
      Currency currency,
      Set<? extends Index> indices,
      NodalCurve curveOverride) {

    // TODO - we should be able to replace curves more easily than having to pick out all the
    // market data into a new rates provider.

    return ImmutableRatesProvider.builder()
        .valuationDate(marketData.getValuationDate())
        .discountCurves(ImmutableMap.of(currency, curveOverride))
        .indexCurves(
            indices.stream().collect(toImmutableMap(Function.identity(), k -> curveOverride)))
        .timeSeries(
            indices
                .stream()
                .collect(
                    toImmutableMap(
                        Function.identity(), k -> marketData.getTimeSeries(IndexRateKey.of(k)))))
        .build();
  }
  /** Test parameter sensitivity with finite difference sensitivity calculator. No cutoff period. */
  public void rateChfNoCutOffParameterSensitivity() {
    LocalDate[] valuationDate = {date(2015, 1, 1), date(2015, 1, 8)};
    double[] time = new double[] {0.0, 0.5, 1.0, 2.0, 5.0, 10.0};
    double[] rate = new double[] {0.0100, 0.0110, 0.0115, 0.0130, 0.0135, 0.0135};

    for (int loopvaldate = 0; loopvaldate < 2; loopvaldate++) {
      Curve onCurve =
          InterpolatedNodalCurve.of(Curves.zeroRates("ON", ACT_ACT_ISDA), time, rate, INTERPOLATOR);
      ImmutableRatesProvider prov =
          ImmutableRatesProvider.builder()
              .valuationDate(valuationDate[loopvaldate])
              .indexCurves(ImmutableMap.of(CHF_TOIS, onCurve))
              .timeSeries(ImmutableMap.of(CHF_TOIS, TIME_SERIES_BUILDER.build()))
              .build();
      OvernightAveragedRateObservation ro =
          OvernightAveragedRateObservation.of(CHF_TOIS, FIXING_START_DATE, FIXING_END_DATE, 0);
      ForwardOvernightAveragedRateObservationFn obsFn =
          ForwardOvernightAveragedRateObservationFn.DEFAULT;

      PointSensitivityBuilder sensitivityBuilderComputed =
          obsFn.rateSensitivity(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, prov);
      CurveCurrencyParameterSensitivities parameterSensitivityComputed =
          prov.curveParameterSensitivity(sensitivityBuilderComputed.build());

      CurveCurrencyParameterSensitivities parameterSensitivityExpected =
          CAL_FD.sensitivity(
              prov,
              (p) ->
                  CurrencyAmount.of(
                      CHF_TOIS.getCurrency(),
                      obsFn.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, (p))));
      assertTrue(
          parameterSensitivityComputed.equalWithTolerance(
              parameterSensitivityExpected, EPS_FD * 10.0));
    }
  }