Using fpml data to price financial instruments


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()) {
	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(

	    // How do I select the market data from a file, this is currently from
	    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);


Use ExampleMarketDataBuilder.ofPath(marketDataDir) instead of ExampleMarketData.builder() if you want to specify the location of the market data directory.

The market data directory must have the same structure as the example-marketdata directory in the strata-examples module.



Thank you, that worked like a charm.
If instead of parsing through a FpML file and instead I want to use the sample portfolio’s you have provided, how would I go through with that.
From the Git Hub page, I know that I have to use the “TradeListParameterConverter” class but am unsure of how.

this is what I have so far:

String location = "C:/Users/jkapur/Strata/modules/swap-portfolio.xml"
List<Trade> trades = TradeListParameterConverter(location)


This code is based on JodaBeanParameterConverter:

TradeList loadTrades(String filename) {
    try {
      File f = new File(fileName);
      try (Reader reader = new InputStreamReader(new FileInputStream(f), StandardCharsets.UTF_8)) {
        return JodaBeanSer.PRETTY.xmlReader().read(reader, TradeList.class);
    } catch (IOException ex) {
      throw new UncheckedIOException(ex);


If I specify a local directory the method executes without any errors. The problem, is when I try to use a hosted directory like url. Shown below

Path marketDataDir = Paths.get("localhost:8888/marketdata");
ExampleMarketDataBuilder marketDataBuilder = ExampleMarketDataBuilder.ofPath(marketDataDir);

Is there a way to use URL’s to point to a directory, like below, or would that require changing all the method definitions in “DirectoryMarketBuilder”?

URL url = new URL(fileName);


The ExampleMarketDataBuilder only works with directories on the local filesystem. There is no way to load data over HTTP.