public void test_of_index() { IborFixingDepositTemplate test = IborFixingDepositTemplate.of(EUR_LIBOR_3M); assertEquals(test.getConvention(), CONVENTION); assertEquals(test.getDepositPeriod(), EUR_LIBOR_3M.getTenor().getPeriod()); }
@Override public IborFixingDepositTrade trade(double quantity, MarketData marketData, ReferenceData refData) { double fixedRate = marketData.getValue(rateId) + additionalSpread; BuySell buySell = quantity > 0 ? BuySell.BUY : BuySell.SELL; return template.createTrade(marketData.getValuationDate(), buySell, Math.abs(quantity), fixedRate, refData); }
@Override public IborFixingDepositTemplate build() { preBuild(this); return new IborFixingDepositTemplate( depositPeriod, convention); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(IborFixingDepositTemplate beanToCopy) { this.depositPeriod = beanToCopy.getDepositPeriod(); this.convention = beanToCopy.getConvention(); }
public void test_createTrade() { IborFixingDepositTemplate template = IborFixingDepositTemplate.of(EUR_LIBOR_3M); double notional = 1d; double fixedRate = 0.045; LocalDate tradeDate = LocalDate.of(2015, 1, 22); IborFixingDepositTrade trade = template.createTrade(tradeDate, BUY, notional, fixedRate, REF_DATA); ImmutableIborFixingDepositConvention conv = (ImmutableIborFixingDepositConvention) template.getConvention(); LocalDate startExpected = conv.getSpotDateOffset().adjust(tradeDate, REF_DATA); LocalDate endExpected = startExpected.plus(template.getDepositPeriod()); IborFixingDeposit productExpected = IborFixingDeposit.builder() .businessDayAdjustment(conv.getBusinessDayAdjustment()) .buySell(BUY) .startDate(startExpected) .endDate(endExpected) .fixedRate(fixedRate) .index(EUR_LIBOR_3M) .notional(notional) .build(); TradeInfo tradeInfoExpected = TradeInfo.builder() .tradeDate(tradeDate) .build(); assertEquals(trade.getInfo(), tradeInfoExpected); assertEquals(trade.getProduct(), productExpected); }
/** * Obtains a template based on the specified period and index. * <p> * The period from the start date to the end is specified. * The convention will be created based on the index. * * @param depositPeriod the period between the start date and the end date * @param index the index that defines the market convention * @return the template */ public static IborFixingDepositTemplate of(Period depositPeriod, IborIndex index) { return of(depositPeriod, IborFixingDepositConvention.of(index)); }
public void test_builder_noPeriod() { IborFixingDepositTemplate test = IborFixingDepositTemplate.builder() .convention(CONVENTION) .build(); assertEquals(test.getConvention(), CONVENTION); assertEquals(test.getDepositPeriod(), EUR_LIBOR_3M.getTenor().getPeriod()); }
@ImmutablePreBuild private static void preBuild(Builder builder) { if (builder.label == null && builder.template != null) { builder.label = Tenor.of(builder.template.getDepositPeriod()).toString(); } }
/** * Obtains a template based on the specified periods and convention. * * @param depositPeriod the period between the start date and the end date * @param convention the market convention * @return the template */ public static IborFixingDepositTemplate of(Period depositPeriod, IborFixingDepositConvention convention) { ArgChecker.notNull(depositPeriod, "depositPeriod"); ArgChecker.notNull(convention, "convention"); return IborFixingDepositTemplate.builder() .depositPeriod(depositPeriod) .convention(convention) .build(); }
/** * Obtains a template based on the specified index. * <p> * The period from the start date to the end date will be the tenor of the index. * The convention will be created based on the index. * * @param index the index that defines the market convention * @return the template */ public static IborFixingDepositTemplate of(IborIndex index) { return of(index.getTenor().getPeriod(), IborFixingDepositConvention.of(index)); }
public void test_builder() { IborFixingDepositTemplate test = IborFixingDepositTemplate.builder() .convention(CONVENTION) .depositPeriod(Period.ofMonths(1)) .build(); assertEquals(test.getConvention(), CONVENTION); assertEquals(test.getDepositPeriod(), Period.ofMonths(1)); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 14649855: // depositPeriod return ((IborFixingDepositTemplate) bean).getDepositPeriod(); case 2039569265: // convention return ((IborFixingDepositTemplate) bean).getConvention(); } return super.propertyGet(bean, propertyName, quiet); }
@Override public double initialGuess(MarketData marketData, ValueType valueType) { if (ValueType.ZERO_RATE.equals(valueType) || ValueType.FORWARD_RATE.equals(valueType)) { return marketData.getValue(rateId); } if (ValueType.DISCOUNT_FACTOR.equals(valueType)) { double approximateMaturity = template.getDepositPeriod().toTotalMonths() / 12.0d; return Math.exp(-approximateMaturity * marketData.getValue(rateId)); } return 0d; }
public void test_build_negativePeriod() { assertThrowsIllegalArg(() -> IborFixingDepositTemplate.builder() .convention(CONVENTION) .depositPeriod(Period.ofMonths(-3)) .build()); }
public void test_of_periodAndIndex() { IborFixingDepositTemplate test = IborFixingDepositTemplate.of(Period.ofMonths(1), EUR_LIBOR_3M); assertEquals(test.getConvention(), CONVENTION); assertEquals(test.getDepositPeriod(), Period.ofMonths(1)); }
public void test_trade() { IborFixingDepositCurveNode node = IborFixingDepositCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD); LocalDate valuationDate = LocalDate.of(2015, 1, 22); double rate = 0.035; MarketData marketData = ImmutableMarketData.builder(valuationDate).addValue(QUOTE_ID, rate).build(); IborFixingDepositTrade trade = node.trade(1d, marketData, REF_DATA); ImmutableIborFixingDepositConvention conv = (ImmutableIborFixingDepositConvention) TEMPLATE.getConvention(); LocalDate startDateExpected = conv.getSpotDateOffset().adjust(valuationDate, REF_DATA); LocalDate endDateExpected = startDateExpected.plus(TEMPLATE.getDepositPeriod()); IborFixingDeposit depositExpected = IborFixingDeposit.builder() .buySell(BuySell.BUY) .index(EUR_LIBOR_3M) .startDate(startDateExpected) .endDate(endDateExpected) .businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, EUR_LIBOR_3M.getFixingCalendar())) .notional(1.0d) .fixedRate(rate + SPREAD) .build(); TradeInfo tradeInfoExpected = TradeInfo.builder() .tradeDate(valuationDate) .build(); assertEquals(trade.getProduct(), depositExpected); assertEquals(trade.getInfo(), tradeInfoExpected); }
@Override public DatedParameterMetadata metadata(LocalDate valuationDate, ReferenceData refData) { LocalDate nodeDate = date(valuationDate, refData); if (date.isFixed()) { return LabelDateParameterMetadata.of(nodeDate, label); } Tenor tenor = Tenor.of(template.getDepositPeriod()); return TenorDateParameterMetadata.of(nodeDate, tenor, label); }
private LocalDate calculateEnd(LocalDate valuationDate, ReferenceData refData) { IborFixingDepositTrade trade = template.createTrade(valuationDate, BuySell.BUY, 0d, 0d, refData); ResolvedIborFixingDeposit deposit = trade.getProduct().resolve(refData); return deposit.getEndDate(); }
public void test_serialization() { IborFixingDepositTemplate test = IborFixingDepositTemplate.of(EUR_LIBOR_3M); assertSerialization(test); }