Hi guys , I m trying to calculate the present value for a swap trade using the resources from the strata examples. This is the error I get in the NPV column : Market data not found for identifier ‘CurveId:Default/USD-Disc’ of type ‘CurveId’ and this is my class :
`
public class swapPV {
private static SwapLeg payLeg;
private static SwapLeg receiveLeg;
public swapPV() {};
public static Swap createProduct() {
payLeg = RateCalculationSwapLeg.builder()
.payReceive(PayReceive.PAY)
.accrualSchedule(PeriodicSchedule.builder()
.startDate(LocalDate.of(2014, 9, 12))
.endDate(LocalDate.of(2021, 9, 12))
.frequency(Frequency.P6M)
.businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY))
.build())
.paymentSchedule(PaymentSchedule.builder()
.paymentFrequency(Frequency.P6M)
.paymentDateOffset(DaysAdjustment.NONE)
.build())
.notionalSchedule(NotionalSchedule.of(Currency.USD, 100_000_000))
.calculation(FixedRateCalculation.of(0.015, DayCounts.THIRTY_U_360))
.build();
receiveLeg = RateCalculationSwapLeg.builder()
.payReceive(PayReceive.RECEIVE)
.accrualSchedule(PeriodicSchedule.builder()
.startDate(LocalDate.of(2014, 9, 12))
.endDate(LocalDate.of(2021, 9, 12))
.frequency(Frequency.P3M)
.businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY))
.build())
.paymentSchedule(PaymentSchedule.builder()
.paymentFrequency(Frequency.P3M)
.paymentDateOffset(DaysAdjustment.NONE)
.build())
.notionalSchedule(NotionalSchedule.of(Currency.USD, 100_000_000))
.calculation(IborRateCalculation.of(IborIndices.USD_LIBOR_3M))
.build();
return of(payLeg, receiveLeg);
}
public static SwapTrade createTrade() {
SwapTrade swapTrade = SwapTrade.builder()
.product(createProduct())
.info(TradeInfo.builder()
.id(StandardId.of("example", "2"))
.addAttribute(AttributeType.DESCRIPTION, "Libor 3m + spread vs Libor 6m")
.counterparty(StandardId.of("example", "A"))
.settlementDate(LocalDate.of(2014, 9, 12))
.build())
.build();
return swapTrade;
}
public static void calculatePV(CalculationRunner runner) {
Trade trade = createTrade();
// the columns, specifying the measures to be calculated
List<Column> columns = ImmutableList.of(
Column.of(Measures.PRESENT_VALUE));
// use the built-in example market data
LocalDate valuationDate = LocalDate.of(2014, 1, 22);
ExampleMarketDataBuilder marketDataBuilder = ExampleMarketData.builder();
MarketData marketData = marketDataBuilder.buildSnapshot(valuationDate);
// the complete set of rules for calculating measures
CalculationFunctions functions = StandardComponents.calculationFunctions();
CalculationRules rules = CalculationRules.of(functions, marketDataBuilder.ratesLookup(valuationDate));
// the reference data, such as holidays and securities
ReferenceData refData = ReferenceData.standard();
// calculate the results
Results results = runner.calculate(rules, Collections.singletonList((SwapTrade) trade), columns, marketData, refData);
// use the report runner to transform the engine results into a trade report
ReportCalculationResults calculationResults =
ReportCalculationResults.of(valuationDate, Collections.singletonList((SwapTrade) trade), columns, results, functions, refData);
TradeReportTemplate reportTemplate = ExampleData.loadTradeReportTemplate("swap-report-template");
TradeReport tradeReport = TradeReport.of(calculationResults, reportTemplate);
tradeReport.writeAsciiTable(System.out);
}
public static void main(String[] args) {
// setup calculation runner component, which needs life-cycle management
// a typical application might use dependency injection to obtain the instance
try (CalculationRunner runner = CalculationRunner.ofMultiThreaded()) {
calculatePV(runner);
}
}
}
`