F#: Modelling An Interest Rate Swap (IRS) Trade Using FpML 5.0
I want to take the previous blogged Market Risk IRS trade to the next level, and move from Excel to a real calculation engine. To aid this I need to model a trade. I was going to start with auto-generating C# code from FpML, but I though it would be more interesting to build the Proof Of Concept (POC) types in F# – and XSD.EXE doesn’t support F#
FpML is probably the best scheme to model off since the ISDA initially create FpML for a purely IRS perspective, but has now moved to cover multiple products. For this example, I’m looking at section 5.1 Interest Rate Swap.
If you are doing anything with FpML then get XMLSpy.
The 5.0 release of FpML is different from previously published versions of FpML in that it is no longer a single XML schema. Each view in 5.0 (e.g. pre-trade, confirmation, reporting, etc.) is a separate schema derived from a master schema using a code generation procedure that uses embedded control information to decide which elements to copy and how to adjust them to suit the needs of the view.
So taking FpML 5.0 we get the following parametric view of the previous blogged IRS trade:
<dataDocument xmlns="http://www.fpml.org/FpML-5/confirmation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" fpmlVersion="5-0" xsi:schemaLocation="http://www.fpml.org/FpML-5/confirmation ../../fpml-main-5-0.xsd">
<trade>
<tradeHeader>
<partyTradeIdentifier>
<partyReference href="party1"/>
<tradeId tradeIdScheme="http://www.paybank.com/swaps/trade-id">PAY1001</tradeId>
</partyTradeIdentifier>
<partyTradeIdentifier>
<partyReference href="party2"/>
<tradeId tradeIdScheme="http://www.receivebank.com/swaps/trade-id">RECEIVE2002</tradeId>
</partyTradeIdentifier>
<tradeDate>2010-03-09Z</tradeDate>
</tradeHeader>
<swap>
<!-- PAYBANK pays the floating rate every 6 months, based on 6M USE-LIBOR,
on an ACT/360 basis -->
<swapStream>
<payerPartyReference href="party1"/>
<receiverPartyReference href="party2"/>
<calculationPeriodDates id="floatingCalcPeriodDates">
<effectiveDate>
<unadjustedDate>2010-01-01Z</unadjustedDate>
<dateAdjustments>
<businessDayConvention>NONE</businessDayConvention>
</dateAdjustments>
</effectiveDate>
<terminationDate>
<unadjustedDate>2015-01-01Z</unadjustedDate>
<dateAdjustments>
<businessDayConvention>MODFOLLOWING</businessDayConvention>
<businessCenters id="primaryBusinessCenters">
<businessCenter>GBLO</businessCenter>
</businessCenters>
</dateAdjustments>
</terminationDate>
<calculationPeriodDatesAdjustments>
<businessDayConvention>MODFOLLOWING</businessDayConvention>
<businessCentersReference href="primaryBusinessCenters"/>
</calculationPeriodDatesAdjustments>
<calculationPeriodFrequency>
<periodMultiplier>6</periodMultiplier>
<period>M</period>
<rollConvention>1</rollConvention>
</calculationPeriodFrequency>
</calculationPeriodDates>
<paymentDates>
<calculationPeriodDatesReference href="floatingCalcPeriodDates"/>
<paymentFrequency>
<periodMultiplier>6</periodMultiplier>
<period>M</period>
</paymentFrequency>
<payRelativeTo>CalculationPeriodEndDate</payRelativeTo>
<paymentDatesAdjustments>
<businessDayConvention>MODFOLLOWING</businessDayConvention>
<businessCentersReference href="primaryBusinessCenters"/>
</paymentDatesAdjustments>
</paymentDates>
<resetDates id="resetDates">
<calculationPeriodDatesReference href="floatingCalcPeriodDates"/>
<resetRelativeTo>CalculationPeriodStartDate</resetRelativeTo>
<fixingDates>
<periodMultiplier>-2</periodMultiplier>
<period>D</period>
<dayType>Business</dayType>
<businessDayConvention>NONE</businessDayConvention>
<businessCenters>
<businessCenter>GBLO</businessCenter>
</businessCenters>
<dateRelativeTo href="resetDates"/>
</fixingDates>
<resetFrequency>
<periodMultiplier>6</periodMultiplier>
<period>M</period>
</resetFrequency>
<resetDatesAdjustments>
<businessDayConvention>MODFOLLOWING</businessDayConvention>
<businessCentersReference href="primaryBusinessCenters"/>
</resetDatesAdjustments>
</resetDates>
<calculationPeriodAmount>
<calculation>
<notionalSchedule>
<notionalStepSchedule>
<initialValue>100000000.00</initialValue>
<currency currencyScheme="http://www.fpml.org/ext/iso4217">USD</currency>
</notionalStepSchedule>
</notionalSchedule>
<floatingRateCalculation>
<floatingRateIndex>USD-LIBOR</floatingRateIndex>
<indexTenor>
<periodMultiplier>6</periodMultiplier>
<period>M</period>
</indexTenor>
</floatingRateCalculation>
<dayCountFraction>ACT/360</dayCountFraction>
</calculation>
</calculationPeriodAmount>
</swapStream>
<!-- RECEIVEBANK pays the 5% fixed rate every year on a 30E/360 basis -->
<swapStream>
<payerPartyReference href="party2"/>
<receiverPartyReference href="party1"/>
<calculationPeriodDates id="fixedCalcPeriodDates">
<effectiveDate>
<unadjustedDate>2010-01-01Z</unadjustedDate>
<dateAdjustments>
<businessDayConvention>NONE</businessDayConvention>
</dateAdjustments>
</effectiveDate>
<terminationDate>
<unadjustedDate>2015-01-01Z</unadjustedDate>
<dateAdjustments>
<businessDayConvention>MODFOLLOWING</businessDayConvention>
<businessCentersReference href="primaryBusinessCenters"/>
</dateAdjustments>
</terminationDate>
<calculationPeriodDatesAdjustments>
<businessDayConvention>MODFOLLOWING</businessDayConvention>
<businessCentersReference href="primaryBusinessCenters"/>
</calculationPeriodDatesAdjustments>
<calculationPeriodFrequency>
<periodMultiplier>6</periodMultiplier>
<period>M</period>
<rollConvention>1</rollConvention>
</calculationPeriodFrequency>
</calculationPeriodDates>
<paymentDates>
<calculationPeriodDatesReference href="fixedCalcPeriodDates"/>
<paymentFrequency>
<periodMultiplier>6</periodMultiplier>
<period>M</period>
</paymentFrequency>
<payRelativeTo>CalculationPeriodEndDate</payRelativeTo>
<paymentDatesAdjustments>
<businessDayConvention>MODFOLLOWING</businessDayConvention>
<businessCentersReference href="primaryBusinessCenters"/>
</paymentDatesAdjustments>
</paymentDates>
<calculationPeriodAmount>
<calculation>
<notionalSchedule>
<notionalStepSchedule>
<initialValue>100000000.00</initialValue>
<currency currencyScheme="http://www.fpml.org/ext/iso4217">GBP</currency>
</notionalStepSchedule>
</notionalSchedule>
<fixedRateSchedule>
<initialValue>0.05</initialValue>
</fixedRateSchedule>
<dayCountFraction>30E/360</dayCountFraction>
</calculation>
</calculationPeriodAmount>
</swapStream>
</swap>
</trade>
<party id="party1">
<partyId>RECEIVEPARTY</partyId>
</party>
<party id="party2">
<partyId>PAYPARTY</partyId>
</party>
</dataDocument>
From an F# perspective, and somewhat simplified from the above FpML we end up with something like this:
open System;
type TradeHeader =
{
TradeDate : DateTime;
}
type CalculationPeriodFrequency =
{
PeriodMultiplier : int;
Period : string;
}
type CalculationPeriodDates =
{
EffectiveDate : DateTime;
TerminationDate : DateTime;
CalculationPeriodFrequency : CalculationPeriodFrequency;
}
type PaymentFrequency =
{
PeriodMultiplier : int;
Period : string;
}
type PaymentDates =
{
PaymentFrequency : PaymentFrequency;
}
type InterestRateStream =
{
CalculationPeriodDates: CalculationPeriodDates;
PaymentDates : PaymentDates;
}
type Trade =
{
Id : int;
Header : TradeHeader;
SwapStream: seq<InterestRateStream>;
}

