Pricer API for Fixed Coupon Bonds


There are currently examples in Strata to demonstrate how to use the Calc API but I am unable to find an example on how to use the Pricer Level API in strata for the asset types that can not be priced using the Calc API, such as Fixed Coupon Bonds.

Is there any example online or method to teach how to use the pricer api? Currently, I am trying to work on how to price a Fixed Coupon Bond?

What is the purpose of LegalEntityDiscountingProvider

The pricer API is fairly simple to use:

FixedCouponBondTrade bondTrade = ...  // create trade
ResolvedFixedCouponBondTrade resolvedTrade = bondTrade.resolve(ReferenceData.standard());

LegalEntityDiscountingProvider provider = ... // create market data

DiscountingFixedCouponBondTradePricerpricer = DiscountingFixedCouponBondTradePricer.DEFAULT;
double computed = pricer.presentValue(resolvedTrade, provider);

Note that a lot of methods are on DiscountingFixedCouponBondProductPricer rather than DiscountingFixedCouponBondTradePricer, so you may need to use the product (bond) rather than the trade in some cases.

A good place for example code is test cases, such as DiscountingFixedCouponBondTradePricerTest and DiscountingFixedCouponBondProductPricerTest.


Thank you Stephen, I am going through both the test cases “DiscountingFixedCouponBondTradePricerTest”, “DiscountingFixedCouponBondProductPricerTest” now.

Is there any way to load trades from xml’s. Such as the the xml portfolio’s used in the SwapPricingExample, or currently do the trades for Bonds have to be made using code directly i.e:

private static final ResolvedFixedCouponBondTrade TRADE = ResolvedFixedCouponBondTrade.builder()

I know the way strata was converting the trades from xml was by using the javabeans module. Is there something similar for Bond’s as well?


There is currently no supported mechanism for loading bonds from CSV/XML. It is possible to load them using Joda-Beans:


However, this format is undocumented and subject to change. (Almost all classes in Strata are Joda-Beans, and thus they can all be read/written in this way). If you want to use the Joda-Beans format, your best approach is to create some bonds using code and write them out to see what the format is, see SwapTradeExample for example code that reads/writes.


Thank you Stephen, I managed to convert the “ResolvedFixedCouponBondTrade” into an xml.
I was wondering if there is going to be any support in the Calc API to price bonds in the next version of Strata?
If not, I have been trying to extend the Calc API definition to accept “ResolvedFixedCouponBondTrade” but I keep getting stuck at this error: cannot be cast to com.opengamma.strata.product.Trade

and I am unable to work out where exactly do I need to add the CouponBond definition to? The “Trade” and the “CalculationTarget” classes are seemingly empty?

Thank you


The calculation API - CalculationRunner- requires the input to be FixedCouponBondTrade, not ResolvedFixedCouponBondTrade.

We do intend to extend the calc-API to cover the missing asset classes, its just a matter of development time. Adding it yourself is possible, but not the easiest. You’d have to copy the two classes FraTradeCalculationFunction and FraMeasureCalculations, changing Fra to FixedCouponBond, and then fixup any errors. The main problem is that the bond code requires a LegalEntityDiscountingProvider, which the calc API does not known about yet, and adding that support will be relatively complex.


I will give it a try and see what happens. In stead of adding the LegalEntityDiscountingProvider support to the calc API, would it not make more sense to add MarketData class support to pricing a Bond in the following way:

  LocalDate valuationDate = LocalDate.of(date); 
  Path marketDataDir = Paths.get(location);
  ExampleMarketDataBuilder marketDataBuilder = ExampleMarketDataBuilder.ofPath(marketDataDir);
  MarketData marketSnapshot = marketDataBuilder.buildSnapshot(valuationDate);

And then whilst building the MarketData only take the interest curve values and use them to price the bond on that given date? Therefore, editing the bond definition to accept either LegalEntityDiscountingProvider or MarketData. As both would have the interest level rates needed to price the bond?

In addition, do you have any timeline outlining when each additional asset class would be added to the Calc API or is there a version number by which you hope to add the remaining asset classes by?

Thank you


An instance of MarketData is structured to contain any market data. In this sense, it could contain many LegalEntityDiscountingProvider instances. The purpose of the “lookup” interfaces is to select one provider out of the many (of course in most cases, there will only be one provider). Given this, MarketData is the wrong object to use in the pricers, which need a single specific set of data.

(This split makes more sense with curves. For example, an application may have multiple USD discounting curves, such as one for Hedge Funds and one for Banks. Each discounting curve would be in MarketData, but only only would be exposed to the pricer API via RatesProvider.)

I hope that we will have calc-API asset class coverage in the next release, which I hope to be during September.