Hi
I am trying to calculate the PV and DV01 for a plain vanilla 3 year interest rate swap.
Have the following code modified from SwapPricingTest.java:
SwapLeg payLeg = RateCalculationSwapLeg.builder()
.payReceive(PayReceive.PAY)
.accrualSchedule(PeriodicSchedule.builder()
.startDate(LocalDate.of(2016, 8, 10))
.endDate(LocalDate.of(2019, 8, 10))
.frequency(Frequency.P6M)
.businessDayAdjustment(BusinessDayAdjustment.of(BusinessDayConventions.MODIFIED_FOLLOWING, CalendarUSD.NYC))
.stubConvention(null)
.build())
.paymentSchedule(PaymentSchedule.builder()
.paymentFrequency(Frequency.P6M)
.paymentDateOffset(DaysAdjustment.NONE)
.build())
.notionalSchedule(NOTIONAL)
.calculation(FixedRateCalculation.of(1.072 * 0.01, THIRTY_U_360))
.build();
SwapLeg receiveLeg = RateCalculationSwapLeg.builder()
.payReceive(RECEIVE)
.accrualSchedule(PeriodicSchedule.builder()
.startDate(LocalDate.of(2016, 8, 10))
.endDate(LocalDate.of(2019, 8, 10))
.frequency(Frequency.P1M)
.businessDayAdjustment(BusinessDayAdjustment.of(BusinessDayConventions.MODIFIED_FOLLOWING, CalendarUSD.NYC))
.build())
.paymentSchedule(PaymentSchedule.builder()
.paymentFrequency(Frequency.P1M)
.paymentDateOffset(DaysAdjustment.NONE)
.build())
.notionalSchedule(NOTIONAL)
.calculation(IborRateCalculation.builder()
.index(USD_LIBOR_1M)
.fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P))
.build())
.build();
Swap swap = Swap.of(payLeg, receiveLeg);
SwapTrade trade = SwapTrade.builder()
.info(TradeInfo.builder().tradeDate(LocalDate.of(2016, 8, 8)).build())
.product(swap).build();
CurveGroupName groupName = CurveGroupName.of("Test");
CurveId idUsdDsc = CurveId.of(groupName, StandardDataSets.GROUP1_USD_DSC.getName());
CurveId idUsdOn = CurveId.of(groupName, StandardDataSets.GROUP1_USD_ON.getName());
CurveId idUsdL1M = CurveId.of(groupName, StandardDataSets.GROUP1_USD_L1M.getName());
CurveId idUsdL3M = CurveId.of(groupName, StandardDataSets.GROUP1_USD_L3M.getName());
CurveId idUsdL6M = CurveId.of(groupName, StandardDataSets.GROUP1_USD_L6M.getName());
MarketData suppliedData = ImmutableMarketData.builder(VAL_DATE)
.addValue(idUsdDsc, StandardDataSets.GROUP1_USD_DSC)
.addValue(idUsdOn, StandardDataSets.GROUP1_USD_ON)
.addValue(idUsdL1M, StandardDataSets.GROUP1_USD_L1M)
.addValue(idUsdL3M, StandardDataSets.GROUP1_USD_L3M)
.addValue(idUsdL6M, StandardDataSets.GROUP1_USD_L6M)
.build();
CalculationFunctions functions = StandardComponents.calculationFunctions();
RatesMarketDataLookup ratesLookup = RatesMarketDataLookup.of(
ImmutableMap.of(
USD, idUsdDsc),
ImmutableMap.of(
USD_FED_FUND, idUsdOn,
USD_LIBOR_1M, idUsdL1M,
USD_LIBOR_3M, idUsdL3M,
USD_LIBOR_6M, idUsdL6M));
// create the calculation runner
List<SwapTrade> trades = ImmutableList.of(trade);
List<Column> columns = ImmutableList.of(
Column.of(Measures.LEG_INITIAL_NOTIONAL),
Column.of(Measures.PRESENT_VALUE),
Column.of(Measures.LEG_PRESENT_VALUE),
Column.of(Measures.PV01_CALIBRATED_SUM),
Column.of(Measures.PAR_RATE),
Column.of(Measures.ACCRUED_INTEREST));
CalculationRules rules = CalculationRules.of(functions, USD, ratesLookup);
// calculate results using the runner
// using the direct executor means there is no need to close/shutdown the runner
CalculationRunner runner = CalculationRunner.of(MoreExecutors.newDirectExecutorService());
Results results = runner.calculate(rules, trades, columns, suppliedData, REF_DATA);
//System.out.println(JodaBeanSer.PRETTY.xmlWriter().write(swap));
for(int i = 0; i< results.getRowCount(); i++){
for(int j =0;j < results.getColumnCount(); j++){
Result<?> result = results.get(i, j);
System.out.println(result.getClass()+":"+result.getValue());
}
}
2 questions:
- I have my own real-time source of Libor and swap rates. How do I build the MarketData for the CalculationRunner in order to match the Bloomberg terminal ?
- Measures/AdvancedMeasures doesn’t have DV01. Do you currently support it ?