public void test_discountFactorTimeDerivative() { DiscountFactors test = DiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double expectedP = test.discountFactor(relativeYearFraction + EPS); double expectedM = test.discountFactor(relativeYearFraction - EPS); assertEquals(test.discountFactorTimeDerivative(relativeYearFraction), (expectedP - expectedM) / (2 * EPS), TOLERANCE_DELTA_FD); }
/** * 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); }
public void test_of_zeroRatePeriodic() { DiscountFactors test = DiscountFactors.of(GBP, DATE_VAL, CURVE_ZERO_PERIODIC); assertEquals(test instanceof ZeroRatePeriodicDiscountFactors, true); assertEquals(test.getCurrency(), GBP); assertEquals(test.getValuationDate(), DATE_VAL); }
/** * 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); }
/** * 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 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); }
@Override public CurrencyParameterSensitivities parameterSensitivity(IborRateSensitivity pointSensitivity) { LocalDate fixingStartDate = pointSensitivity.getObservation().getEffectiveDate(); LocalDate fixingEndDate = pointSensitivity.getObservation().getMaturityDate(); double accrualFactor = pointSensitivity.getObservation().getYearFraction(); double forwardBar = pointSensitivity.getSensitivity(); double dfForwardStart = discountFactors.discountFactor(fixingStartDate); double dfForwardEnd = discountFactors.discountFactor(fixingEndDate); double dfStartBar = forwardBar / (accrualFactor * dfForwardEnd); double dfEndBar = -forwardBar * dfForwardStart / (accrualFactor * dfForwardEnd * dfForwardEnd); ZeroRateSensitivity zrsStart = discountFactors.zeroRatePointSensitivity(fixingStartDate, pointSensitivity.getCurrency()); ZeroRateSensitivity zrsEnd = discountFactors.zeroRatePointSensitivity(fixingEndDate, pointSensitivity.getCurrency()); CurrencyParameterSensitivities psStart = discountFactors.parameterSensitivity(zrsStart).multipliedBy(dfStartBar); CurrencyParameterSensitivities psEnd = discountFactors.parameterSensitivity(zrsEnd).multipliedBy(dfEndBar); return psStart.combinedWith(psEnd); }
@Override public PointSensitivityBuilder presentValueSensitivity(RatePaymentPeriod period, RatesProvider provider) { Currency ccy = period.getCurrency(); DiscountFactors discountFactors = provider.discountFactors(ccy); LocalDate paymentDate = period.getPaymentDate(); double df = discountFactors.discountFactor(paymentDate); PointSensitivityBuilder forecastSensitivity = forecastValueSensitivity(period, provider); forecastSensitivity = forecastSensitivity.multipliedBy(df); double forecastValue = forecastValue(period, provider); PointSensitivityBuilder dscSensitivity = discountFactors.zeroRatePointSensitivity(paymentDate); dscSensitivity = dscSensitivity.multipliedBy(forecastValue); return forecastSensitivity.combinedWith(dscSensitivity); }
@Override public DiscountFactors toDiscountFactors() { return DiscountFactors.of(currency, valuationDate, curve); }
@Override public double rateIgnoringFixings(IborIndexObservation observation) { LocalDate fixingStartDate = observation.getEffectiveDate(); LocalDate fixingEndDate = observation.getMaturityDate(); double accrualFactor = observation.getYearFraction(); // simply compounded forward rate from discount factors double dfStart = discountFactors.discountFactor(fixingStartDate); double dfEnd = discountFactors.discountFactor(fixingEndDate); return (dfStart / dfEnd - 1) / accrualFactor; }
public void test_presentValueWithSpread() { double computed = PRICER.presentValueWithSpread( PAYMENT_PERIOD, ISSUER_CURVE, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); double expected = FIXED_RATE * NOTIONAL * YEAR_FRACTION * DSC_FACTORS.discountFactorWithSpread(END_ADJUSTED, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); assertEquals(computed, expected); }
public void test_zeroRatePointSensitivity() { IssuerCurveDiscountFactors base = IssuerCurveDiscountFactors.of(DSC_FACTORS, GROUP); IssuerCurveZeroRateSensitivity expected = IssuerCurveZeroRateSensitivity.of(DSC_FACTORS.zeroRatePointSensitivity(DATE_AFTER), GROUP); IssuerCurveZeroRateSensitivity computed = base.zeroRatePointSensitivity(DATE_AFTER); assertEquals(computed, expected); }
private DiscountFactors createDiscountFactors(DiscountFactors originalDsc, Curve bumpedCurve) { if (originalDsc instanceof ZeroRateDiscountFactors) { return ZeroRateDiscountFactors.of(originalDsc.getCurrency(), originalDsc.getValuationDate(), bumpedCurve); } else if (originalDsc instanceof SimpleDiscountFactors) { return SimpleDiscountFactors.of(originalDsc.getCurrency(), originalDsc.getValuationDate(), bumpedCurve); } throw new IllegalArgumentException("Not supported"); }
public void test_parameterSensitivity() { RepoCurveDiscountFactors base = RepoCurveDiscountFactors.of(DSC_FACTORS, GROUP); RepoCurveZeroRateSensitivity sensi = base.zeroRatePointSensitivity(DATE_AFTER, USD); CurrencyParameterSensitivities computed = base.parameterSensitivity(sensi); CurrencyParameterSensitivities expected = DSC_FACTORS.parameterSensitivity(DSC_FACTORS.zeroRatePointSensitivity(DATE_AFTER, USD)); assertEquals(computed, expected); }
@Override public Double apply(Double t) { return counterDiscountFactors.zeroRate(t); } };
/** * 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); }
DiscountFactors counterDiscountFactors = ratesProvider.discountFactors(ccyCounter); double rateBase = baseDiscountFactors.zeroRate(underlyingFx.getPaymentDate()); double rateCounter = counterDiscountFactors.zeroRate(underlyingFx.getPaymentDate()); double costOfCarry = rateCounter - rateBase; double dfBase = baseDiscountFactors.discountFactor(underlyingFx.getPaymentDate()); double dfCounter = counterDiscountFactors.discountFactor(underlyingFx.getPaymentDate()); double todayFx = ratesProvider.fxRate(currencyPair); double strike = underlyingOption.getStrike();
/** * Calculates the zero rate point sensitivity at the specified year fraction. * <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> * The year fraction must be based on {@code #relativeYearFraction(LocalDate)}. * * @param yearFraction the year fraction * @return the point sensitivity of the zero rate * @throws RuntimeException if the result cannot be calculated */ public default ZeroRateSensitivity zeroRatePointSensitivity(double yearFraction) { return zeroRatePointSensitivity(yearFraction, getCurrency()); }
/** * Calculates the zero rate point sensitivity with z-spread at the specified year fraction. * <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> * The year fraction must be based on {@code #relativeYearFraction(LocalDate)}. * * @param yearFraction the year fraction * @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( double yearFraction, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { return zeroRatePointSensitivityWithSpread(yearFraction, getCurrency(), zSpread, compoundedRateType, periodsPerYear); }
/** * Gets the valuation date. * <p> * The raw data in this provider is calibrated for this date. * * @return the valuation date */ public LocalDate getValuationDate() { return discountFactors.getValuationDate(); }