hi , i want to send ,order date i.e productname,ticker,bidprice,offerprice,Buy Or Sell in fpml formate and validate with xds schema ,i am new ti Fpml thats why no idea how to senf it,canu guied me..
Cool post. Something I did some experimenting with at a firm we both worked at together a while ago.
Why not use a .Net Timespan for fpml:CalculationPeriodFrequency and fpml:PaymentFrequency? IIRC FpML distinguishes between Frequency and Duration, which you might also do. The reason FpML does is because different validation rules apply to Frequency and Duration.
TradeDate as DateTime doesn’t always work in practise because it loses some information about the time offset. Then you wouldn’t be able to evaluate all the FpML validation rules.
I can’t see why SwapStream is a sequence. OK, the XML is a sequence, but the semantics are whatever the schema author says they are, which is unsequenced.
In general the really hard problem is representing the FpML validation rules as types.
[...] F#: Modelling An Interest Rate Swap (IRS) Trade Using FpML 5.0 … [...]
How to Draw a Car said this on May 14, 2010 at 5:55 am |
[...] I’ve leveraged FpML when it came to modelling in the IR space. Although there are advantages to going with FpML from a [...]
Bitemporal: Modelling Trade and Lifecycle Events – Part 4 « Tales from a Trading Desk said this on December 9, 2011 at 6:11 pm |