Skip to content

Commit

Permalink
Add completed flag in explain (#1277)
Browse files Browse the repository at this point in the history
Fixes #1270
  • Loading branch information
jodastephen authored and cjkent committed Aug 16, 2016
1 parent a8bf6a9 commit 10a115e
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ public final class ExplainKey<T>
* The forecast value.
*/
public static final ExplainKey<CurrencyAmount> FORECAST_VALUE = of("ForecastValue");
/**
* The flag to indicate that the period has completed.
* For example, a swap payment period that has already paid would have this set to true.
* This will generally never be set to false.
*/
public static final ExplainKey<Boolean> COMPLETED = of("Completed");

/**
* The currency of the payment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public ExplainMap explainPresentValue(Payment payment, BaseProvider provider) {
builder.put(ExplainKey.PAYMENT_DATE, paymentDate);
builder.put(ExplainKey.PAYMENT_CURRENCY, currency);
if (paymentDate.isBefore(provider.getValuationDate())) {
builder.put(ExplainKey.COMPLETED, Boolean.TRUE);
builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.zero(currency));
builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.zero(currency));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public void explainPresentValue(
builder.put(ExplainKey.UNADJUSTED_END_DATE, period.getUnadjustedEndDate());
builder.put(ExplainKey.DAYS, (int) DAYS.between(period.getUnadjustedStartDate(), period.getUnadjustedEndDate()));
if (paymentDate.isBefore(ratesProvider.getValuationDate())) {
builder.put(ExplainKey.COMPLETED, Boolean.TRUE);
builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.zero(currency));
builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.zero(currency));
} else {
Expand Down Expand Up @@ -283,6 +284,7 @@ public void explainPresentValueWithZSpread(
builder.put(ExplainKey.UNADJUSTED_END_DATE, period.getUnadjustedEndDate());
builder.put(ExplainKey.DAYS, (int) DAYS.between(period.getUnadjustedStartDate(), period.getUnadjustedEndDate()));
if (paymentDate.isBefore(ratesProvider.getValuationDate())) {
builder.put(ExplainKey.COMPLETED, Boolean.TRUE);
builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.zero(currency));
builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.zero(currency));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public void explainPresentValue(
LocalDate paymentDate = period.getPaymentDate();
explainBasics(period, builder, currency, paymentDate);
if (paymentDate.isBefore(discountFactors.getValuationDate())) {
builder.put(ExplainKey.COMPLETED, Boolean.TRUE);
builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.zero(currency));
builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.zero(currency));
} else {
Expand Down Expand Up @@ -248,6 +249,7 @@ public void explainPresentValueWithSpread(
LocalDate paymentDate = period.getPaymentDate();
explainBasics(period, builder, currency, paymentDate);
if (paymentDate.isBefore(discountFactors.getValuationDate())) {
builder.put(ExplainKey.COMPLETED, Boolean.TRUE);
builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.zero(currency));
builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.zero(currency));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public ExplainMap explainPresentValue(ResolvedFra fra, RatesProvider provider) {
builder.put(ExplainKey.NOTIONAL, CurrencyAmount.of(currency, fra.getNotional()));
builder.put(ExplainKey.TRADE_NOTIONAL, CurrencyAmount.of(currency, fra.getNotional()));
if (fra.getPaymentDate().isBefore(provider.getValuationDate())) {
builder.put(ExplainKey.COMPLETED, Boolean.TRUE);
builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.zero(currency));
builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.zero(currency));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void explainPresentValue(FxResetNotionalExchange event, RatesProvider pro
builder.put(ExplainKey.PAYMENT_CURRENCY, currency);
builder.put(ExplainKey.TRADE_NOTIONAL, event.getNotionalAmount());
if (paymentDate.isBefore(provider.getValuationDate())) {
builder.put(ExplainKey.COMPLETED, Boolean.TRUE);
builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.zero(currency));
builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.zero(currency));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public void explainPresentValue(KnownAmountSwapPaymentPeriod period, RatesProvid
builder.put(ExplainKey.UNADJUSTED_END_DATE, period.getUnadjustedEndDate());
builder.put(ExplainKey.DAYS, (int) DAYS.between(period.getStartDate(), period.getEndDate()));
if (paymentDate.isBefore(provider.getValuationDate())) {
builder.put(ExplainKey.COMPLETED, Boolean.TRUE);
builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.zero(currency));
builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.zero(currency));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void explainPresentValue(NotionalExchange event, RatesProvider provider,
builder.put(ExplainKey.PAYMENT_CURRENCY, currency);
builder.put(ExplainKey.TRADE_NOTIONAL, event.getPaymentAmount());
if (paymentDate.isBefore(provider.getValuationDate())) {
builder.put(ExplainKey.COMPLETED, Boolean.TRUE);
builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.zero(currency));
builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.zero(currency));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ public void explainPresentValue(RatePaymentPeriod paymentPeriod, RatesProvider p
builder.put(ExplainKey.NOTIONAL, CurrencyAmount.of(currency, notional));
builder.put(ExplainKey.TRADE_NOTIONAL, paymentPeriod.getNotionalAmount());
if (paymentDate.isBefore(provider.getValuationDate())) {
builder.put(ExplainKey.COMPLETED, Boolean.TRUE);
builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.zero(currency));
builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.zero(currency));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ public void test_explainPresentValue_single_paymentDateInPast() {
assertEquals(explain.get(ExplainKey.NOTIONAL).get().getAmount(), NOTIONAL_100, TOLERANCE_PV);
assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().getCurrency(), currency);
assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().getAmount(), NOTIONAL_100, TOLERANCE_PV);
assertEquals(explain.get(ExplainKey.COMPLETED).get(), Boolean.TRUE);
assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getCurrency(), currency);
assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getAmount(), 0d, TOLERANCE_PV);
assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().getCurrency(), currency);
Expand Down

0 comments on commit 10a115e

Please sign in to comment.