コード例 #1
0
  // -------------------------------------------------------------------------
  // calculates calibrated bucketed PV01 for all scenarios
  ScenarioArray<CurrencyParameterSensitivities> pv01CalibratedBucketed(
      ResolvedDsfTrade trade, RatesScenarioMarketData marketData) {

    return ScenarioArray.of(
        marketData.getScenarioCount(),
        i -> pv01CalibratedBucketed(trade, marketData.scenario(i).ratesProvider()));
  }
コード例 #2
0
  // obtains the data and calculates the grid of results
  private static void calculate(CalculationRunner runner) {
    // the trade that will have measures calculated
    List<Trade> trades = ImmutableList.of(createVanillaFixedVsLibor3mSwap());

    // the columns, specifying the measures to be calculated
    List<Column> columns =
        ImmutableList.of(
            Column.of(Measures.PRESENT_VALUE), Column.of(Measures.PV01_CALIBRATED_SUM));

    // use the built-in example market data
    ExampleMarketDataBuilder marketDataBuilder = ExampleMarketData.builder();

    // the complete set of rules for calculating measures
    LocalDate valuationDate = LocalDate.of(2014, 1, 22);
    CalculationFunctions functions = StandardComponents.calculationFunctions();
    CalculationRules rules =
        CalculationRules.of(functions, Currency.USD, marketDataBuilder.ratesLookup(valuationDate));

    // mappings that select which market data to apply perturbations to
    // this applies the perturbations above to all curves
    PerturbationMapping<Curve> mapping =
        PerturbationMapping.of(
            Curve.class,
            MarketDataFilter.ofIdType(CurveId.class),
            // no shift for the base scenario, 1bp absolute shift to calibrated curves (zeros)
            CurveParallelShifts.absolute(0, ONE_BP));

    // create a scenario definition containing the single mapping above
    // this creates two scenarios - one for each perturbation in the mapping
    ScenarioDefinition scenarioDefinition = ScenarioDefinition.ofMappings(mapping);

    // build a market data snapshot for the valuation date
    MarketData marketData = marketDataBuilder.buildSnapshot(valuationDate);

    // the reference data, such as holidays and securities
    ReferenceData refData = ReferenceData.standard();

    // calculate the results
    MarketDataRequirements reqs = MarketDataRequirements.of(rules, trades, columns, refData);
    ScenarioMarketData scenarioMarketData =
        marketDataFactory()
            .createMultiScenario(
                reqs, MarketDataConfig.empty(), marketData, refData, scenarioDefinition);
    Results results =
        runner.calculateMultiScenario(rules, trades, columns, scenarioMarketData, refData);

    // TODO Replace the results processing below with a report once the reporting framework supports
    // scenarios

    // The results are lists of currency amounts containing one value for each scenario
    ScenarioArray<?> pvList = (ScenarioArray<?>) results.get(0, 0).getValue();
    ScenarioArray<?> pv01List = (ScenarioArray<?>) results.get(0, 1).getValue();

    double pvBase = ((CurrencyAmount) pvList.get(0)).getAmount();
    double pvShifted = ((CurrencyAmount) pvList.get(1)).getAmount();
    double pv01Base = ((CurrencyAmount) pv01List.get(0)).getAmount();
    NumberFormat numberFormat =
        new DecimalFormat("###,##0.00", new DecimalFormatSymbols(Locale.ENGLISH));

    System.out.println("                         PV (base) = " + numberFormat.format(pvBase));
    System.out.println("             PV (1 bp curve shift) = " + numberFormat.format(pvShifted));
    System.out.println("PV01 (algorithmic differentiation) = " + numberFormat.format(pv01Base));
    System.out.println(
        "          PV01 (finite difference) = " + numberFormat.format(pvShifted - pvBase));
  }