@Test public void priceBeforeFixing() { double interest = 0.0; final YieldAndDiscountCurve oisCurve = CURVES.getCurve(CURVE_NAMES[0]); final double[] ratePeriod = new double[FUTURE_SECURITY_DEFINITION.getFixingPeriodAccrualFactor().length]; for (int loopfix = 0; loopfix < FUTURE_SECURITY_DEFINITION.getFixingPeriodAccrualFactor().length; loopfix++) { ratePeriod[loopfix] = (oisCurve.getDiscountFactor(FUTURE_SECURITY.getFixingPeriodTime()[loopfix]) / oisCurve.getDiscountFactor( FUTURE_SECURITY.getFixingPeriodTime()[loopfix + 1]) - 1.0) / FUTURE_SECURITY_DEFINITION.getFixingPeriodAccrualFactor()[loopfix]; interest += (oisCurve.getDiscountFactor(FUTURE_SECURITY.getFixingPeriodTime()[loopfix]) / oisCurve.getDiscountFactor(FUTURE_SECURITY.getFixingPeriodTime()[loopfix + 1]) - 1.0); } final double rate = interest / FUTURE_SECURITY_DEFINITION.getFixingTotalAccrualFactor(); final double priceExpected = 1.0 - rate; final double priceComputed = METHOD_SECURITY.price(FUTURE_SECURITY, CURVES); assertEquals( "Federal Funds Future Security: price", priceExpected, priceComputed, TOLERANCE_PRICE); }
@Test public void priceAfterFixing() { final ZonedDateTime referenceDate = DateUtils.getUTCDate(2012, 3, 7); final ZonedDateTime[] dateFixing = new ZonedDateTime[] { DateUtils.getUTCDate(2012, 3, 1), DateUtils.getUTCDate(2012, 3, 2), DateUtils.getUTCDate(2012, 3, 5), DateUtils.getUTCDate(2012, 3, 6), DateUtils.getUTCDate(2012, 3, 7) }; final double[] rateFixing = new double[] {0.0010, 0.0011, 0.0012, 0.0013, 0.0014}; final DoubleTimeSeries<ZonedDateTime> fixingTS = ImmutableZonedDateTimeDoubleTimeSeries.ofUTC(dateFixing, rateFixing); final FederalFundsFutureSecurity futureSecurity = FUTURE_SECURITY_DEFINITION.toDerivative(referenceDate, fixingTS, CURVE_NAMES); double interest = futureSecurity.getAccruedInterest(); final YieldAndDiscountCurve oisCurve = CURVES.getCurve(CURVE_NAMES[0]); final double[] ratePeriod = new double[futureSecurity.getFixingPeriodAccrualFactor().length]; for (int loopfix = 0; loopfix < futureSecurity.getFixingPeriodAccrualFactor().length; loopfix++) { ratePeriod[loopfix] = (oisCurve.getDiscountFactor(futureSecurity.getFixingPeriodTime()[loopfix]) / oisCurve.getDiscountFactor( futureSecurity.getFixingPeriodTime()[loopfix + 1]) - 1.0) / futureSecurity.getFixingPeriodAccrualFactor()[loopfix]; interest += (oisCurve.getDiscountFactor(futureSecurity.getFixingPeriodTime()[loopfix]) / oisCurve.getDiscountFactor(futureSecurity.getFixingPeriodTime()[loopfix + 1]) - 1.0); } final double rate = interest / FUTURE_SECURITY_DEFINITION.getFixingTotalAccrualFactor(); final double priceExpected = 1.0 - rate; final double priceComputed = METHOD_SECURITY.price(futureSecurity, CURVES); assertEquals( "Federal Funds Future Security: price", priceExpected, priceComputed, TOLERANCE_PRICE); }
@Override public MulticurveSensitivity visitFederalFundsFutureSecurity( final FederalFundsFutureSecurity futures, final ParameterProviderInterface multicurve) { ArgChecker.notNull(futures, "Futures"); ArgChecker.notNull(multicurve, "Multi-curves provider"); final IndexON index = futures.getIndex(); final int nbFixing = futures.getFixingPeriodAccrualFactor().length; final double[] rates = new double[nbFixing]; for (int loopfix = 0; loopfix < nbFixing; loopfix++) { rates[loopfix] = multicurve .getMulticurveProvider() .getSimplyCompoundForwardRate( index, futures.getFixingPeriodTime()[loopfix], futures.getFixingPeriodTime()[loopfix + 1], futures.getFixingPeriodAccrualFactor()[loopfix]); } // Backward sweep final double priceBar = 1.0; final double interestBar = -1.0 / futures.getFixingTotalAccrualFactor() * priceBar; final double[] ratesBar = new double[nbFixing]; for (int loopfix = 0; loopfix < nbFixing; loopfix++) { ratesBar[loopfix] = futures.getFixingPeriodAccrualFactor()[loopfix] * interestBar; } final Map<String, List<ForwardSensitivity>> resultMap = new HashMap<>(); final List<ForwardSensitivity> listON = new ArrayList<>(); for (int loopfix = 0; loopfix < nbFixing; loopfix++) { listON.add( new SimplyCompoundedForwardSensitivity( futures.getFixingPeriodTime()[loopfix], futures.getFixingPeriodTime()[loopfix + 1], futures.getFixingPeriodAccrualFactor()[loopfix], ratesBar[loopfix])); } resultMap.put(multicurve.getMulticurveProvider().getName(index), listON); return MulticurveSensitivity.ofForward(resultMap); }