CurveBundleResource { @GET @Produces("application/json") public String buildCurveBundle(@PathParam("bundle") String bundle, @PathParam("spec") String spec) { MarketDataSpecification marketDataSpec = MarketDataSpecificationParser.parse(spec); ZonedDateTime valuationTime = ZonedDateTime.now(); MarketDataEnvironment suppliedData = MarketDataEnvironmentBuilder.empty(); MulticurveId multicurveId = MulticurveId.of(bundle); SingleValueRequirement requirement = SingleValueRequirement.of(multicurveId); Set<MarketDataRequirement> requirements = ImmutableSet.<MarketDataRequirement>of(requirement); SingleScenarioDefinition perturbations = SingleScenarioDefinition.base(); MarketDataEnvironment marketData = _environmentFactory.build(suppliedData, requirements, perturbations, marketDataSpec, valuationTime); MulticurveBundle curveBundle = (MulticurveBundle) marketData.getData().get(requirement); MulticurveProviderDiscount multicurveProvider = curveBundle.getMulticurveProvider(); Map<Currency, YieldAndDiscountCurve> discountingCurves = multicurveProvider.getDiscountingCurves(); Map<IndexON, YieldAndDiscountCurve> forwardONCurves = multicurveProvider.getForwardONCurves(); Map<IborIndex, YieldAndDiscountCurve> forwardIborCurves = multicurveProvider.getForwardIborCurves(); Map<String, Map<String, Object>> discounting = new HashMap<>(); Map<String, Map<String, Object>> forwardON = new HashMap<>(); Map<String, Map<String, Object>> forwardIbor = new HashMap<>(); for (Map.Entry<Currency, YieldAndDiscountCurve> entry : discountingCurves.entrySet()) { discounting.put(entry.getKey().getCode(), getCurveData(entry.getValue())); } for (Map.Entry<IndexON, YieldAndDiscountCurve> entry : forwardONCurves.entrySet()) { forwardON.put(entry.getKey().toString(), getCurveData(entry.getValue())); } for (Map.Entry<IborIndex, YieldAndDiscountCurve> entry : forwardIborCurves.entrySet()) { forwardIbor.put(entry.getKey().toString(), getCurveData(entry.getValue())); } Map<String, Map> curves = new HashMap<>(); curves.put("discounting", discounting); curves.put("forwardOn", forwardON); curves.put("forwardIbor", forwardIbor); Gson gson = new Gson(); return gson.toJson(curves); } CurveBundleResource(MarketDataEnvironmentFactory environmentFactory); @GET @Produces("application/json") String buildCurveBundle(@PathParam("bundle") String bundle,
                                 @PathParam("spec") String spec);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testError() { _resource.buildCurveBundle("bad-bundle-name", "live:bloomberg"); }
@Test public void test() { String calculate = _resource.buildCurveBundle("bundle-name", "live:bloomberg"); JsonParser parser = new JsonParser(); JsonObject o = (JsonObject)parser.parse(calculate); JsonElement discounting = o.get("discounting"); JsonElement usd = discounting.getAsJsonObject().get("USD"); assertThat(usd.getAsJsonObject().get("name").getAsString(), is("A")); testCurveX(usd.getAsJsonObject().get("x").getAsJsonArray()); testCurveY(usd.getAsJsonObject().get("y").getAsJsonArray()); JsonElement eur = discounting.getAsJsonObject().get("EUR"); assertThat(eur.getAsJsonObject().get("name").getAsString(), is("B")); testCurveX(eur.getAsJsonObject().get("x").getAsJsonArray()); testCurveY(eur.getAsJsonObject().get("y").getAsJsonArray()); JsonElement forwardIbor = o.get("forwardIbor"); JsonElement c = forwardIbor.getAsJsonObject().get("C-Index"); assertThat(c.getAsJsonObject().get("name").getAsString(), is("C")); testCurveX(c.getAsJsonObject().get("x").getAsJsonArray()); testCurveY(c.getAsJsonObject().get("y").getAsJsonArray()); JsonElement d = forwardIbor.getAsJsonObject().get("D-Index"); assertThat(d.getAsJsonObject().get("name").getAsString(), is("D")); testCurveX(d.getAsJsonObject().get("x").getAsJsonArray()); testCurveY(d.getAsJsonObject().get("y").getAsJsonArray()); JsonElement forwardOn = o.get("forwardOn"); JsonElement name1 = forwardOn.getAsJsonObject().get("NAME1-USD-Actual/360"); assertThat(name1.getAsJsonObject().get("name").getAsString(), is("E")); testCurveX(name1.getAsJsonObject().get("x").getAsJsonArray()); testCurveY(name1.getAsJsonObject().get("y").getAsJsonArray()); JsonElement name2 = forwardOn.getAsJsonObject().get("NAME2-EUR-Actual/360"); assertThat(name2.getAsJsonObject().get("name").getAsString(), is("F")); testCurveX(name2.getAsJsonObject().get("x").getAsJsonArray()); testCurveY(name2.getAsJsonObject().get("y").getAsJsonArray()); }