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 present value sensitivity by discounting the final cash flow (nominal + interest) * and the initial payment (initial amount). * * @param deposit the product * @param provider the rates provider * @return the point sensitivity of the present value */ public PointSensitivities presentValueSensitivity(ResolvedTermDeposit deposit, RatesProvider provider) { Currency currency = deposit.getCurrency(); // backward sweep double dfEndBar = deposit.getNotional() + deposit.getInterest(); double dfStartBar = -initialAmount(deposit, provider); // sensitivity DiscountFactors discountFactors = provider.discountFactors(currency); PointSensitivityBuilder sensStart = discountFactors.zeroRatePointSensitivity(deposit.getStartDate()) .multipliedBy(dfStartBar); PointSensitivityBuilder sensEnd = discountFactors.zeroRatePointSensitivity(deposit.getEndDate()) .multipliedBy(dfEndBar); return sensStart.combinedWith(sensEnd).build(); }
/** * Calculates the present value by discounting the final cash flow (nominal + interest) * and the initial payment (initial amount). * <p> * The present value of the product is the value on the valuation date. * * @param deposit the product * @param provider the rates provider * @return the present value of the product */ public CurrencyAmount presentValue(ResolvedTermDeposit deposit, RatesProvider provider) { Currency currency = deposit.getCurrency(); if (provider.getValuationDate().isAfter(deposit.getEndDate())) { return CurrencyAmount.of(currency, 0.0d); } DiscountFactors discountFactors = provider.discountFactors(currency); double dfStart = discountFactors.discountFactor(deposit.getStartDate()); double dfEnd = discountFactors.discountFactor(deposit.getEndDate()); double pvStart = initialAmount(deposit, provider) * dfStart; double pvEnd = (deposit.getNotional() + deposit.getInterest()) * dfEnd; double pv = pvEnd - pvStart; return CurrencyAmount.of(currency, pv); }
/** * Calculates the current cash. * * @param trade the trade * @param provider the rates provider * @return the current cash */ public CurrencyAmount currentCash(ResolvedTermDepositTrade trade, RatesProvider provider) { ResolvedTermDeposit product = trade.getProduct(); if (product.getStartDate().isEqual(provider.getValuationDate())) { return CurrencyAmount.of(product.getCurrency(), -product.getNotional()); } if (product.getEndDate().isEqual(provider.getValuationDate())) { return CurrencyAmount.of(product.getCurrency(), product.getNotional() + product.getInterest()); } return CurrencyAmount.zero(product.getCurrency()); }