/// <summary> /// Builds an fx trade from the current vanillar fx option class. /// </summary> /// <param name="hasExpired"></param> /// <returns></returns> public FxSingleLeg CreateFxSingleLeg(bool hasExpired)//TODO This is not correct and will need to be fixed { QuoteBasisEnum quoteBasis = strike.strikeQuoteBasis == StrikeQuoteBasisEnum.CallCurrencyPerPutCurrency ? QuoteBasisEnum.Currency2PerCurrency1 : QuoteBasisEnum.Currency1PerCurrency2; ExchangeRate exchangeRate = hasExpired ? ExchangeRate.Create(putCurrencyAmount.currency.Value, putCurrencyAmount.currency.Value, quoteBasis, strike.rate) : ExchangeRate.Create(putCurrencyAmount.currency.Value, putCurrencyAmount.currency.Value, quoteBasis, strike.rate, strike.rate, null); var fxforward = new FxSingleLeg { exchangedCurrency1 = PaymentHelper.Create(sellerAccountReference.href, buyerAccountReference.href, putCurrencyAmount.currency.Value, putCurrencyAmount.amount), exchangedCurrency2 = PaymentHelper.Create(buyerAccountReference.href, sellerAccountReference.href, callCurrencyAmount.currency.Value, callCurrencyAmount.amount), exchangeRate = exchangeRate, Items1ElementName = new[] { Items1ChoiceType.valueDate } }; var exercise = Item as FxEuropeanExercise; if (exercise != null) { fxforward.Items1 = new[] { exercise.expiryDate }; } return(fxforward); }
private void SetProperties(QuoteBasisEnum quoteBasis) { QuotedCurrencyPair = PropertyHelper.ExtractQuotedCurrencyPair(Properties); QuotedCurrencyPair.quoteBasis = quoteBasis; CurveName = $"{Currency.Value}-{QuoteCurrency.Value}"; UniqueIdentifier = BuildUniqueId(); Id = BuildId(); }
public static ExchangeRate Create(string currency1, string currency2, QuoteBasisEnum quoteBasis, Decimal spotRate) { var exchangeRate = new ExchangeRate { quotedCurrencyPair = QuotedCurrencyPair.Create(currency1, currency2, quoteBasis), rate = spotRate }; return(exchangeRate); }
/// <summary> /// /// </summary> /// <param name="currency1"></param> /// <param name="currency2"></param> /// <param name="quoteBasis"></param> /// <returns></returns> public static QuotedCurrencyPair Create(string currency1, string currency2, QuoteBasisEnum quoteBasis) { var quotedCurrencyPair = new QuotedCurrencyPair { currency1 = Parse(currency1), currency2 = Parse(currency2), quoteBasis = quoteBasis }; return(quotedCurrencyPair); }
public static ExchangeRate Create(string currency1, string currency2, QuoteBasisEnum quoteBasis, Decimal spotRate, Decimal forwardRate, Decimal?forwardPoints) { var exchangeRate = new ExchangeRate { quotedCurrencyPair = QuotedCurrencyPair.Create(currency1, currency2, quoteBasis), rate = forwardRate, spotRate = spotRate }; if (forwardPoints != null) { exchangeRate.forwardPointsField = (decimal)forwardPoints; } return(exchangeRate); }
/// <summary> /// A helper to extract properties from a named value set. /// </summary> /// <param name="properties">The collection of properties.</param> public static QuotedCurrencyPair ExtractQuotedCurrencyPair(NamedValueSet properties) { string currency = ExtractCurrency(properties); string quoteCurrency = ExtractCurrency2(properties); if (string.IsNullOrEmpty(currency) || string.IsNullOrEmpty(quoteCurrency)) { string currencyPair = properties.GetString(CurveProp.CurrencyPair, false); if (!string.IsNullOrEmpty(currencyPair)) { if (!GetCurrencyPair(currencyPair, out currency, out quoteCurrency)) { throw new ArgumentException("Currency pair is invalid, it should be of the type XXX-YYY"); } } else { currencyPair = properties.GetString("CurveName", false); if (!string.IsNullOrEmpty(currencyPair)) { if (!GetCurrencyPair(currencyPair, out currency, out quoteCurrency)) { throw new ArgumentException("CurveName is invalid, it should be of the type XXX-YYY"); } } else { string id = properties.GetString("Identifier", false); if (!string.IsNullOrEmpty(currencyPair) && id.Split('.').Length < 2) { currencyPair = id.Split('.').Last(); if (!GetCurrencyPair(currencyPair, out currency, out quoteCurrency)) { throw new ArgumentException("Identifier is invalid, it should be of the type XXX-YYY"); } } else { throw new ArgumentException("Mandatory field CurrencyPair or QuoteCurrency, not set."); } } } } QuoteBasisEnum quoteBasis = ExtractQuoteBasis(properties); return(QuotedCurrencyPair.Create(currency, quoteCurrency, quoteBasis)); }
/// <summary> /// Builds and fx trade from the current class. /// </summary> /// <param name="hasExpired"></param> /// <returns></returns> public FxLeg CreateFxLeg(bool hasExpired) { QuoteBasisEnum quoteBasis = fxStrikePrice.strikeQuoteBasis == StrikeQuoteBasisEnum.CallCurrencyPerPutCurrency ? QuoteBasisEnum.Currency2PerCurrency1 : QuoteBasisEnum.Currency1PerCurrency2; ExchangeRate exchangeRate = hasExpired ? ExchangeRate.Create(putCurrencyAmount.currency.Value, putCurrencyAmount.currency.Value, quoteBasis, fxStrikePrice.rate) : ExchangeRate.Create(putCurrencyAmount.currency.Value, putCurrencyAmount.currency.Value, quoteBasis, fxStrikePrice.rate, fxStrikePrice.rate, null); var fxforward = new FxLeg { //exchangedCurrency1 = // PaymentHelper.Create(this.putCurrencyPayPartyReference, callCurrencyPayPartyReference, // putCurrency, putCurrencyAmount), //exchangedCurrency2 = // PaymentHelper.Create(callCurrencyPayPartyReference, putCurrencyPayPartyReference, // callCurrency, callCurrencyAmount), Items = new[] { valueDate }, exchangeRate = exchangeRate, ItemsElementName = new[] { ItemsChoiceType15.valueDate } }; return(fxforward); }
/// <summary> /// /// </summary> /// <param name="hasExpired"></param> /// <param name="putCurrencyPayPartyReference"></param> /// <param name="callCurrencyPayPartyReference"></param> /// <param name="putCurrencyAmount"></param> /// <param name="putCurrency"></param> /// <param name="callCurrencyAmount"></param> /// <param name="callCurrency"></param> /// <param name="strikeQuoteBasis"></param> /// <param name="valueDate"></param> /// <param name="fxRate"></param> /// <returns></returns> public static FxLeg CreateFxLeg(bool hasExpired, string putCurrencyPayPartyReference, string callCurrencyPayPartyReference, decimal putCurrencyAmount, string putCurrency, decimal callCurrencyAmount, string callCurrency, StrikeQuoteBasisEnum strikeQuoteBasis, DateTime valueDate, Decimal fxRate) { QuoteBasisEnum quoteBasis = strikeQuoteBasis == StrikeQuoteBasisEnum.CallCurrencyPerPutCurrency ? QuoteBasisEnum.Currency2PerCurrency1 : QuoteBasisEnum.Currency1PerCurrency2; ExchangeRate exchangeRate = hasExpired ? ExchangeRate.Create(putCurrency, callCurrency, quoteBasis, fxRate) : ExchangeRate.Create(putCurrency, callCurrency, quoteBasis, fxRate, fxRate, null); var fxforward = new FxLeg { exchangedCurrency1 = PaymentHelper.Create(putCurrencyPayPartyReference, callCurrencyPayPartyReference, putCurrency, putCurrencyAmount), exchangedCurrency2 = PaymentHelper.Create(callCurrencyPayPartyReference, putCurrencyPayPartyReference, callCurrency, callCurrencyAmount), Items = new[] { valueDate }, exchangeRate = exchangeRate, ItemsElementName = new[] { ItemsChoiceType15.valueDate } }; return(fxforward); }
/// <summary> /// Builds an fx trade from the current vanilla fx option class. /// </summary> /// <param name="hasExpired"></param> /// <returns></returns> public FxSingleLeg CreateFxSingleLeg(bool hasExpired) { QuoteBasisEnum quoteBasis = strike.strikeQuoteBasis == StrikeQuoteBasisEnum.CallCurrencyPerPutCurrency ? QuoteBasisEnum.Currency2PerCurrency1 : QuoteBasisEnum.Currency1PerCurrency2; ExchangeRate exchangeRate = hasExpired ? ExchangeRate.Create(putCurrencyAmount.currency.Value, putCurrencyAmount.currency.Value, quoteBasis, strike.rate) : ExchangeRate.Create(putCurrencyAmount.currency.Value, putCurrencyAmount.currency.Value, quoteBasis, strike.rate, strike.rate, null); var fxForward = new FxSingleLeg { //exchangedCurrency1 = // PaymentHelper.Create(this.putCurrencyPayPartyReference, callCurrencyPayPartyReference, // putCurrency, putCurrencyAmount), //exchangedCurrency2 = // PaymentHelper.Create(callCurrencyPayPartyReference, putCurrencyPayPartyReference, // callCurrency, callCurrencyAmount), exchangeRate = exchangeRate, ItemsElementName = new[] { ItemsChoiceType31.valueDate } }; if (Item is FxEuropeanExercise exercise && exercise.expiryDateSpecified) { fxForward.Items = new[] { exercise.expiryDate }; } return(fxForward); }
public static Trade CreateFxLeg(string tradeId, DateTime tradeDate, string exchangeCurrency1PayPartyReference, string exchangeCurrency2PayPartyReference, decimal exchangeCurrency1Amount, string exchangeCurrency1, string exchangeCurrency2, QuoteBasisEnum quoteBasis, DateTime valueDate, Decimal spotRate, Decimal?forwardRate, Decimal?forwardPoints) { var trade = new Trade { id = tradeId, tradeHeader = new TradeHeader() }; var party1 = PartyTradeIdentifierHelper.Parse(tradeId, "party1"); var party2 = PartyTradeIdentifierHelper.Parse(tradeId, "party2"); trade.tradeHeader.partyTradeIdentifier = new[] { party1, party2 }; trade.tradeHeader.tradeDate = new IdentifiedDate { Value = tradeDate }; FxSingleLeg fxLeg; if (forwardRate == null) { fxLeg = ParseSpot(exchangeCurrency1PayPartyReference, exchangeCurrency2PayPartyReference, exchangeCurrency1Amount, exchangeCurrency1, exchangeCurrency2, quoteBasis, valueDate, spotRate); } else { fxLeg = ParseForward(exchangeCurrency1PayPartyReference, exchangeCurrency2PayPartyReference, exchangeCurrency1Amount, exchangeCurrency1, exchangeCurrency2, quoteBasis, valueDate, spotRate, (decimal)forwardRate, forwardPoints); } FpMLFieldResolver.TradeSetFxLeg(trade, fxLeg); return(trade); }
/// <summary> /// Build the fx leg /// </summary> /// <param name="exchangeCurrency1PayPartyReference"></param> /// <param name="exchangeCurrency2PayPartyReference"></param> /// <param name="exchangeCurrency1Amount"></param> /// <param name="exchangeCurrency1"></param> /// <param name="exchangeCurrency2"></param> /// <param name="quoteBasis"></param> /// <param name="valueDate"></param> /// <param name="spotRate"></param> /// <returns></returns> public static FxSingleLeg ParseSpot(string exchangeCurrency1PayPartyReference, string exchangeCurrency2PayPartyReference, decimal exchangeCurrency1Amount, string exchangeCurrency1, string exchangeCurrency2, QuoteBasisEnum quoteBasis, DateTime valueDate, Decimal spotRate) { var fxLeg = FxSingleLeg.CreateSpot(exchangeCurrency1PayPartyReference, exchangeCurrency2PayPartyReference, exchangeCurrency1Amount, exchangeCurrency1, exchangeCurrency2, quoteBasis, valueDate, spotRate); return(fxLeg); }
public static Trade CreateFxSwap(string tradeId, DateTime tradeDate, string exchangeCurrency1PayPartyReference, string exchangeCurrency2PayPartyReference, decimal exchangeCurrency1Amount, string exchangeCurrency1, string exchangeCurrency2, QuoteBasisEnum quoteBasis, DateTime valueDate, Decimal spotRate, Decimal?forwardRate, Decimal?forwardPoints) { var trade = new Trade { id = tradeId, tradeHeader = new TradeHeader() }; var party1 = PartyTradeIdentifierHelper.Parse(tradeId, "party1"); var party2 = PartyTradeIdentifierHelper.Parse(tradeId, "party2"); trade.tradeHeader.partyTradeIdentifier = new[] { party1, party2 }; trade.tradeHeader.tradeDate = new IdentifiedDate { Value = tradeDate }; var nearLeg = new FxSwapLeg(); var farLeg = new FxSwapLeg(); if (forwardRate == null) { nearLeg = ParseSpot(exchangeCurrency1PayPartyReference, exchangeCurrency2PayPartyReference, exchangeCurrency1Amount, exchangeCurrency1, exchangeCurrency2, quoteBasis, valueDate, spotRate); } else { farLeg = PriceableFxSwapLeg.ParseForward(exchangeCurrency1PayPartyReference, exchangeCurrency2PayPartyReference, exchangeCurrency1Amount, exchangeCurrency1, exchangeCurrency2, quoteBasis, valueDate, spotRate, (decimal)forwardRate, forwardPoints); } var fxSwap = new FxSwap { nearLeg = nearLeg, farLeg = farLeg, Items = new object[] { ProductTypeHelper.Create(ProductTypeSimpleEnum.FxSwap.ToString()) }, ItemsElementName = new[] { ItemsChoiceType2.productType } }; FpMLFieldResolver.TradeSetFxSwap(trade, fxSwap); return(trade); }
public static Trade CreateFxSwap(string tradeId, DateTime tradeDate, string exchangeCurrency1PayPartyReference, string exchangeCurrency2PayPartyReference, decimal exchangeCurrency1Amount, string exchangeCurrency1, string exchangeCurrency2, QuoteBasisEnum quoteBasis, DateTime startValueDate, DateTime forwardValueDate, Decimal startRate, Decimal forwardRate, Decimal?forwardPoints) { var trade = new Trade { id = tradeId, tradeHeader = new TradeHeader() }; var party1 = PartyTradeIdentifierHelper.Parse(tradeId, "party1"); var party2 = PartyTradeIdentifierHelper.Parse(tradeId, "party2"); trade.tradeHeader.partyTradeIdentifier = new[] { party1, party2 }; trade.tradeHeader.tradeDate = new IdentifiedDate { Value = tradeDate }; var fxSwap = Parse(exchangeCurrency1PayPartyReference, exchangeCurrency2PayPartyReference, exchangeCurrency1Amount, exchangeCurrency1, exchangeCurrency2, quoteBasis, startValueDate, forwardValueDate, startRate, forwardRate, forwardPoints); FpMLFieldResolver.TradeSetFxSwap(trade, fxSwap); return(trade); }
/// <summary> /// Builds a fx swap. /// </summary> /// <returns></returns> public static FxSwap Parse(string exchangeCurrency1PayPartyReference, string exchangeCurrency2PayPartyReference, decimal exchangeCurrency1Amount, string exchangeCurrency1, string exchangeCurrency2, QuoteBasisEnum quoteBasis, DateTime startValueDate, DateTime forwardValueDate, Decimal startRate, Decimal forwardRate, Decimal?forwardPoints) { var fxSwap = new FxSwap { Items = new object[] { ProductTypeHelper.Create(ProductTypeSimpleEnum.FxSwap.ToString()) }, ItemsElementName = new[] { ItemsChoiceType2.productType } }; var leg1 = ParseSpot(exchangeCurrency1PayPartyReference, exchangeCurrency2PayPartyReference, exchangeCurrency1Amount, exchangeCurrency1, exchangeCurrency2, quoteBasis, startValueDate, startRate); var leg2 = PriceableFxSwapLeg.ParseForward(exchangeCurrency2PayPartyReference, exchangeCurrency1PayPartyReference, exchangeCurrency1Amount, exchangeCurrency1, exchangeCurrency2, quoteBasis, forwardValueDate, forwardRate, forwardRate, forwardPoints); fxSwap.nearLeg = leg1; fxSwap.farLeg = leg2; return(fxSwap); }
/// <summary> /// Build the fx leg. /// </summary> /// <param name="exchangeCurrency1PayPartyReference"></param> /// <param name="exchangeCurrency2PayPartyReference"></param> /// <param name="exchangeCurrency1Amount"></param> /// <param name="exchangeCurrency1"></param> /// <param name="exchangeCurrency2"></param> /// <param name="quoteBasis"></param> /// <param name="valueDate"></param> /// <param name="spotRate"></param> /// <param name="forwardRate"></param> /// <param name="forwardPoints"></param> /// <returns></returns> public static FxSwapLeg ParseForward(string exchangeCurrency1PayPartyReference, string exchangeCurrency2PayPartyReference, decimal exchangeCurrency1Amount, string exchangeCurrency1, string exchangeCurrency2, QuoteBasisEnum quoteBasis, DateTime valueDate, Decimal spotRate, Decimal forwardRate, Decimal?forwardPoints) { var fxLeg = FxSwapLeg.CreateForward(exchangeCurrency1PayPartyReference, exchangeCurrency2PayPartyReference, exchangeCurrency1Amount, exchangeCurrency1, exchangeCurrency2, quoteBasis, valueDate, spotRate, forwardRate, forwardPoints); return(fxLeg); }
/// <summary> /// The FxCurveIdentifier. /// </summary> /// <param name="pricingStructureType"></param> /// <param name="curveName"></param> /// <param name="quoteBasis"></param> /// <param name="buildDateTime"></param> public FxCurveIdentifier(PricingStructureTypeEnum pricingStructureType, string curveName, QuoteBasisEnum quoteBasis, DateTime buildDateTime) : base(pricingStructureType, curveName, buildDateTime) { SetProperties(quoteBasis); }
/// <summary> /// /// </summary> /// <param name="exchangeCurrency1PayPartyReference"></param> /// <param name="exchangeCurrency2PayPartyReference"></param> /// <param name="exchangeCurrency1Amount"></param> /// <param name="exchangeCurrency1"></param> /// <param name="exchangeCurrency2"></param> /// <param name="quoteBasis"></param> /// <param name="valueDate"></param> /// <param name="spotRate"></param> /// <param name="forwardRate"></param> /// <param name="forwardPoints"></param> /// <returns></returns> public static FxSwapLeg CreateForward(string exchangeCurrency1PayPartyReference, string exchangeCurrency2PayPartyReference, decimal exchangeCurrency1Amount, string exchangeCurrency1, string exchangeCurrency2, QuoteBasisEnum quoteBasis, DateTime valueDate, Decimal spotRate, Decimal forwardRate, Decimal?forwardPoints) { decimal exchange2Amount; if (quoteBasis == QuoteBasisEnum.Currency2PerCurrency1) { exchange2Amount = exchangeCurrency1Amount * forwardRate; } else { exchange2Amount = exchangeCurrency1Amount / forwardRate; } var fxForward = new FxSwapLeg { exchangedCurrency1 = PaymentHelper.Create(exchangeCurrency1PayPartyReference, exchangeCurrency2PayPartyReference, exchangeCurrency1, exchangeCurrency1Amount), exchangedCurrency2 = PaymentHelper.Create(exchangeCurrency2PayPartyReference, exchangeCurrency1PayPartyReference, exchangeCurrency2, exchange2Amount), Items = new[] { valueDate }, exchangeRate = ExchangeRate.Create(exchangeCurrency1, exchangeCurrency2, quoteBasis, spotRate, forwardRate, forwardPoints), ItemsElementName = new[] { ItemsChoiceType9.valueDate } }; return(fxForward); }
public static FxSingleLeg CreateSpot(string exchangeCurrency1PayPartyReference, string exchangeCurrency2PayPartyReference, decimal exchangeCurrency1Amount, string exchangeCurrency1, string exchangeCurrency2, QuoteBasisEnum quoteBasis, DateTime valueDate, Decimal spotRate) { decimal exchange2Amount; if (quoteBasis == QuoteBasisEnum.Currency2PerCurrency1) { exchange2Amount = exchangeCurrency1Amount * spotRate; } else { exchange2Amount = exchangeCurrency1Amount / spotRate; } var fxforward = new FxSingleLeg { exchangedCurrency1 = PaymentHelper.Create(exchangeCurrency1PayPartyReference, exchangeCurrency2PayPartyReference, exchangeCurrency1, exchangeCurrency1Amount), exchangedCurrency2 = PaymentHelper.Create(exchangeCurrency2PayPartyReference, exchangeCurrency1PayPartyReference, exchangeCurrency2, exchange2Amount), Items1 = new[] { valueDate }, exchangeRate = ExchangeRate.Create(exchangeCurrency1, exchangeCurrency2, quoteBasis, spotRate), Items1ElementName = new[] { Items1ChoiceType.valueDate } }; return(fxforward); }
public QuotedCurrencyPair(XmlNode xmlNode) { XmlNodeList currency1NodeList = xmlNode.SelectNodes("currency1"); if (currency1NodeList.Count > 1 ) { throw new Exception(); } foreach (XmlNode item in currency1NodeList) { if (item.Attributes["href"] != null || item.Attributes["id"] == null) { if (item.Attributes["id"] != null) { currency1IDRef = item.Attributes["id"].Name; Currency ob = Currency(); IDManager.SetID(currency1IDRef, ob); } else if (item.Attributes.ToString() == "href") { currency1IDRef = item.Attributes["href"].Name; } else { currency1 = new Currency(item); } } } XmlNodeList currency2NodeList = xmlNode.SelectNodes("currency2"); if (currency2NodeList.Count > 1 ) { throw new Exception(); } foreach (XmlNode item in currency2NodeList) { if (item.Attributes["href"] != null || item.Attributes["id"] == null) { if (item.Attributes["id"] != null) { currency2IDRef = item.Attributes["id"].Name; Currency ob = Currency(); IDManager.SetID(currency2IDRef, ob); } else if (item.Attributes.ToString() == "href") { currency2IDRef = item.Attributes["href"].Name; } else { currency2 = new Currency(item); } } } XmlNodeList quoteBasisNodeList = xmlNode.SelectNodes("quoteBasis"); if (quoteBasisNodeList.Count > 1 ) { throw new Exception(); } foreach (XmlNode item in quoteBasisNodeList) { if (item.Attributes["href"] != null || item.Attributes["id"] == null) { if (item.Attributes["id"] != null) { quoteBasisIDRef = item.Attributes["id"].Name; QuoteBasisEnum ob = QuoteBasisEnum(); IDManager.SetID(quoteBasisIDRef, ob); } else if (item.Attributes.ToString() == "href") { quoteBasisIDRef = item.Attributes["href"].Name; } else { quoteBasis = new QuoteBasisEnum(item); } } } }