/// <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 FxSwapLeg ParseSpot(string exchangeCurrency1PayPartyReference, string exchangeCurrency2PayPartyReference, decimal exchangeCurrency1Amount, string exchangeCurrency1, string exchangeCurrency2, QuoteBasisEnum quoteBasis, DateTime valueDate, Decimal spotRate) { var fxLeg = FxSwapLeg.CreateSpot(exchangeCurrency1PayPartyReference, exchangeCurrency2PayPartyReference, exchangeCurrency1Amount, exchangeCurrency1, exchangeCurrency2, quoteBasis, valueDate, spotRate); return(fxLeg); }
/// <summary> /// Builds this instance. /// </summary> /// <returns></returns> public FxSwapLeg Build()//TODO implement this. { var fxLeg = new FxSwapLeg { exchangedCurrency1 = Payments[0].Build(), exchangedCurrency2 = Payments[1].Build(), exchangeRate = ExchangeRate, id = Id, Items = new[] { RiskMaturityDate }, ItemsElementName = new[] { ItemsChoiceType12.valueDate } }; return(fxLeg); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableFxSwapLeg"/> class. All the cashfloews must be signed. /// </summary> /// <param name="fxLeg">The fxLeg.</param> /// <param name="baseParty">The the base party.</param> /// <param name="productType">THe product type: This should only be FxSpot or FxForward.</param> public PriceableFxSwapLeg(FxSwapLeg fxLeg, string baseParty, ProductTypeSimpleEnum productType) { Multiplier = 1.0m; OrderedPartyNames = new List <string>(); Id = fxLeg.id; AnalyticsModel = new FxLegAnalytic(); ProductType = productType; ExchangeRate = fxLeg.exchangeRate; HybridValuation = true; //Get the currency. PaymentCurrencies = new List <string>(); Currency1 = fxLeg.exchangedCurrency1.paymentAmount.currency; Currency2 = fxLeg.exchangedCurrency2.paymentAmount.currency; if (!PaymentCurrencies.Contains(Currency1.Value)) { PaymentCurrencies.Add(Currency1.Value); } if (!PaymentCurrencies.Contains(Currency2.Value)) { PaymentCurrencies.Add(Currency2.Value); } //Set the default discount curve name. Currency1DiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Currency1.Value, true); //Set the default discount curve name. Currency2DiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Currency2.Value, true); //TODO //Set the appropraiet cross //if the quotebasis is : Currency1PerCurrency2 the currency curve is: currency1-currency2 if (ExchangeRate.quotedCurrencyPair.quoteBasis == QuoteBasisEnum.Currency2PerCurrency1) { FxIndexCurveName = MarketEnvironmentHelper.ResolveFxCurveNames(Currency1.Value, Currency2.Value); } //Otherwise it is Currency2-Currency1 else { FxIndexCurveName = MarketEnvironmentHelper.ResolveFxCurveNames(Currency2.Value, Currency1.Value); } if (fxLeg.nonDeliverableSettlement != null)//TODO Not implemented yet. { IsNonDeliverableForward = true; SettlementCurrency = fxLeg.nonDeliverableSettlement.settlementCurrency; SettlementCurrencyDiscountCurveName = CurveNameHelpers.GetDiscountCurveName(SettlementCurrency.Value, true); } //Build the coupons and principal exchanges. Payments = PriceableInstrumentsFactory.CreatePriceableFxLegPayment(baseParty, fxLeg); //TODO: add extra cashflowss. RiskMaturityDate = fxLeg.ItemsElementName[0] == ItemsChoiceType12.valueDate ? fxLeg.Items[0] : LastDate(); }
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); }
/// <summary> /// /// </summary> /// <param name="baseParty"></param> /// <param name="fxLeg"></param> /// <returns></returns> public static IList <PriceablePayment> CreatePriceableFxLegPayment(string baseParty, FxSwapLeg fxLeg)//TODO Fix this. { string id1 = fxLeg.exchangedCurrency1.id ?? "Payment_" + fxLeg.exchangedCurrency1.paymentAmount.currency.Value; string id2 = fxLeg.exchangedCurrency2.id ?? "Payment_" + fxLeg.exchangedCurrency2.paymentAmount.currency.Value; var priceablePayments = new List <PriceablePayment>(); bool payerIsBase = false; //payment1 var paymentAmount1 = fxLeg.exchangedCurrency1.paymentAmount.amount; if (baseParty == fxLeg.exchangedCurrency1.payerPartyReference.href) { paymentAmount1 *= -1; // *fxLeg.exchangedCurrency1.paymentAmount.amount; payerIsBase = true; } var paymentDate = fxLeg.Items[0]; var currency1 = fxLeg.exchangedCurrency1.paymentAmount.currency.Value; priceablePayments.Add(new PriceablePayment(id1, fxLeg.exchangedCurrency1.payerPartyReference.href, fxLeg.exchangedCurrency2.payerPartyReference.href, payerIsBase, paymentAmount1, currency1, paymentDate, null)); //payment2 var paymentAmount2 = fxLeg.exchangedCurrency2.paymentAmount.amount; if (baseParty == fxLeg.exchangedCurrency2.payerPartyReference.href) { paymentAmount2 *= -1; // *fxLeg.exchangedCurrency2.paymentAmount.amount; payerIsBase = true; } var currency2 = fxLeg.exchangedCurrency2.paymentAmount.currency.Value; priceablePayments.Add(new PriceablePayment(id2, fxLeg.exchangedCurrency1.payerPartyReference.href, fxLeg.exchangedCurrency2.payerPartyReference.href, payerIsBase, paymentAmount2, currency2, paymentDate, null)); return(priceablePayments); }