/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(FxSwapCurveNode beanToCopy) { this.template = beanToCopy.getTemplate(); this.fxRateId = beanToCopy.getFxRateId(); this.farForwardPointsId = beanToCopy.getFarForwardPointsId(); this.label = beanToCopy.getLabel(); this.date = beanToCopy.getDate(); this.dateOrder = beanToCopy.getDateOrder(); }
@Override public ResolvedFxSwapTrade resolvedTrade(double quantity, MarketData marketData, ReferenceData refData) { return trade(quantity, marketData, refData).resolve(refData); }
/** * Returns a copy of this node with the specified date. * * @param date the date to use * @return the node based on this node with the specified date */ public FxSwapCurveNode withDate(CurveNodeDate date) { return new FxSwapCurveNode(template, fxRateId, farForwardPointsId, label, date, dateOrder); }
@Override public LocalDate date(LocalDate valuationDate, ReferenceData refData) { return date.calculate( () -> calculateEnd(valuationDate, refData), () -> calculateLastFixingDate(valuationDate, refData)); }
public void test_builder_defaults() { FxSwapCurveNode test = FxSwapCurveNode.builder() .template(TEMPLATE) .farForwardPointsId(QUOTE_ID_PTS) .build(); assertEquals(test.getLabel(), LABEL_AUTO); assertEquals(test.getFxRateId(), FX_RATE_ID); assertEquals(test.getFarForwardPointsId(), QUOTE_ID_PTS); assertEquals(test.getTemplate(), TEMPLATE); assertEquals(test.getDate(), CurveNodeDate.END); }
public void test_of() { FxSwapCurveNode test = FxSwapCurveNode.of(TEMPLATE, QUOTE_ID_PTS); assertEquals(test.getLabel(), LABEL_AUTO); assertEquals(test.getFxRateId(), FX_RATE_ID); assertEquals(test.getFarForwardPointsId(), QUOTE_ID_PTS); assertEquals(test.getTemplate(), TEMPLATE); }
/** * Returns a curve node for an FX Swap using the specified instrument template and keys. * <p> * A suitable default label will be created. * * @param template the template used for building the instrument for the node * @param farForwardPointsId the identifier of the FX points at the far date * @return a node whose instrument is built from the template using a market rate */ public static FxSwapCurveNode of(FxSwapTemplate template, ObservableId farForwardPointsId) { return builder() .template(template) .farForwardPointsId(farForwardPointsId) .build(); }
public void test_metadata_fixed() { LocalDate nodeDate = VAL_DATE.plusMonths(1); FxSwapCurveNode node = FxSwapCurveNode.of(TEMPLATE, QUOTE_ID_PTS).withDate(CurveNodeDate.of(nodeDate)); LocalDate valuationDate = LocalDate.of(2015, 1, 22); DatedParameterMetadata metadata = node.metadata(valuationDate, REF_DATA); assertEquals(metadata.getDate(), nodeDate); assertEquals(metadata.getLabel(), node.getLabel()); }
public void test_trade() { FxSwapCurveNode node = FxSwapCurveNode.of(TEMPLATE, QUOTE_ID_PTS); FxSwapTrade trade = node.trade(1d, MARKET_DATA, REF_DATA); double rate = FX_RATE_NEAR.fxRate(EUR_USD); FxSwapTrade expected = TEMPLATE.createTrade(VAL_DATE, BuySell.BUY, 1.0, rate, FX_RATE_PTS, REF_DATA); assertEquals(trade, expected); assertEquals(node.resolvedTrade(1d, MARKET_DATA, REF_DATA), trade.resolve(REF_DATA)); }
public void coverage() { FxSwapCurveNode test = FxSwapCurveNode.of(TEMPLATE, QUOTE_ID_PTS); coverImmutableBean(test); FxSwapCurveNode test2 = FxSwapCurveNode.builder() .label(LABEL) .template(FxSwapTemplate.of(Period.ZERO, FAR_PERIOD, CONVENTION)) .fxRateId(FX_RATE_ID2) .farForwardPointsId(QUOTE_ID_PTS2) .date(CurveNodeDate.LAST_FIXING) .build(); coverBeanEquals(test, test2); }
public void test_builder() { FxSwapCurveNode test = FxSwapCurveNode.builder() .label(LABEL) .template(TEMPLATE) .fxRateId(FX_RATE_ID2) .farForwardPointsId(QUOTE_ID_PTS) .date(CurveNodeDate.LAST_FIXING) .build(); assertEquals(test.getLabel(), LABEL); assertEquals(test.getFxRateId(), FX_RATE_ID2); assertEquals(test.getFarForwardPointsId(), QUOTE_ID_PTS); assertEquals(test.getTemplate(), TEMPLATE); assertEquals(test.getDate(), CurveNodeDate.LAST_FIXING); }
public void test_of_withLabel() { FxSwapCurveNode test = FxSwapCurveNode.of(TEMPLATE, QUOTE_ID_PTS, LABEL); assertEquals(test.getLabel(), LABEL); assertEquals(test.getFxRateId(), FX_RATE_ID); assertEquals(test.getFarForwardPointsId(), QUOTE_ID_PTS); assertEquals(test.getTemplate(), TEMPLATE); }
/** * Returns a curve node for an FX Swap using the specified instrument template and keys and label. * * @param template the template used for building the instrument for the node * @param farForwardPointsId the identifier of the FX points at the far date * @param label the label to use for the node * @return a node whose instrument is built from the template using a market rate */ public static FxSwapCurveNode of(FxSwapTemplate template, ObservableId farForwardPointsId, String label) { return builder() .template(template) .farForwardPointsId(farForwardPointsId) .label(label) .build(); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -1321546630: // template return ((FxSwapCurveNode) bean).getTemplate(); case -1054985843: // fxRateId return ((FxSwapCurveNode) bean).getFxRateId(); case -566044884: // farForwardPointsId return ((FxSwapCurveNode) bean).getFarForwardPointsId(); case 102727412: // label return ((FxSwapCurveNode) bean).getLabel(); case 3076014: // date return ((FxSwapCurveNode) bean).getDate(); case -263699392: // dateOrder return ((FxSwapCurveNode) bean).getDateOrder(); } return super.propertyGet(bean, propertyName, quiet); }
private static CurveNode curveFxSwapCurveNode( String conventionStr, String timeStr, String label, QuoteId quoteId, double spread, CurveNodeDate date, CurveNodeDateOrder order) { if (!DoubleMath.fuzzyEquals(spread, 0d, 1e-10d)) { throw new IllegalArgumentException("Additional spread must be zero for FX swaps"); } Matcher matcher = SIMPLE_YMD_TIME_REGEX.matcher(timeStr.toUpperCase(Locale.ENGLISH)); if (!matcher.matches()) { throw new IllegalArgumentException(Messages.format("Invalid time format for FX swap: {}", timeStr)); } Period periodToEnd = Period.parse("P" + matcher.group(1)); FxSwapConvention convention = FxSwapConvention.of(conventionStr); FxSwapTemplate template = FxSwapTemplate.of(periodToEnd, convention); return FxSwapCurveNode.builder() .template(template) .farForwardPointsId(quoteId) .label(label) .date(date) .dateOrder(order) .build(); }
@Override public FxSwapCurveNode build() { preBuild(this); return new FxSwapCurveNode( template, fxRateId, farForwardPointsId, label, date, dateOrder); }
public void test_builder_noTemplate() { assertThrowsIllegalArg(() -> FxSwapCurveNode.builder().label(LABEL).farForwardPointsId(QUOTE_ID_PTS).build()); }