public void test_withCurrency() { PointSensitivityBuilder base = PointSensitivityBuilder.none(); assertSame(base.withCurrency(GBP), base); // no effect assertSame(base.withCurrency(USD), base); // no effect }
/** * Calculates the forecast value sensitivity of the FRA product. * <p> * The forecast value sensitivity of the product is the sensitivity of the forecast value to * the underlying curves. * * @param fra the product * @param provider the rates provider * @return the point sensitivity of the forecast value */ public PointSensitivities forecastValueSensitivity(ResolvedFra fra, RatesProvider provider) { double notional = fra.getNotional(); double derivative = derivative(fra, provider); PointSensitivityBuilder iborSens = forwardRateSensitivity(fra, provider) .multipliedBy(derivative * notional); return iborSens.withCurrency(fra.getCurrency()).build(); }
/** * Calculates the present value sensitivity of the swap product converted in a given currency. * <p> * The present value sensitivity of the product is the sensitivity of the present value to * the underlying curves. * * @param swap the product * @param currency the currency to convert to * @param provider the rates provider * @return the present value curve sensitivity of the swap product converted in the given currency */ public PointSensitivityBuilder presentValueSensitivity(ResolvedSwap swap, Currency currency, RatesProvider provider) { PointSensitivityBuilder builder = PointSensitivityBuilder.none(); for (ResolvedSwapLeg leg : swap.getLegs()) { PointSensitivityBuilder ls = legPricer.presentValueSensitivity(leg, provider); PointSensitivityBuilder lsConverted = ls.withCurrency(currency).multipliedBy(provider.fxRate(leg.getCurrency(), currency)); builder = builder.combinedWith(lsConverted); } return builder; }
otherLegsConvertedPvDr = otherLegsConvertedPvDr.withCurrency(ccyFixedLeg); PointSensitivityBuilder dfDr = provider.discountFactors(ccyFixedLeg).zeroRatePointSensitivity(fixedLeg.getPaymentPeriods().get(0).getPaymentDate()); return dfDr.multipliedBy(dfBar).combinedWith(otherLegsConvertedPvDr.multipliedBy(otherLegsConvertedPvBar)); otherLegsConvertedPvDr = otherLegsConvertedPvDr.withCurrency(ccyFixedLeg); return pvbpFixedLegDr.multipliedBy(pvbpFixedLegBar) .combinedWith(fixedLegEventsPvDr.multipliedBy(fixedLegEventsPvBar))
/** * Calculates the present value sensitivity of the FRA product. * <p> * The present value sensitivity of the product is the sensitivity of the present value to * the underlying curves. * * @param fra the product * @param provider the rates provider * @return the point sensitivity of the present value */ public PointSensitivities presentValueSensitivity(ResolvedFra fra, RatesProvider provider) { DiscountFactors discountFactors = provider.discountFactors(fra.getCurrency()); double df = discountFactors.discountFactor(fra.getPaymentDate()); double notional = fra.getNotional(); double unitAmount = unitAmount(fra, provider); double derivative = derivative(fra, provider); PointSensitivityBuilder iborSens = forwardRateSensitivity(fra, provider) .multipliedBy(derivative * df * notional); PointSensitivityBuilder discSens = discountFactors.zeroRatePointSensitivity(fra.getPaymentDate()) .multipliedBy(unitAmount * notional); return iborSens.withCurrency(fra.getCurrency()).combinedWith(discSens).build(); }
/** * Calculates the present value curve sensitivity of the NDF product. * <p> * The present value sensitivity of the product is the sensitivity of the present value to * the underlying curves. * * @param ndf the product * @param provider the rates provider * @return the point sensitivity of the present value */ public PointSensitivities presentValueSensitivity(ResolvedFxNdf ndf, RatesProvider provider) { if (provider.getValuationDate().isAfter(ndf.getPaymentDate())) { return PointSensitivities.empty(); } Currency ccySettle = ndf.getSettlementCurrency(); Currency ccyOther = ndf.getNonDeliverableCurrency(); double notionalSettle = ndf.getSettlementNotional(); double agreedRate = ndf.getAgreedFxRate().fxRate(ccySettle, ccyOther); double forwardRate = provider.fxIndexRates(ndf.getIndex()).rate(ndf.getObservation(), ccySettle); double dfSettle = provider.discountFactor(ccySettle, ndf.getPaymentDate()); double ratio = agreedRate / forwardRate; double dscBar = (1d - ratio) * notionalSettle; PointSensitivityBuilder sensiDsc = provider.discountFactors(ccySettle).zeroRatePointSensitivity(ndf.getPaymentDate()).multipliedBy(dscBar); double forwardRateBar = dfSettle * notionalSettle * ratio / forwardRate; PointSensitivityBuilder sensiFx = provider.fxIndexRates(ndf.getIndex()) .ratePointSensitivity(ndf.getObservation(), ccySettle).withCurrency(ccySettle).multipliedBy(forwardRateBar); return sensiDsc.combinedWith(sensiFx).build(); }