/** * Returns a curve node for a Fixed-Overnight interest rate swap using the * specified instrument template and rate. * <p> * A suitable default label will be created. * * @param template the template used for building the instrument for the node * @param rateId the identifier of the market rate used when building the instrument for the node * @return a node whose instrument is built from the template using a market rate */ public static FixedOvernightSwapCurveNode of(FixedOvernightSwapTemplate template, ObservableId rateId) { return of(template, rateId, 0d); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(FixedOvernightSwapCurveNode beanToCopy) { this.template = beanToCopy.getTemplate(); this.rateId = beanToCopy.getRateId(); this.additionalSpread = beanToCopy.getAdditionalSpread(); this.label = beanToCopy.getLabel(); this.date = beanToCopy.getDate(); this.dateOrder = beanToCopy.getDateOrder(); }
@Override public ResolvedSwapTrade resolvedTrade(double quantity, MarketData marketData, ReferenceData refData) { return trade(quantity, marketData, refData).resolve(refData); }
public void test_of_noSpread() { FixedOvernightSwapCurveNode test = FixedOvernightSwapCurveNode.of(TEMPLATE, QUOTE_ID); assertEquals(test.getLabel(), LABEL_AUTO); assertEquals(test.getRateId(), QUOTE_ID); assertEquals(test.getAdditionalSpread(), 0.0d); assertEquals(test.getTemplate(), TEMPLATE); }
public void test_builder() { FixedOvernightSwapCurveNode test = FixedOvernightSwapCurveNode.builder() .label(LABEL) .template(TEMPLATE) .rateId(QUOTE_ID) .additionalSpread(SPREAD) .build(); assertEquals(test.getLabel(), LABEL); assertEquals(test.getRateId(), QUOTE_ID); assertEquals(test.getAdditionalSpread(), SPREAD); assertEquals(test.getTemplate(), TEMPLATE); assertEquals(test.getDate(), CurveNodeDate.END); }
public void test_metadata_fixed() { LocalDate nodeDate = VAL_DATE.plusMonths(1); FixedOvernightSwapCurveNode node = FixedOvernightSwapCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD, LABEL).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_requirements() { FixedOvernightSwapCurveNode test = FixedOvernightSwapCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD); Set<ObservableId> set = test.requirements(); Iterator<ObservableId> itr = set.iterator(); assertEquals(itr.next(), QUOTE_ID); assertFalse(itr.hasNext()); }
public void test_metadata_end() { FixedOvernightSwapCurveNode node = FixedOvernightSwapCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD); LocalDate valuationDate = LocalDate.of(2015, 1, 22); ParameterMetadata metadata = node.metadata(valuationDate, REF_DATA); // 2015-01-22 is Thursday, start is 2015-01-26, but 2025-01-26 is Sunday, so end is 2025-01-27 assertEquals(((TenorDateParameterMetadata) metadata).getDate(), LocalDate.of(2025, 1, 27)); assertEquals(((TenorDateParameterMetadata) metadata).getTenor(), Tenor.TENOR_10Y); }
public void test_initialGuess() { FixedOvernightSwapCurveNode node = FixedOvernightSwapCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD); double rate = 0.035; MarketData marketData = ImmutableMarketData.builder(VAL_DATE).addValue(QUOTE_ID, rate).build(); assertEquals(node.initialGuess(marketData, ValueType.ZERO_RATE), rate); assertEquals(node.initialGuess(marketData, ValueType.FORWARD_RATE), rate); assertEquals(node.initialGuess(marketData, ValueType.DISCOUNT_FACTOR), Math.exp(-rate * TENOR_10Y.getPeriod().toTotalMonths() / 12d), 1.0E-12); }
/** * Returns a curve node for a Fixed-Overnight interest rate swap using the * specified instrument template, rate key and spread. * <p> * A suitable default label will be created. * * @param template the template defining the node instrument * @param rateId the identifier of the market data providing the rate for the node instrument * @param additionalSpread the additional spread amount added to the rate * @return a node whose instrument is built from the template using a market rate */ public static FixedOvernightSwapCurveNode of( FixedOvernightSwapTemplate template, ObservableId rateId, double additionalSpread) { return builder() .template(template) .rateId(rateId) .additionalSpread(additionalSpread) .build(); }
@Override public FixedOvernightSwapCurveNode build() { preBuild(this); return new FixedOvernightSwapCurveNode( template, rateId, additionalSpread, label, date, dateOrder); }
public void test_of_withSpread() { FixedOvernightSwapCurveNode test = FixedOvernightSwapCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD); assertEquals(test.getLabel(), LABEL_AUTO); assertEquals(test.getRateId(), QUOTE_ID); assertEquals(test.getAdditionalSpread(), SPREAD); assertEquals(test.getTemplate(), TEMPLATE); }
public void test_trade() { FixedOvernightSwapCurveNode node = FixedOvernightSwapCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD); double rate = 0.125; double quantity = -1234.56; MarketData marketData = ImmutableMarketData.builder(VAL_DATE).addValue(QUOTE_ID, rate).build(); SwapTrade trade = node.trade(quantity, marketData, REF_DATA); SwapTrade expected = TEMPLATE.createTrade(VAL_DATE, BUY, -quantity, rate + SPREAD, REF_DATA); assertEquals(trade, expected); }
private static CurveNode curveFixedOvernightCurveNode( String conventionStr, String timeStr, String label, QuoteId quoteId, double spread, CurveNodeDate date, CurveNodeDateOrder order) { Matcher matcher = SIMPLE_YMD_TIME_REGEX.matcher(timeStr.toUpperCase(Locale.ENGLISH)); if (!matcher.matches()) { throw new IllegalArgumentException(Messages.format("Invalid time format for Fixed-Overnight swap: {}", timeStr)); } Period periodToEnd = Period.parse("P" + matcher.group(1)); FixedOvernightSwapConvention convention = FixedOvernightSwapConvention.of(conventionStr); FixedOvernightSwapTemplate template = FixedOvernightSwapTemplate.of(Tenor.of(periodToEnd), convention); return FixedOvernightSwapCurveNode.builder() .template(template) .rateId(quoteId) .additionalSpread(spread) .label(label) .date(date) .dateOrder(order) .build(); }
/** * 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 FixedOvernightSwapCurveNode withDate(CurveNodeDate date) { return new FixedOvernightSwapCurveNode(template, rateId, additionalSpread, label, date, dateOrder); }
public void test_of_withSpreadAndLabel() { FixedOvernightSwapCurveNode test = FixedOvernightSwapCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD, LABEL); assertEquals(test.getLabel(), LABEL); assertEquals(test.getRateId(), QUOTE_ID); assertEquals(test.getAdditionalSpread(), SPREAD); assertEquals(test.getTemplate(), TEMPLATE); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -1321546630: // template return ((FixedOvernightSwapCurveNode) bean).getTemplate(); case -938107365: // rateId return ((FixedOvernightSwapCurveNode) bean).getRateId(); case 291232890: // additionalSpread return ((FixedOvernightSwapCurveNode) bean).getAdditionalSpread(); case 102727412: // label return ((FixedOvernightSwapCurveNode) bean).getLabel(); case 3076014: // date return ((FixedOvernightSwapCurveNode) bean).getDate(); case -263699392: // dateOrder return ((FixedOvernightSwapCurveNode) bean).getDateOrder(); } return super.propertyGet(bean, propertyName, quiet); }
public void test_serialization() { FixedOvernightSwapCurveNode test = FixedOvernightSwapCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD); assertSerialization(test); }