BondFuturesSecurityDiscountingMethod extends FuturesSecurityIssuerMethod { public double[] grossBasisFromPrices(final BondFuturesSecurity futures, final double[] cleanPrices, final double futurePrice) { ArgumentChecker.notNull(futures, "futures"); ArgumentChecker.notNull(cleanPrices, "cleanPrices"); final int nbBasket = futures.getDeliveryBasketAtDeliveryDate().length; ArgumentChecker.isTrue(cleanPrices.length == nbBasket, "Number of clean prices"); final double[] grossBasis = new double[nbBasket]; for (int loopbasket = 0; loopbasket < futures.getDeliveryBasketAtDeliveryDate().length; loopbasket++) { grossBasis[loopbasket] = cleanPrices[loopbasket] - futurePrice * futures.getConversionFactor()[loopbasket]; } return grossBasis; } private  BondFuturesSecurityDiscountingMethod(); static BondFuturesSecurityDiscountingMethod getInstance(); double priceFromNetBasis(final BondFuturesSecurity futures, final IssuerProviderInterface issuerMulticurves, final double netBasis); double[] grossBasisFromPrices(final BondFuturesSecurity futures, final double[] cleanPrices, final double futurePrice); double[] grossBasisFromCurves(final BondFuturesSecurity futures, final IssuerProviderInterface issuerMulticurves, final double futurePrice); double[] netBasisAllBonds(final BondFuturesSecurity futures, final IssuerProviderInterface issuerMulticurves, final double futurePrice); double netBasisCheapest(final BondFuturesSecurity futures, final IssuerProviderInterface issuerMulticurves, final double futurePrice);  }
@Test public void cheapestToDeliver() { final double yieldTest = 0.01345; final double priceTest = 1.03414063; final double mdTest = 4.271; final double grossBasisTest = 20.718; final double futurePriceTest = 1.19984375; final double[] priceCTD = new double[NB_BOND]; final double[] mdCTD = new double[NB_BOND]; final double[] yieldCTD = new double[NB_BOND]; for (int loopbasket = 0; loopbasket < NB_BOND; loopbasket++) { priceCTD[loopbasket] = priceTest; mdCTD[loopbasket] = METHOD_BOND_SEC.modifiedDurationFromYield(STANDARD[loopbasket], yieldTest); yieldCTD[loopbasket] = METHOD_BOND_SEC.yieldFromCleanPrice(STANDARD[loopbasket], priceTest); } final double[] grossBasis = METHOD_FUT_SEC_DSC.grossBasisFromPrices(BOND_FUTURE, priceCTD, futurePriceTest); final int ctdIndex = 1; assertEquals("Bond future security: CTD - yield from price", yieldTest, yieldCTD[ctdIndex], 1.0E-4); assertEquals("Bond future security: CTD - modified duration from yield", mdTest, mdCTD[ctdIndex], 1.0E-3); assertEquals("Bond future security: CTD - gross basis from price", grossBasisTest / 100.0 / 32.0, grossBasis[ctdIndex], 1.0E-7); }
@Test public void grossBasis() { final double futurePriceTest = 1.19984375; final double[] pricesTest = new double[] {0.86, 0.885, 0.88, 0.8825, 0.885, 0.8725, 0.86 }; final double[] pricesCurvesAtSpot = new double[NB_BOND]; for (int loopbasket = 0; loopbasket < NB_BOND; loopbasket++) { pricesCurvesAtSpot[loopbasket] = METHOD_BOND_SEC.cleanPriceFromCurves(BOND_FUTURE.getDeliveryBasketAtSpotDate()[loopbasket], ISSUER_MULTICURVES); } final double[] basisComputedTest = METHOD_FUT_SEC_DSC.grossBasisFromPrices(BOND_FUTURE, pricesTest, futurePriceTest); final double[] basisComputedCurves = METHOD_FUT_SEC_DSC.grossBasisFromPrices(BOND_FUTURE, pricesCurvesAtSpot, futurePriceTest); final double[] basisExpectedTest = new double[NB_BOND]; final double[] basisExpectedCurves = new double[NB_BOND]; for (int loopbasket = 0; loopbasket < NB_BOND; loopbasket++) { basisExpectedTest[loopbasket] = (pricesTest[loopbasket] - futurePriceTest * CONVERSION_FACTOR[loopbasket]); basisExpectedCurves[loopbasket] = (pricesCurvesAtSpot[loopbasket] - futurePriceTest * CONVERSION_FACTOR[loopbasket]); assertEquals("Gross basis from prices", basisExpectedTest[loopbasket], basisComputedTest[loopbasket], TOLERANCE_PRICE); assertEquals("Gross basis from curves", basisExpectedCurves[loopbasket], basisComputedCurves[loopbasket], TOLERANCE_PRICE); } }