I am currently working on a script that is using the CalculationRunner class from the strata-calc module. The script will basically take in FpML data and the return the net present value of each of the trades present in the FpML portfolio.
I understand to correctly use the CalculationRunner class, you need to pass in rules, trades and market data. The trades will come from the FpML file, the rules will be constant as the only calculation being performed will be Net Present Value, the issue I am facing is the market data. How do I pass a directory to capture the market data?
I have pasted my code below so you can see where I am currently:
public class FpMLexample {
/**
* @param args
*/
public static void main(String[] args) {
try (CalculationRunner runner = CalculationRunner.ofMultiThreaded()) {
calculate(runner);
}
}
private static void calculate(CalculationRunner runner) {
// Method to add FpML data
String location = "file:C:/Users/jkapur/Strata/modules/loader/target/test-classes/com/opengamma/strata/loader/fpml/ird-ex01-vanilla-swap.xml";
ByteSource resource = ResourceLocator.of(location).getByteSource();
List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party1")).parseTrades(resource);
// the columns, specifying the measures to be calculated
List<Column> columns = ImmutableList.of(
Column.of(Measures.PRESENT_VALUE));
// How do I select the market data from a file, this is currently from SwapPricingExample.java
LocalDate valuationDate = LocalDate.of(2014, 1, 22);
ExampleMarketDataBuilder marketDataBuilder = ExampleMarketData.builder();
ScenarioMarketData marketSnapshot = 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.calculateSingleScenario(rules, trades, columns, marketSnapshot, refData);
// use the report runner to transform the engine results into a trade report
ReportCalculationResults calculationResults =
ReportCalculationResults.of(valuationDate, trades, columns, results, refData);
TradeReportTemplate reportTemplate = ExampleData.loadTradeReportTemplate("swap-report-template3");
TradeReport tradeReport = TradeReport.of(calculationResults, reportTemplate);
tradeReport.writeAsciiTable(System.out); //tradeReport.writeCsv(System.out);
}
}