|
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:m="http://www.modelity.com/structures/model" xmlns:mxf="http://www.modelity.com/xslt/functions" xmlns:fn="http://www.w3.org/2005/xpath-functions" version="2.0">
|
|
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
|
|
<xsl:param name="refProdDoc" />
|
|
<xsl:variable name="refProd" select="$refProdDoc" />
|
|
<xsl:variable name="source" select="/" />
|
|
<xsl:variable name="Premium1" select="xs:decimal($source/MxML/trades/trade[1]/tradeBody/fxOption/settlement/settlementFlow/flow/amount/text())" />
|
|
<xsl:variable name="Premium2" select="xs:decimal($source/MxML/trades/trade[2]/tradeBody/fxOption/settlement/settlementFlow/flow/amount/text())" />
|
|
<xsl:template match="node()|@*">
|
|
<xsl:copy>
|
|
<xsl:apply-templates select="node()|@*" />
|
|
</xsl:copy>
|
|
</xsl:template>
|
|
<xsl:template match="/">
|
|
<xsl:apply-templates select="$refProd/node()" />
|
|
</xsl:template>
|
|
<!-- Product Ids -->
|
|
<xsl:template match="/m:product/m:parameter/m:productIdsMeta/m:productIds/m:item/text()">
|
|
<xsl:value-of select="$source/MxML/contracts/contract/businessObjectId/identifier/text()" />
|
|
</xsl:template>
|
|
<!-- Issue Date -->
|
|
<xsl:template match="/m:product/m:schedule/m:issueDateMeta/m:issueDate/m:adjustedDate/m:unadjustedDate/text()">
|
|
<xsl:value-of select="mxf:format-date($source/MxML/contracts/contract/contractHeader/contractSource/originDate/text())" />
|
|
</xsl:template>
|
|
<!-- Delivery Date -->
|
|
<xsl:template match="/m:product/m:schedule/m:maturityDateMeta/m:maturityDate/m:adjustedDate/m:unadjustedDate/text()">
|
|
<xsl:value-of select="mxf:format-date($source/MxML/trades/trade[1]/tradeBody/fxOption/fxVanillaOption/callCurrencyAmount/date/text())" />
|
|
</xsl:template>
|
|
<!-- Strike Date -->
|
|
<xsl:template match="/m:product/m:schedule/m:strikeDateMeta/m:strikeDate/m:adjustedDate/m:unadjustedDate/text()">
|
|
<xsl:value-of select="mxf:format-date($source/MxML/contracts/contract/contractHeader/contractSource/originDate/text())" />
|
|
</xsl:template>
|
|
<!-- Expiry Date -->
|
|
<xsl:template match="/m:product/m:schedule/m:finalValuationDateMeta/m:finalValuationDate/m:adjustedDate/m:unadjustedDate/text()">
|
|
<xsl:value-of select="mxf:format-date($source/MxML/trades/trade[1]/tradeBody/fxOption/fxVanillaOption/option/optionMaturity/date/text())" />
|
|
</xsl:template>
|
|
<!-- Premium Payment Date -->
|
|
<xsl:template match="/m:product/m:schedule/m:premiumPaymentDateMeta/m:premiumPaymentDate/m:adjustedDate/m:unadjustedDate/text()">
|
|
<xsl:if test="$Premium1!=$Premium2">
|
|
<xsl:value-of select="mxf:format-date($source/MxML/trades/trade[1]/tradeBody/fxOption/settlement/settlementFlow/flow/date/text())" />
|
|
</xsl:if>
|
|
</xsl:template>
|
|
<!-- Currency Pair -->
|
|
<xsl:variable name="currency1" select="$source/MxML/trades/trade[1]/tradeBody/fxOption/fxVanillaOption/fxStrike/exchangeRate/fxQuotation/currency1/text()" />
|
|
<xsl:variable name="currency2" select="$source/MxML/trades/trade[1]/tradeBody/fxOption/fxVanillaOption/fxStrike/exchangeRate/fxQuotation/currency2/text()" />
|
|
<xsl:variable name="quoteBasis" select="$source/MxML/trades/trade[1]/tradeBody/fxOption/fxVanillaOption/fxStrike/exchangeRate/fxQuotation/fxQuoteBasis/text()" />
|
|
<xsl:template match="/m:product/m:underlier/m:fxAssetMeta/m:fxAsset/m:instrumentId/text()">
|
|
<xsl:choose>
|
|
<xsl:when test="lower-case($quoteBasis) = lower-case('currency1PerCurrency2')">
|
|
<xsl:value-of select="concat($currency2, $currency1,' Curncy')" />
|
|
</xsl:when>
|
|
<xsl:when test="lower-case($quoteBasis) = lower-case('currency2PerCurrency1')">
|
|
<xsl:value-of select="concat($currency1, $currency2,' Curncy')" />
|
|
</xsl:when>
|
|
</xsl:choose>
|
|
</xsl:template>
|
|
<!-- Base Currency -->
|
|
<xsl:template match="/m:product/m:parameter/m:baseCurrencyMeta/m:baseCurrency/text()">
|
|
<xsl:choose>
|
|
<xsl:when test="lower-case($quoteBasis) = lower-case('currency1PerCurrency2')">
|
|
<xsl:value-of select="$currency2" />
|
|
</xsl:when>
|
|
<xsl:when test="lower-case($quoteBasis) = lower-case('currency2PerCurrency1')">
|
|
<xsl:value-of select="$currency1" />
|
|
</xsl:when>
|
|
</xsl:choose>
|
|
</xsl:template>
|
|
<!-- Counter Currency -->
|
|
<xsl:template match="/m:product/m:parameter/m:counterCurrencyMeta/m:counterCurrency/text()">
|
|
<xsl:choose>
|
|
<xsl:when test="lower-case($quoteBasis) = lower-case('currency1PerCurrency2')">
|
|
<xsl:value-of select="$currency1" />
|
|
</xsl:when>
|
|
<xsl:when test="lower-case($quoteBasis) = lower-case('currency2PerCurrency1')">
|
|
<xsl:value-of select="$currency2" />
|
|
</xsl:when>
|
|
</xsl:choose>
|
|
</xsl:template>
|
|
<!-- Notional Currency -->
|
|
<xsl:template match="/m:product/m:parameter/m:denominationMeta/m:denomination/text()">
|
|
<xsl:value-of select="$source/MxML/trades/trade[1]/tradeBody/fxOption/fxVanillaOption/callCurrencyAmount/currency/text()" />
|
|
</xsl:template>
|
|
<!-- Notional Amount -->
|
|
<xsl:template match="/m:product/m:parameter/m:notionalAmountMeta/m:notionalAmount/text()">
|
|
<xsl:value-of select="xs:decimal($source/MxML/trades/trade[1]/tradeBody/fxOption/fxVanillaOption/callCurrencyAmount/amount/text())" />
|
|
</xsl:template>
|
|
<!-- Premium -->
|
|
<xsl:template match="/m:product/m:parameter/m:premiumMeta/m:premium/text()">
|
|
<!--If Premium1-Premium2>0
|
|
then Premium=Premium1-Premium2
|
|
If Premium1-Premium2<0
|
|
then Premium=Premium2-Premium1
|
|
If Premium1-Premium2=0
|
|
then No Premium -->
|
|
<xsl:value-of select="fn:abs($Premium1 - $Premium2)" />
|
|
</xsl:template>
|
|
<!-- Premium Currency -->
|
|
<xsl:template match="/m:product/m:parameter/m:premiumCurrencyMeta/m:premiumCurrency/text()">
|
|
<xsl:if test="$Premium1!=$Premium2">
|
|
<xsl:value-of select="$source/MxML/trades/trade[1]/tradeBody/fxOption/settlement/settlementFlow/flow/currency/text()" />
|
|
</xsl:if>
|
|
</xsl:template>
|
|
<!-- Settlement -->
|
|
<xsl:template match="/m:product/m:parameter/m:settlementMeta/m:settlement/m:valueId/text()">
|
|
<xsl:choose>
|
|
<xsl:when test="contains(lower-case($source/MxML/trades/trade[1]/tradeBody/fxOption/fxVanillaOption/option/optionExercizeMethod/text()),'delivery')">physical</xsl:when>
|
|
<xsl:otherwise>cash</xsl:otherwise>
|
|
</xsl:choose>
|
|
</xsl:template>
|
|
<!-- Pay/Receive -->
|
|
<xsl:template match="/m:product/m:parameter/m:product_directionMeta/m:product_direction/m:valueId/text()">
|
|
<!-- If "Option 1 Direction"="Client sells"
|
|
then
|
|
If Premium1-Premium2>0
|
|
then "Pay/Receive"="Receive"
|
|
ElseIf Premium1-Premium2<0
|
|
then "Pay/Receive"="Pay"
|
|
If Premium1-Premium2=0
|
|
then Empty
|
|
If "Option 1 Direction"="Client buys"
|
|
then
|
|
If Premium2-Premium1>0
|
|
then "Pay/Receive"="Receive"
|
|
ElseIf Premium2-Premium1<0
|
|
then "Pay/Receive"="Pay"
|
|
If Premium1-Premium2=0
|
|
then Empty -->
|
|
<xsl:choose>
|
|
<xsl:when test="$Option1Direction = 'sells'">
|
|
<xsl:choose>
|
|
<xsl:when test="$Premium1 - $Premium2 > 0 ">receive</xsl:when>
|
|
<xsl:when test="$Premium1 - $Premium2 < 0 ">pay</xsl:when>
|
|
</xsl:choose>
|
|
</xsl:when>
|
|
<xsl:when test="$Option1Direction = 'buys'">
|
|
<xsl:choose>
|
|
<xsl:when test="$Premium2 - $Premium1 > 0 ">receive</xsl:when>
|
|
<xsl:when test="$Premium2 - $Premium1 < 0 ">pay</xsl:when>
|
|
</xsl:choose>
|
|
</xsl:when>
|
|
</xsl:choose>
|
|
</xsl:template>
|
|
<!-- Option 1 Direction -->
|
|
<xsl:variable name="PayerParty" select="$source/MxML/trades/trade[1]/tradeBody/fxOption/fxVanillaOption/option/optionHolderReference/@href" />
|
|
<xsl:variable name="Option1Direction">
|
|
<!-- If "Payer Party" = "#NATIXIS_FXD"
|
|
Then "Direction" = Client sells
|
|
Else "Direction" = Client buys -->
|
|
<xsl:choose>
|
|
<xsl:when test="upper-case($PayerParty) = '#NATIXIS_FXD'">sells</xsl:when>
|
|
<xsl:otherwise>buys</xsl:otherwise>
|
|
</xsl:choose>
|
|
</xsl:variable>
|
|
<xsl:template match="/m:product/m:parameter/m:option_1_directionMeta/m:option_1_direction/m:valueId/text()">
|
|
<xsl:value-of select="$Option1Direction" />
|
|
</xsl:template>
|
|
<!-- Option 1 Style -->
|
|
<xsl:template match="/m:product/m:parameter/m:option_1_styleMeta/m:option_1_style/m:valueId/text()">
|
|
<xsl:variable name="optionStyle" select="$source/MxML/trades/trade[1]/tradeBody/fxOption/fxVanillaOption/option/optionStyle/text()" />
|
|
<xsl:choose>
|
|
<xsl:when test="lower-case($optionStyle) = 'european' or lower-case($optionStyle) = 'american'">
|
|
<xsl:value-of select="$optionStyle" />
|
|
</xsl:when>
|
|
<xsl:otherwise>
|
|
<xsl:message>
|
|
<xsl:value-of select="concat('Warning! Unknown option 1 style : ',$optionStyle)" />
|
|
</xsl:message>
|
|
</xsl:otherwise>
|
|
</xsl:choose>
|
|
</xsl:template>
|
|
<!-- Option 1 Call/Put Currency -->
|
|
<xsl:template match="/m:product/m:parameter/m:option_1_callPutCurrencyMeta/m:option_1_callPutCurrency/text()">
|
|
<xsl:value-of select="$source/MxML/trades/trade[1]/tradeBody/fxOption/fxVanillaOption/callCurrencyAmount/currency/text()" />
|
|
</xsl:template>
|
|
<!-- Option 1 Strike Rate -->
|
|
<xsl:template match="/m:product/m:parameter/m:option_1_strikeRateMeta/m:option_1_strikeRate/text()">
|
|
<xsl:value-of select="$source/MxML/trades/trade[1]/tradeBody/fxOption/fxVanillaOption/fxStrike/exchangeRate/rate/text()" />
|
|
</xsl:template>
|
|
<!-- Option 1 Ratio -->
|
|
<xsl:template match="/m:product/m:parameter/m:option_1_ratioMeta/m:option_1_ratio/text()">
|
|
<xsl:value-of select="$source/MxML/trades/trade[1]/tradeBody/fxOption/fxVanillaOption/fxStrike/exchangeRate/fxQuotation/formFactor/text()" />
|
|
</xsl:template>
|
|
<!-- Option 2 Direction -->
|
|
<xsl:variable name="PayerParty2" select="$source/MxML/trades/trade[2]/tradeBody/fxOption/fxBarrierOption/fxOption/fxVanillaOption/option/optionHolderReference/@href" />
|
|
<xsl:template match="/m:product/m:parameter/m:option_2_directionMeta/m:option_2_direction/m:valueId/text()">
|
|
<xsl:choose>
|
|
<xsl:when test="upper-case($PayerParty2) = '#NATIXIS_FXD'">sells</xsl:when>
|
|
<xsl:otherwise>buys</xsl:otherwise>
|
|
</xsl:choose>
|
|
</xsl:template>
|
|
<!-- Option 2 Style -->
|
|
<xsl:template match="/m:product/m:parameter/m:option_2_styleMeta/m:option_2_style/m:valueId/text()">
|
|
<xsl:variable name="src" select="lower-case($source/MxML/trades/trade[2]/tradeBody/fxOption/fxBarrierOption/fxOption/fxVanillaOption/option/optionStyle/text())" />
|
|
<xsl:choose>
|
|
<xsl:when test="$src = 'european' or $src = 'american'">
|
|
<xsl:value-of select="$src" />
|
|
</xsl:when>
|
|
<xsl:otherwise>
|
|
<xsl:message>
|
|
<xsl:value-of select="concat('Warning! Unknown option 2 style : ',$src)" />
|
|
</xsl:message>
|
|
</xsl:otherwise>
|
|
</xsl:choose>
|
|
</xsl:template>
|
|
<!-- Option 2 Call/Put Currency -->
|
|
<xsl:template match="/m:product/m:parameter/m:option_2_callPutCurrencyMeta/m:option_2_callPutCurrency/text()">
|
|
<xsl:value-of select="$source/MxML/trades/trade[2]/tradeBody/fxOption/fxBarrierOption/fxOption/fxVanillaOption/putCurrencyAmount/currency/text()" />
|
|
</xsl:template>
|
|
<!-- Option 2 Strike Rate -->
|
|
<xsl:template match="/m:product/m:parameter/m:option_2_strikeRateMeta/m:option_2_strikeRate/text()">
|
|
<xsl:value-of select="$source/MxML/trades/trade[2]/tradeBody/fxOption/fxBarrierOption/fxOption/fxVanillaOption/fxStrike/exchangeRate/rate/text()" />
|
|
</xsl:template>
|
|
<!-- Option 2 Ratio -->
|
|
<xsl:template match="/m:product/m:parameter/m:option_2_ratioMeta/m:option_2_ratio/text()">
|
|
<xsl:value-of select="$source/MxML/trades/trade[2]/tradeBody/fxOption/fxBarrierOption/fxOption/fxVanillaOption/fxStrike/exchangeRate/fxQuotation/formFactor/text()" />
|
|
</xsl:template>
|
|
<!-- Option 2 Knockin Lower Barrier -->
|
|
<xsl:variable name="BarrierRate" select="$source/MxML/trades/trade[2]/tradeBody/fxOption/fxBarrierOption/barrierBlock/singleBarrier/barrierRate/rate/text()" />
|
|
<xsl:variable name="BarrierType" select="$source/MxML/trades/trade[2]/tradeBody/fxOption/fxBarrierOption/barrierBlock/singleBarrier/barrierType/text()" />
|
|
<!-- first remove 'option_2_Knock...Barrier' node if exist in modelity.xml template,
|
|
then copy everything and then conditionally add 'option_2_Knock...Barrier' node-->
|
|
<xsl:template match="/m:product/m:parameter/m:option_2_KnockinLowerBarrierMeta/m:option_2_KnockinLowerBarrier" />
|
|
<xsl:template match="/m:product/m:parameter/m:option_2_KnockinLowerBarrierMeta/@initMode">
|
|
<xsl:copy-of select="." />
|
|
<xsl:if test="$BarrierType = 'downAndIn'">
|
|
<xsl:element name="option_2_KnockinLowerBarrier" namespace="http://www.modelity.com/structures/model">
|
|
<xsl:value-of select="$BarrierRate" />
|
|
</xsl:element>
|
|
</xsl:if>
|
|
</xsl:template>
|
|
<!-- Option 2 Knockin Upper Barrier -->
|
|
<xsl:template match="/m:product/m:parameter/m:option_2_KnockinUpperBarrierMeta/m:option_2_KnockinUpperBarrier" />
|
|
<xsl:template match="/m:product/m:parameter/m:option_2_KnockinUpperBarrierMeta/@initMode">
|
|
<xsl:copy-of select="." />
|
|
<xsl:choose>
|
|
<xsl:when test="$BarrierType = 'upAndIn'">
|
|
<xsl:element name="option_2_KnockinUpperBarrier" namespace="http://www.modelity.com/structures/model">
|
|
<xsl:value-of select="$BarrierRate" />
|
|
</xsl:element>
|
|
</xsl:when>
|
|
</xsl:choose>
|
|
</xsl:template>
|
|
<!-- Option 2 Knockout Lower Barrier -->
|
|
<xsl:template match="/m:product/m:parameter/m:option_2_KnockoutLowerBarrierMeta/ m:option_2_KnockoutLowerBarrier" />
|
|
<xsl:template match="/m:product/m:parameter/m:option_2_KnockoutLowerBarrierMeta/@initMode">
|
|
<xsl:copy-of select="." />
|
|
<xsl:choose>
|
|
<xsl:when test="$BarrierType = 'downAndOut'">
|
|
<xsl:element name="option_2_KnockoutLowerBarrier" namespace="http://www.modelity.com/structures/model">
|
|
<xsl:value-of select="$BarrierRate" />
|
|
</xsl:element>
|
|
</xsl:when>
|
|
</xsl:choose>
|
|
</xsl:template>
|
|
<!-- Option 2 Knockout Upper Barrier -->
|
|
<xsl:template match="/m:product/m:parameter/m:option_2_KnockoutUpperBarrierMeta/ m:option_2_KnockoutUpperBarrier" />
|
|
<xsl:template match="/m:product/m:parameter/m:option_2_KnockoutUpperBarrierMeta/@initMode">
|
|
<xsl:copy-of select="." />
|
|
<xsl:choose>
|
|
<xsl:when test="$BarrierType = 'upAndOut'">
|
|
<xsl:element name="option_2_KnockoutUpperBarrier" namespace="http://www.modelity.com/structures/model">
|
|
<xsl:value-of select="$BarrierRate" />
|
|
</xsl:element>
|
|
</xsl:when>
|
|
</xsl:choose>
|
|
</xsl:template>
|
|
<!-- Option 2 Rebate -->
|
|
<xsl:template match="/m:product/m:parameter/m:option_1_RebateMeta">
|
|
<xsl:element name="option_1_RebateMeta" namespace="http://www.modelity.com/structures/model">
|
|
<xsl:value-of select="$source/MxML/trades/trade[2]/tradeBody/fxOption/fxBarrierOption/barrierBlock/singleBarrier/rebate/rebateAmount/text()" />
|
|
</xsl:element>
|
|
</xsl:template>
|
|
<!-- Custom date formatter: YYYYmmdd => YYYY-mm-dd -->
|
|
<xsl:function name="mxf:format-date" as="xs:date">
|
|
<xsl:param name="customDate" as="xs:string" />
|
|
<xsl:value-of select="replace($customDate,'(\d{4})(\d{2})(\d{2})','$1-$2-$3')" />
|
|
</xsl:function>
|
|
</xsl:stylesheet>
|