@Override public SwapTrade trade(double quantity, MarketData marketData, ReferenceData refData) { double fixedRate = marketData.getValue(rateId) + additionalSpread; BuySell buySell = quantity > 0 ? BuySell.SELL : BuySell.BUY; return template.createTrade(marketData.getValuationDate(), buySell, Math.abs(quantity), fixedRate, refData); }
@Override public LocalDateDoubleTimeSeries getTimeSeries(ObservableId id) { return underlying.getTimeSeries(id); }
@Override public Set<ObservableId> getTimeSeriesIds() { return underlying.getTimeSeriesIds(); }
public void test_of_3arg() { Map<MarketDataId<?>, Object> dataMap = ImmutableMap.of(ID1, VAL1); Map<ObservableId, LocalDateDoubleTimeSeries> tsMap = ImmutableMap.of(ID5, TIME_SERIES); MarketData test = MarketData.of(VAL_DATE, dataMap, tsMap); assertEquals(test.containsValue(ID1), true); assertEquals(test.getValue(ID1), VAL1); assertEquals(test.findValue(ID1), Optional.of(VAL1)); assertEquals(test.containsValue(ID2), false); assertThrows(() -> test.getValue(ID2), MarketDataNotFoundException.class); assertEquals(test.findValue(ID2), Optional.empty()); assertEquals(test.getIds(), ImmutableSet.of(ID1)); assertEquals(test.getTimeSeries(ID4), LocalDateDoubleTimeSeries.empty()); assertEquals(test.getTimeSeries(ID5), TIME_SERIES); }
@Override @SuppressWarnings("unchecked") public <R> R getValue(MarketDataId<R> id) { if (this.id.equals(id)) { return (R) value; } return underlying.getValue(id); }
public void test_combinedWith_noClash() { Map<MarketDataId<?>, Object> dataMap1 = ImmutableMap.of(ID1, VAL1); MarketData test1 = MarketData.of(VAL_DATE, dataMap1); Map<MarketDataId<?>, Object> dataMap2 = ImmutableMap.of(ID2, VAL2); MarketData test2 = MarketData.of(VAL_DATE, dataMap2); MarketData test = test1.combinedWith(test2); assertEquals(test.getValue(ID1), VAL1); assertEquals(test.getValue(ID2), VAL2); assertEquals(test.getIds(), ImmutableSet.of(ID1, ID2)); }
assertEquals(test.getValuationDate(), VAL_DATE); assertEquals(test.containsValue(ID1), true); assertEquals(test.containsValue(ID2), false); assertEquals(test.getValue(ID1), VAL1); assertThrows(() -> test.getValue(ID2), MarketDataNotFoundException.class); assertEquals(test.findValue(ID1), Optional.of(VAL1)); assertEquals(test.findValue(ID2), Optional.empty());
@Override public LocalDate getValuationDate() { return underlying1.getValuationDate(); }
public void market_data() { RatesCurveGroupDefinition group = GROUPS_SYN_EUR; RatesProvider multicurveTsLarge = MULTICURVE_INPUT_EUR_TSEMPTY.toBuilder().timeSeries(TS_LARGE).build(); MarketData madTsEmpty = CALIBRATOR_SYNTHETIC.marketData(group, MULTICURVE_INPUT_EUR_TSEMPTY, REF_DATA); MarketData madTsLarge = CALIBRATOR_SYNTHETIC.marketData(group, multicurveTsLarge, REF_DATA); assertEquals(madTsEmpty.getValuationDate(), VALUATION_DATE); for (CurveDefinition entry : group.getCurveDefinitions()) { ImmutableList<CurveNode> nodes = entry.getNodes(); for (CurveNode node : nodes) { ResolvedTrade tradeTsEmpty = node.resolvedTrade(1d, madTsEmpty, REF_DATA); double mqTsEmpty = MQ_MEASURES.value(tradeTsEmpty, MULTICURVE_INPUT_EUR_TSEMPTY); assertEquals(mqTsEmpty, (Double) madTsEmpty.getValue(node.requirements().iterator().next()), TOLERANCE_MQ); ResolvedTrade tradeTsLarge = node.resolvedTrade(1d, madTsLarge, REF_DATA); double mqTsLarge = MQ_MEASURES.value(tradeTsLarge, multicurveTsLarge); assertEquals(mqTsLarge, (Double) madTsLarge.getValue(node.requirements().iterator().next()), TOLERANCE_MQ); // Market Quote for Fixed v ibor swaps should have changed with the fixing if ((tradeTsLarge instanceof ResolvedSwapTrade) && // Swap Fixed v Ibor (((ResolvedSwapTrade) tradeTsLarge)).getProduct().getLegs(SwapLegType.IBOR).size() == 1) { assertTrue(Math.abs(mqTsEmpty - mqTsLarge) > TOLERANCE_MQ); } } } assertEquals(madTsEmpty.getTimeSeriesIds(), ImmutableSet.of()); assertEquals( madTsLarge.getTimeSeriesIds(), ImmutableSet.of(IndexQuoteId.of(EUR_EURIBOR_3M), IndexQuoteId.of(EUR_EURIBOR_6M))); }
/** * Calibrates a single curve group, containing one or more curves. * <p> * The calibration is defined using {@link RatesCurveGroupDefinition}. * Observable market data, time-series and FX are also needed to complete the calibration. * The valuation date is defined by the market data. * <p> * The Jacobian matrices are computed and stored in curve metadata. * * @param curveGroupDefn the curve group definition * @param marketData the market data required to build a trade for the instrument, including time-series * @param refData the reference data, used to resolve the trades * @return the rates provider resulting from the calibration */ public ImmutableRatesProvider calibrate( RatesCurveGroupDefinition curveGroupDefn, MarketData marketData, ReferenceData refData) { Map<Index, LocalDateDoubleTimeSeries> timeSeries = marketData.getTimeSeriesIds().stream() .flatMap(filtering(IndexQuoteId.class)) .collect(toImmutableMap(id -> id.getIndex(), id -> marketData.getTimeSeries(id))); ImmutableRatesProvider knownData = ImmutableRatesProvider.builder(marketData.getValuationDate()) .fxRateProvider(MarketDataFxRateProvider.of(marketData)) .timeSeries(timeSeries) .build(); return calibrate(ImmutableList.of(curveGroupDefn), knownData, marketData, refData); }
public void empty() { MarketData test = MarketData.empty(VAL_DATE); assertEquals(test.containsValue(ID1), false); assertEquals(test.getIds(), ImmutableSet.of()); assertEquals(test.getTimeSeries(ID4), LocalDateDoubleTimeSeries.empty()); }
@Override public double initialGuess(MarketData marketData, ValueType valueType) { if (ValueType.PRICE_INDEX.equals(valueType)) { PriceIndex index = template.getConvention().getFloatingLeg().getIndex(); LocalDateDoubleTimeSeries ts = marketData.getTimeSeries(IndexQuoteId.of(index)); double latestIndex = ts.getLatestValue(); double rate = marketData.getValue(rateId); double year = template.getTenor().getPeriod().getYears(); return latestIndex * Math.pow(1.0 + rate, year); } if (ValueType.ZERO_RATE.equals(valueType)) { return marketData.getValue(rateId); } throw new IllegalArgumentException("No default initial guess when value type is not 'PriceIndex' or 'ZeroRate'."); }
/** * Tests the combinedWith method when the MarketData instances are not both ImmutableMarketData. */ public void test_combinedWith_differentTypes() { Map<MarketDataId<?>, Object> dataMap1 = ImmutableMap.of(ID1, VAL1, ID2, VAL2); MarketData test1 = MarketData.of(VAL_DATE, dataMap1); Map<MarketDataId<?>, Object> dataMap2 = ImmutableMap.of(ID1, VAL1); MarketData test2 = MarketData.of(VAL_DATE, dataMap2); ExtendedMarketData<String> test3 = ExtendedMarketData.of(ID1, VAL3, test2); MarketData test = test3.combinedWith(test1); assertEquals(test.getValue(ID1), VAL3); assertEquals(test.getValue(ID2), VAL2); assertEquals(test.getIds(), ImmutableSet.of(ID1, ID2)); }
public void test_trade_noMarketData() { OvernightIborSwapCurveNode node = OvernightIborSwapCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD); LocalDate valuationDate = LocalDate.of(2015, 1, 22); MarketData marketData = MarketData.empty(valuationDate); assertThrows(() -> node.trade(1d, marketData, REF_DATA), MarketDataNotFoundException.class); }
public void test_combinedWith_dateMismatch() { Map<MarketDataId<?>, Object> dataMap1 = ImmutableMap.of(ID1, VAL1); MarketData test1 = MarketData.of(VAL_DATE, dataMap1); Map<MarketDataId<?>, Object> dataMap2 = ImmutableMap.of(ID1, VAL3); MarketData test2 = MarketData.of(VAL_DATE.plusDays(1), dataMap2); assertThrowsIllegalArg(() -> test1.combinedWith(test2)); }
@Override @SuppressWarnings("unchecked") public <T> Set<MarketDataId<T>> findIds(MarketDataName<T> name) { return underlying.findIds(name); }
@Override public boolean containsValue(MarketDataId<?> id) { return underlying.containsValue(id); }