/** * Calculates the zero rate point sensitivity at the specified date. * <p> * This returns a sensitivity instance referring to the zero rate sensitivity of the * points that were queried in the market data. * The sensitivity typically has the value {@code (-discountFactor * yearFraction)}. * The sensitivity refers to the result of {@link #discountFactor(LocalDate)}. * * @param date the date to discount to * @return the point sensitivity of the zero rate * @throws RuntimeException if the result cannot be calculated */ public default ZeroRateSensitivity zeroRatePointSensitivity(LocalDate date) { double yearFraction = relativeYearFraction(date); return zeroRatePointSensitivity(yearFraction); }
/** * Gets the continuously compounded zero rate for the specified date. * <p> * The continuously compounded zero rate is coherent to {@link #discountFactor(LocalDate)} along with * year fraction which is computed internally in each implementation. * * @param date the date to discount to * @return the zero rate * @throws RuntimeException if the value cannot be obtained */ public default double zeroRate(LocalDate date) { double yearFraction = relativeYearFraction(date); return zeroRate(yearFraction); }
/** * Gets the discount factor for the specified date. * <p> * The discount factor represents the time value of money for the specified currency * when comparing the valuation date to the specified date. * <p> * If the valuation date is on or after the specified date, the discount factor is 1. * * @param date the date to discount to * @return the discount factor * @throws RuntimeException if the value cannot be obtained */ public default double discountFactor(LocalDate date) { double yearFraction = relativeYearFraction(date); return discountFactor(yearFraction); }
/** * Calculates the zero rate point sensitivity at the specified date specifying the currency of the sensitivity. * <p> * This returns a sensitivity instance referring to the zero rate sensitivity of the * points that were queried in the market data. * The sensitivity typically has the value {@code (-discountFactor * yearFraction)}. * The sensitivity refers to the result of {@link #discountFactor(LocalDate)}. * <p> * This method allows the currency of the sensitivity to differ from the currency of the market data. * * @param date the date to discount to * @param sensitivityCurrency the currency of the sensitivity * @return the point sensitivity of the zero rate * @throws RuntimeException if the result cannot be calculated */ public default ZeroRateSensitivity zeroRatePointSensitivity(LocalDate date, Currency sensitivityCurrency) { double yearFraction = relativeYearFraction(date); return zeroRatePointSensitivity(yearFraction, sensitivityCurrency); }
/** * Calculates the zero rate point sensitivity with z-spread at the specified date. * <p> * This returns a sensitivity instance referring to the zero rate sensitivity of the * points that were queried in the market data. * The sensitivity refers to the result of {@link #discountFactorWithSpread(LocalDate, double, CompoundedRateType, int)}. * <p> * The z-spread is a parallel shift applied to continuously compounded rates or periodic * compounded rates of the discounting curve. * * @param date the date to discount to * @param zSpread the z-spread * @param compoundedRateType the compounded rate type * @param periodsPerYear the number of periods per year * @return the point sensitivity of the zero rate * @throws RuntimeException if the result cannot be calculated */ public default ZeroRateSensitivity zeroRatePointSensitivityWithSpread( LocalDate date, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { double yearFraction = relativeYearFraction(date); return zeroRatePointSensitivityWithSpread(yearFraction, zSpread, compoundedRateType, periodsPerYear); }
/** * Gets the discount factor for the specified date with z-spread. * <p> * The discount factor represents the time value of money for the specified currency * when comparing the valuation date to the specified date. * <p> * The z-spread is a parallel shift applied to continuously compounded rates or periodic * compounded rates of the discounting curve. * <p> * If the valuation date is on or after the specified date, the discount factor is 1. * * @param date the date to discount to * @param zSpread the z-spread * @param compoundedRateType the compounded rate type * @param periodsPerYear the number of periods per year * @return the discount factor * @throws RuntimeException if the value cannot be obtained */ public default double discountFactorWithSpread( LocalDate date, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { double yearFraction = relativeYearFraction(date); return discountFactorWithSpread(yearFraction, zSpread, compoundedRateType, periodsPerYear); }
/** * Calculates the zero rate point sensitivity with z-spread at the specified date specifying * the currency of the sensitivity. * <p> * This returns a sensitivity instance referring to the zero rate sensitivity of the * points that were queried in the market data. * The sensitivity refers to the result of {@link #discountFactorWithSpread(LocalDate, double, CompoundedRateType, int)}. * <p> * The z-spread is a parallel shift applied to continuously compounded rates or periodic * compounded rates of the discounting curve. * <p> * This method allows the currency of the sensitivity to differ from the currency of the market data. * * @param date the date to discount to * @param sensitivityCurrency the currency of the sensitivity * @param zSpread the z-spread * @param compoundedRateType the compounded rate type * @param periodsPerYear the number of periods per year * @return the point sensitivity of the zero rate * @throws RuntimeException if the result cannot be calculated */ public default ZeroRateSensitivity zeroRatePointSensitivityWithSpread( LocalDate date, Currency sensitivityCurrency, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { double yearFraction = relativeYearFraction(date); return zeroRatePointSensitivityWithSpread(yearFraction, sensitivityCurrency, zSpread, compoundedRateType, periodsPerYear); }
public void priceFromCurves_zspread() { LocalDate settlementDate = VAL_DATE.plusDays(1); double priceComputed = PRICER.priceFromCurvesWithZSpread(BILL, PROVIDER, settlementDate, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0); double dfMaturity = DSC_FACTORS_ISSUER.discountFactor(MATURITY_DATE); double dfSettle = DSC_FACTORS_REPO.discountFactor(settlementDate); double priceExpected = dfMaturity * Math.exp(-Z_SPREAD * DSC_FACTORS_ISSUER.relativeYearFraction(MATURITY_DATE)) / dfSettle; assertEquals(priceComputed, priceExpected, TOLERANCE_PRICE); }
public void test_presentValue_zspread() { CurrencyAmount pvComputed = PRICER.presentValueWithZSpread(BILL, PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0); double pvExpected = DSC_FACTORS_ISSUER.discountFactor(MATURITY_DATE) * NOTIONAL.getAmount() * Math.exp(-Z_SPREAD * DSC_FACTORS_ISSUER.relativeYearFraction(MATURITY_DATE)); assertEquals(pvComputed.getCurrency(), EUR); assertEquals(pvComputed.getAmount(), pvExpected, TOLERANCE_PV); }
public void test_presentValueSensitivity_onPayment() { PointSensitivityBuilder pvSensi = PRICER .presentValueSensitivityRates(COUPON, RATES_PROVIDER_ON_PAY, VOLATILITIES_ON_PAY); PointSensitivityBuilder pvSensiCapletOtm = PRICER.presentValueSensitivityRates(CAPLET, RATES_PROVIDER_ON_PAY, VOLATILITIES_AFTER_FIX); PointSensitivityBuilder pvSensiCapletItm = PRICER.presentValueSensitivityRates(CAPLET_NEGATIVE, RATES_PROVIDER_ON_PAY, VOLATILITIES_ON_PAY); PointSensitivityBuilder pvSensiFloorletItm = PRICER.presentValueSensitivityRates(FLOORLET, RATES_PROVIDER_ON_PAY, VOLATILITIES_ON_PAY); PointSensitivityBuilder pvSensiFloorletOtm = PRICER.presentValueSensitivityRates(FLOORLET_NEGATIVE, RATES_PROVIDER_ON_PAY, VOLATILITIES_ON_PAY); double paymentTime = RATES_PROVIDER_ON_PAY.discountFactors(EUR).relativeYearFraction(PAYMENT); PointSensitivityBuilder expected = ZeroRateSensitivity.of(EUR, paymentTime, -0d); assertEquals(pvSensi, expected); assertEquals(pvSensiCapletOtm, expected); assertEquals(pvSensiCapletItm, expected); assertEquals(pvSensiFloorletItm, expected); assertEquals(pvSensiFloorletOtm, expected); }
double signedNotional = signedNotional(underlyingOption); double counterYearFraction = ratesProvider.discountFactors(currencyPair.getCounter()).relativeYearFraction(underlyingFx.getPaymentDate()); ZeroRateSensitivity counterSensi = ZeroRateSensitivity.of( currencyPair.getCounter(), signedNotional * (priceDerivatives.getDerivative(2) + priceDerivatives.getDerivative(3))); double baseYearFraction = ratesProvider.discountFactors(currencyPair.getBase()).relativeYearFraction(underlyingFx.getPaymentDate()); ZeroRateSensitivity baseSensi = ZeroRateSensitivity.of( currencyPair.getBase(),