/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(ResolvedTermDeposit beanToCopy) { this.currency = beanToCopy.getCurrency(); this.notional = beanToCopy.getNotional(); this.startDate = beanToCopy.getStartDate(); this.endDate = beanToCopy.getEndDate(); this.yearFraction = beanToCopy.getYearFraction(); this.rate = beanToCopy.getRate(); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 575402001: // currency return ((ResolvedTermDeposit) bean).getCurrency(); case 1585636160: // notional return ((ResolvedTermDeposit) bean).getNotional(); case -2129778896: // startDate return ((ResolvedTermDeposit) bean).getStartDate(); case -1607727319: // endDate return ((ResolvedTermDeposit) bean).getEndDate(); case -1731780257: // yearFraction return ((ResolvedTermDeposit) bean).getYearFraction(); case 3493088: // rate return ((ResolvedTermDeposit) bean).getRate(); } return super.propertyGet(bean, propertyName, quiet); }
public void test_presentValue_onStart() { SimpleRatesProvider prov = provider(START_DATE, 1.0d, DF_END); CurrencyAmount computed = PRICER.presentValue(RTERM_DEPOSIT, prov); double expected = ((1d + RATE * RTERM_DEPOSIT.getYearFraction()) * DF_END - 1.0d) * NOTIONAL; assertEquals(computed.getCurrency(), EUR); assertEquals(computed.getAmount(), expected, TOLERANCE * NOTIONAL); }
public void test_presentValue_notStarted() { SimpleRatesProvider prov = provider(VAL_DATE, DF_START, DF_END); CurrencyAmount computed = PRICER.presentValue(RTERM_DEPOSIT, prov); double expected = ((1d + RATE * RTERM_DEPOSIT.getYearFraction()) * DF_END - DF_START) * NOTIONAL; assertEquals(computed.getCurrency(), EUR); assertEquals(computed.getAmount(), expected, TOLERANCE * NOTIONAL); }
public void test_presentValue_onEnd() { SimpleRatesProvider prov = provider(END_DATE, 1.2d, 1.0d); CurrencyAmount computed = PRICER.presentValue(RTERM_DEPOSIT, prov); double expected = (1d + RATE * RTERM_DEPOSIT.getYearFraction()) * 1.0d * NOTIONAL; assertEquals(computed.getCurrency(), EUR); assertEquals(computed.getAmount(), expected, TOLERANCE * NOTIONAL); }
public void test_presentValue_started() { SimpleRatesProvider prov = provider(date(2014, 2, 22), 1.2d, DF_END); CurrencyAmount computed = PRICER.presentValue(RTERM_DEPOSIT, prov); double expected = (1d + RATE * RTERM_DEPOSIT.getYearFraction()) * DF_END * NOTIONAL; assertEquals(computed.getCurrency(), EUR); assertEquals(computed.getAmount(), expected, TOLERANCE * NOTIONAL); }
/** * Calculates the deposit fair rate given the start and end time and the accrual factor. * <p> * When the deposit has already started the number may not be meaningful as the remaining period * is not in line with the accrual factor. * * @param deposit the product * @param provider the rates provider * @return the par rate */ public double parRate(ResolvedTermDeposit deposit, RatesProvider provider) { Currency currency = deposit.getCurrency(); DiscountFactors discountFactors = provider.discountFactors(currency); double dfStart = discountFactors.discountFactor(deposit.getStartDate()); double dfEnd = discountFactors.discountFactor(deposit.getEndDate()); double accrualFactor = deposit.getYearFraction(); return (dfStart / dfEnd - 1d) / accrualFactor; }
public void test_builder() { ResolvedTermDeposit test = ResolvedTermDeposit.builder() .currency(GBP) .notional(PRINCIPAL) .startDate(START_DATE) .endDate(END_DATE) .yearFraction(YEAR_FRACTION) .rate(RATE) .build(); assertEquals(test.getCurrency(), GBP); assertEquals(test.getNotional(), PRINCIPAL); assertEquals(test.getStartDate(), START_DATE); assertEquals(test.getEndDate(), END_DATE); assertEquals(test.getYearFraction(), YEAR_FRACTION); assertEquals(test.getRate(), RATE); assertEquals(test.getInterest(), RATE * YEAR_FRACTION * PRINCIPAL, PRINCIPAL * EPS); }
public void test_resolve() { TermDeposit base = TermDeposit.builder() .buySell(SELL) .startDate(START_DATE) .endDate(END_DATE) .businessDayAdjustment(BDA_MOD_FOLLOW) .dayCount(ACT_365F) .notional(NOTIONAL) .currency(GBP) .rate(RATE) .build(); ResolvedTermDeposit test = base.resolve(REF_DATA); LocalDate expectedEndDate = BDA_MOD_FOLLOW.adjust(END_DATE, REF_DATA); double expectedYearFraction = ACT_365F.yearFraction(START_DATE, expectedEndDate); assertEquals(test.getStartDate(), START_DATE); assertEquals(test.getEndDate(), expectedEndDate); assertEquals(test.getNotional(), -NOTIONAL); assertEquals(test.getYearFraction(), expectedYearFraction, EPS); assertEquals(test.getInterest(), -RATE * expectedYearFraction * NOTIONAL, NOTIONAL * EPS); assertEquals(test.getRate(), RATE); assertEquals(test.getCurrency(), GBP); }
/** * Calculates the par spread curve sensitivity. * <p> * The calculation is based on both of initial and final payments. * Thus the number resulting may not be meaningful when deposit has already started and only the final * payment remains (no initial payment). * * @param deposit the product * @param provider the rates provider * @return the par spread curve sensitivity */ public PointSensitivities parSpreadSensitivity(ResolvedTermDeposit deposit, RatesProvider provider) { Currency currency = deposit.getCurrency(); double accrualFactorInv = 1d / deposit.getYearFraction(); double dfStart = provider.discountFactor(currency, deposit.getStartDate()); double dfEndInv = 1d / provider.discountFactor(currency, deposit.getEndDate()); DiscountFactors discountFactors = provider.discountFactors(currency); PointSensitivityBuilder sensStart = discountFactors.zeroRatePointSensitivity(deposit.getStartDate()) .multipliedBy(dfEndInv * accrualFactorInv); PointSensitivityBuilder sensEnd = discountFactors.zeroRatePointSensitivity(deposit.getEndDate()) .multipliedBy(-dfStart * dfEndInv * dfEndInv * accrualFactorInv); return sensStart.combinedWith(sensEnd).build(); }