internal static void AddOtherPartyPayments(ValuationReport valuationReport, List <OtherPartyPaymentRangeItem> otherPartyPaymentList) { var otherPartyPayments = new List <Payment>(); // other party payments // if (null != otherPartyPaymentList) { foreach (OtherPartyPaymentRangeItem item in otherPartyPaymentList) { var otherPartyPayment = new Payment { payerPartyReference = PartyReferenceFactory.Create(item.Payer), receiverPartyReference = PartyReferenceFactory.Create(item.Receiver), paymentAmount = MoneyHelper.GetNonNegativeAmount(item.Amount), paymentDate = AdjustableOrAdjustedDateHelper.CreateAdjustedDate(item.PaymentDate), paymentType = PaymentTypeHelper.Create(item.PaymentType) }; otherPartyPayments.Add(otherPartyPayment); } } TradeValuationItem valuationItem = valuationReport.tradeValuationItem[0]; Trade[] tradeArray = XsdClassesFieldResolver.TradeValuationItemGetTradeArray(valuationItem); Trade trade = tradeArray[0]; trade.otherPartyPayment = otherPartyPayments.ToArray(); }
//public static object[,] DoReport(BulletPayment bulletPayment) //{ // if (bulletPayment != null) // { // var result = new object[7, 2]; // result[0, 0] = "adjustedPaymentDate"; // result[1, 0] = "paymentAmount"; // result[2, 0] = "currency"; // result[3, 0] = "paymentType"; // result[4, 0] = "lenderPartyReference"; // result[5, 0] = "borrowerPartyReference"; // result[6, 0] = "currency"; // result[0, 1] = bulletPayment.payment.adjustedPaymentDate; // result[1, 1] = bulletPayment.payment.paymentAmount.amount; // result[2, 1] = bulletPayment.payment.paymentAmount.currency.Value; // result[3, 1] = bulletPayment.payment.paymentType.Value; // result[4, 1] = bulletPayment.payment.payerPartyReference.href; // result[5, 1] = bulletPayment.payment.receiverPartyReference.href; // result[6, 1] = bulletPayment.payment.presentValueAmount!= null ? bulletPayment.payment.presentValueAmount.amount : 0.0m; // return result; // } // return null; //} public override object[,] DoReport(Product product, NamedValueSet properties) { if (product is BulletPayment payment) { var party1 = properties.GetValue <string>(TradeProp.Party1, true); var party2 = properties.GetValue <string>(TradeProp.Party2, true); var result = new object[7, 2]; result[0, 0] = "payerPartyReference"; result[1, 0] = "receiverPartyReference"; result[2, 0] = "amount"; result[3, 0] = "currency"; result[4, 0] = "businessDayConvention"; result[5, 0] = "party1"; result[6, 0] = "party2"; var temp = payment.payment; result[0, 1] = temp.payerPartyReference.href; result[1, 1] = temp.receiverPartyReference.href; result[2, 1] = temp.paymentAmount.amount; result[3, 1] = temp.paymentAmount.currency.Value; var containsBusinessCenters = AdjustableOrAdjustedDateHelper.Contains(temp.paymentDate, ItemsChoiceType.dateAdjustments, out var businessDayAdjustments); if (containsBusinessCenters && businessDayAdjustments != null) { var businessDayConvention = ((BusinessDayAdjustments)businessDayAdjustments).businessDayConvention.ToString(); result[4, 1] = businessDayConvention; } else { result[4, 1] = "NONE"; } result[5, 1] = party1; result[6, 1] = party2; return(result); } return(null); }
/// <summary> /// Derives the adjusted date if not already provided. /// </summary> /// <param name="adjustableOrAdjustedDate">this may contain the adjustedDate, an unadjusted Date and business Centre</param> /// <param name="businessCalendar">THe business calendar must be provided, no namespace is required and can be null</param> /// <returns></returns> public static DateTime?GetAdjustedDate(IBusinessCalendar businessCalendar, AdjustableOrAdjustedDate adjustableOrAdjustedDate) { var result = AdjustableOrAdjustedDateHelper.Contains(adjustableOrAdjustedDate, ItemsChoiceType.adjustedDate, out var date); if (result) { return(((IdentifiedDate)date).Value); } result = AdjustableOrAdjustedDateHelper.Contains(adjustableOrAdjustedDate, ItemsChoiceType.unadjustedDate, out date); var bda = AdjustableOrAdjustedDateHelper.Contains(adjustableOrAdjustedDate, ItemsChoiceType.dateAdjustments, out var businessDayAdjustments); if (result && date != null) { DateTime unadjustedDate = ((IdentifiedDate)date).Value; if (bda && businessCalendar != null) { if (businessDayAdjustments is BusinessDayAdjustments adjustments) { return(businessCalendar.Roll(unadjustedDate, adjustments.businessDayConvention)); } } return(unadjustedDate); } return(null); }
//public static object[,] DoReport(TermDeposit termDeposit) //{ // if (termDeposit != null) // { // var result = new object[10, 2]; // result[0, 0] = "adjustedEffectiveDate"; // result[1, 0] = "fixedRate"; // result[2, 0] = "maturityDate"; // result[3, 0] = "dayCountFraction"; // result[4, 0] = "lenderPartyReference"; // result[5, 0] = "borrowerPartyReference"; // result[6, 0] = "currency"; // result[7, 0] = "notionalamount"; // result[8, 0] = "interest"; // result[9, 0] = "dayCount"; // result[0, 1] = termDeposit.startDate; // result[1, 1] = termDeposit.fixedRate; // result[2, 1] = termDeposit.maturityDate; // result[3, 1] = termDeposit.dayCountFraction.Value; // result[4, 1] = termDeposit.initialPayerReference.href; // result[5, 1] = termDeposit.initialReceiverReference.href; // result[6, 1] = termDeposit.principal.currency.Value; // result[7, 1] = termDeposit.principal.amount; // result[8, 1] = termDeposit.interest.amount; // result[9, 1] = termDeposit.dayCountFraction.Value; // return result; // } // return null; //} public override object[,] DoReport(Product product, NamedValueSet properties) { if (product is FxSwap fxswap) { var party1 = properties.GetValue <string>(TradeProp.Party1, true); var party2 = properties.GetValue <string>(TradeProp.Party2, true); var result = new object[7, 2]; result[0, 0] = "payerPartyReference"; result[1, 0] = "receiverPartyReference"; result[2, 0] = "amount"; result[3, 0] = "currency"; result[4, 0] = "paymentDate"; result[5, 0] = "party1"; result[6, 0] = "party2"; var temp1 = fxswap.nearLeg; result[0, 1] = temp1.exchangedCurrency1.payerPartyReference.href; result[1, 1] = temp1.exchangedCurrency1.receiverPartyReference.href; result[2, 1] = temp1.exchangedCurrency1.paymentAmount.amount; result[3, 1] = temp1.exchangedCurrency1.paymentAmount.currency.Value; var containdUnadjustedDate = AdjustableOrAdjustedDateHelper.Contains(temp1.exchangedCurrency1.paymentDate, ItemsChoiceType.unadjustedDate, out var unadjustedDate); if (containdUnadjustedDate) { result[4, 1] = ((IdentifiedDate)unadjustedDate).Value; } result[5, 1] = party1; result[6, 1] = party2; return(result); } return(null); }
/// <summary> /// /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="baseParty">THe base party is either Party1 or Party2</param> /// <param name="depositFpML">THe FpML representation of the deposit correctly built.</param> public TermDepositPricer(ILogger logger, ICoreCache cache, TermDeposit depositFpML, string baseParty) { Multiplier = 1.0m; OrderedPartyNames = new List <string>(); FixedRate = depositFpML.fixedRate; EffectiveDate = depositFpML.startDate; TerminationDate = depositFpML.maturityDate; DayCountFraction = new DayCountFraction { Value = depositFpML.dayCountFraction.Value }; BasePartyPayingFixed = !IsBasePartyLender(baseParty, depositFpML); if (BasePartyPayingFixed)//From the viewpoint of the counterparty! { BaseParty = depositFpML.receiverPartyReference.href; CounterParty = depositFpML.payerPartyReference.href; } else { BaseParty = depositFpML.payerPartyReference.href; CounterParty = depositFpML.receiverPartyReference.href; } PaymentDate = TerminationDate; RiskMaturityDate = TerminationDate; Principal = MoneyHelper.GetMoney(depositFpML.principal); Payments = new List <PriceablePayment>(); if (depositFpML.payment != null && depositFpML.payment.Length == 3) { //Modify to be principal and interest. //A principal payment ->priceable payment //An interest payment -> priceable fixed coupon var initialDate = AdjustableOrAdjustedDateHelper.Create(null, EffectiveDate, null); var maturityDate = AdjustableOrAdjustedDateHelper.Create(null, PaymentDate, null); depositFpML.payment[0].paymentDate = initialDate; depositFpML.payment[1].paymentDate = maturityDate; depositFpML.payment[2].paymentDate = maturityDate;//Remove this and replace with depositFpML.interest Payments.AddRange(PriceableInstrumentsFactory.CreatePriceablePayments(BaseParty, depositFpML.payment, null)); AddCashFlow(depositFpML, BasePartyPayingFixed); } else//This will change the input FpML as well! { var initial = PaymentHelper.Create(depositFpML.payerPartyReference.href, depositFpML.receiverPartyReference.href, Principal.currency.Value, Principal.amount, EffectiveDate); Payments.Add(PriceableInstrumentsFactory.CreatePriceablePayment(BaseParty, initial, null)); var final = PaymentHelper.Create(depositFpML.receiverPartyReference.href, depositFpML.payerPartyReference.href, depositFpML.principal.currency.Value, Principal.amount, TerminationDate); Payments.Add(PriceableInstrumentsFactory.CreatePriceablePayment(BaseParty, final, null)); //Payments.Add(PaymentHelper.Create("interest payment"); AddCashFlow(depositFpML, !BasePartyPayingFixed); } //Set the product type. ProductType = ProductTypeSimpleEnum.TermDeposit; Currency = depositFpML.principal.currency; PaymentCurrencies = new List <string> { Currency.Value }; //Set the default discount curve name. DiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Currency.Value, true); }
/// <summary> /// Builds this instance. /// </summary> /// <returns></returns> public BulletPayment Build() { var px = new BulletPayment { payment = new Payment { paymentAmount = MoneyHelper.GetNonNegativeAmount(PaymentAmount.amount, PaymentAmount.currency.Value) }, Items = new object[] { ProductTypeHelper.Create(ProductTypeSimpleEnum.BulletPayment.ToString()) }, ItemsElementName = new[] { ItemsChoiceType2.productType } }; //Setting the items array which contains product type and product is information. //payment type information px.payment.paymentType = PaymentTypeHelper.Create("Payment"); //Set the party information px.payment.payerPartyReference = new PartyReference { href = "Party2" }; px.payment.receiverPartyReference = new PartyReference { href = "Party1" }; if (PayerIsBaseParty) { px.payment.payerPartyReference = new PartyReference { href = "Party1" }; px.payment.receiverPartyReference = new PartyReference { href = "Party2" }; } //The payment date px.payment.paymentDate = AdjustableOrAdjustedDateHelper.Create(null, PaymentDate, PaymentDateAdjustments); if (CalculationPerformedIndicator) { px.payment.discountFactor = PaymentDiscountFactor; px.payment.discountFactorSpecified = true; px.payment.presentValueAmount = MoneyHelper.GetAmount(CalculationResults.NPV, PaymentAmount.currency.Value); } return(px); }
public static void UpdatePaymentsAmounts(ILogger logger, ICoreCache cache, String nameSpace, Swap swap, SwapLegParametersRange leg1Parameters, SwapLegParametersRange leg2Parameters, IRateCurve leg1DiscountCurve, IRateCurve leg2DiscountCurve, DateTime valuationDate, IBusinessCalendar paymentCalendar) { foreach (Payment payment in swap.additionalPayment) { // choose correct discount curve // IRateCurve discountCurve; if (payment.payerPartyReference.href == leg1Parameters.Payer) { discountCurve = leg1DiscountCurve; } else if (payment.payerPartyReference.href == leg2Parameters.Payer) { discountCurve = leg2DiscountCurve; } else { throw new NotImplementedException(); } if (paymentCalendar == null) { var containsPaymentDateAdjustments = AdjustableOrAdjustedDateHelper.Contains(payment.paymentDate, ItemsChoiceType.dateAdjustments, out var dateAdjustments); if (containsPaymentDateAdjustments && dateAdjustments != null) { paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, ((BusinessDayAdjustments)dateAdjustments). businessCenters, nameSpace); } } var date = AdjustedDateHelper.GetAdjustedDate(paymentCalendar, payment.paymentDate); if (date == null) { continue; } payment.discountFactor = (decimal)discountCurve.GetDiscountFactor(valuationDate, (DateTime)date); payment.discountFactorSpecified = true; payment.presentValueAmount = MoneyHelper.Mul(payment.paymentAmount, payment.discountFactor); } }
/// <summary> /// Initializes a new instance of the <see cref="PriceablePayment"/> class. /// </summary> /// <param name="id">The identifier.</param> /// <param name="receiverPartyReference">The receiver.</param> /// <param name="payerIsBase">The flag determining if the payer is the base party.</param> /// <param name="amount">The amount.</param> /// <param name="currency">The currency.</param> /// <param name="adjustedPaymentDate">The adjusted payment date.</param> /// <param name="payerPartyReference">The payer.</param> /// <param name="paymentCalendar">Type paymentCalendar.</param> public PriceablePayment ( string id , string payerPartyReference , string receiverPartyReference , bool payerIsBase , Decimal amount , string currency , DateTime adjustedPaymentDate , IBusinessCalendar paymentCalendar) : base(id, "DiscountedCashflow", payerIsBase, MoneyHelper.GetAmount(amount, currency), AdjustableOrAdjustedDateHelper.CreateAdjustedDate(adjustedPaymentDate), PaymentTypeHelper.Create("Certain"), CashflowTypeHelper.Create(CashflowTypeEnum.PrincipalExchange.ToString()), false, paymentCalendar) { PayerPartyReference = PartyReferenceFactory.Create(payerPartyReference); ReceiverPartyReference = PartyReferenceFactory.Create(receiverPartyReference); OrderedPartyNames.Add(PayerPartyReference.href); OrderedPartyNames.Add(ReceiverPartyReference.href); }
/// <summary> /// Builds this instance. /// </summary> /// <returns></returns> public Payment Build() { var px = PaymentHelper.Create(PayerPartyReference.href, ReceiverPartyReference.href, PaymentAmount.currency.Value, Math.Abs(PaymentAmount.amount), PaymentDate); px.id = Id; //px.paymentAmount = PaymentAmount;//this is the raw amount without the multiplier effect. px.paymentDate = AdjustableOrAdjustedDateHelper.CreateAdjustedDate(AdjustedPaymentDate.Value, PaymentDateAdjustments); if (CalculationPerformedIndicator) { var payment = Math.Abs(ForecastAmount.amount); px.paymentAmount = MoneyHelper.GetNonNegativeAmount(payment, ForecastAmount.currency.Value); var npv = Math.Abs(NPV.amount); var money = MoneyHelper.GetAmount(npv, PaymentAmount.currency.Value); px.discountFactor = PaymentDiscountFactor; px.discountFactorSpecified = true; px.presentValueAmount = money; } return(px); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableCashflow"/> class. /// </summary> /// <param name="cashflowId">The identifier.</param> /// <param name="payerIsBaseParty">The is base party flag.</param> /// <param name="modelIdentifier">The _model identifier.</param> /// <param name="amount">The amount.</param> /// <param name="paymentDate">The payment date.</param> /// <param name="paymentType">Type of the payment.</param> /// <param name="cashflowType">Type of the cashflow.</param> /// <param name="includePaymentDate">if set to <c>true</c> [include payment date].</param> /// <param name="paymentCalendar">Type paymentCalendar.</param> protected PriceableCashflow ( string cashflowId , string modelIdentifier , bool payerIsBaseParty , Money amount , AdjustableOrAdjustedDate paymentDate , PaymentType paymentType , CashflowType cashflowType , bool includePaymentDate , IBusinessCalendar paymentCalendar) { Multiplier = 1.0m; var date = AdjustedDateHelper.GetAdjustedDate(paymentCalendar, paymentDate); if (date != null) { PaymentDate = (DateTime)date; } var containsPaymentDateAdjustments = AdjustableOrAdjustedDateHelper.Contains(paymentDate, ItemsChoiceType.dateAdjustments, out var dateAdjustments); if (containsPaymentDateAdjustments && dateAdjustments != null) { PaymentDateAdjustments = (BusinessDayAdjustments)dateAdjustments; } PayerIsBaseParty = payerIsBaseParty; Id = cashflowId; ModelIdentifier = modelIdentifier; PaymentType = paymentType; PaymentAmount = amount; ForecastAmount = amount; CashflowType = cashflowType; PaymentDateIncluded = includePaymentDate; PricingStructureEvolutionType = PricingStructureEvolutionType.ForwardToSpot; RiskMaturityDate = PaymentDate; DiscountCurveName = CurveNameHelpers.GetDiscountCurveName(amount.currency.Value, true); if (!PaymentCurrencies.Contains(amount.currency.Value)) { PaymentCurrencies.Add(amount.currency.Value); } }
/// <summary> /// Builds this instance and returns the underlying instrument associated with the controller /// </summary> /// <returns></returns> public TermDeposit Build() { var deposit = new TermDeposit { Items = new object[] { new ProductType { Value = ProductType.ToString() } }, ItemsElementName = new[] { ItemsChoiceType2.productType }, dayCountFraction = DayCountFraction, principal = MoneyHelper.GetPositiveMoney(Principal), maturityDate = TerminationDate, maturityDateSpecified = true, startDate = EffectiveDate, startDateSpecified = true, fixedRate = FixedRate, fixedRateSpecified = true }; if (BasePartyPayingFixed)//From the viewpoint of the counterparty! { deposit.receiverPartyReference = PartyReferenceHelper.Parse(BaseParty); deposit.payerPartyReference = PartyReferenceHelper.Parse(CounterParty); } else { deposit.payerPartyReference = PartyReferenceHelper.Parse(BaseParty); deposit.receiverPartyReference = PartyReferenceHelper.Parse(CounterParty); } //deposit payments. if (deposit.payment?.Length == 3) { var initialDate = AdjustableOrAdjustedDateHelper.Create(null, EffectiveDate, null); var maturityDate = AdjustableOrAdjustedDateHelper.Create(null, PaymentDate, null); deposit.payment[0].paymentDate = initialDate; deposit.payment[1].paymentDate = maturityDate; deposit.payment[2].paymentDate = maturityDate; } var interest = System.Math.Abs(InterestAmount.AccruedInterest); deposit.interest = MoneyHelper.GetAmount(interest, deposit.principal.currency.Value); return(deposit); }
/// <summary> /// Builds a bullet payment. /// </summary> /// <param name="productType"></param> /// <param name="payerIsBaseParty"></param> /// <param name="paymentDate"></param> /// <param name="businessDayCalendar"></param> /// <param name="businessDayAdjustments"> </param> /// <param name="currency"></param> /// <param name="amount"></param> /// <returns></returns> public static BulletPayment Parse(string productType, Boolean payerIsBaseParty, DateTime paymentDate, string businessDayCalendar, string businessDayAdjustments, string currency, decimal amount) { var px = new BulletPayment { payment = new Payment { paymentAmount = MoneyHelper.GetNonNegativeAmount(amount, currency) }, Items = new object[] { ProductTypeHelper.Create("BulletPayment") }, ItemsElementName = new[] { ItemsChoiceType2.productType } }; var tempDate = DateTypesHelper.ToAdjustableDate(paymentDate, businessDayAdjustments, businessDayCalendar); px.payment.paymentDate = AdjustableOrAdjustedDateHelper.Create(tempDate.unadjustedDate.Value, null, tempDate.dateAdjustments);//TODO //Setting the items array which contains product type and product is information. //payment type information px.payment.paymentType = PaymentTypeHelper.Create("Payment"); //Set the party information px.payment.payerPartyReference = new PartyReference { href = "Party2" }; px.payment.receiverPartyReference = new PartyReference { href = "Party1" }; if (payerIsBaseParty) { px.payment.payerPartyReference = new PartyReference { href = "Party1" }; px.payment.receiverPartyReference = new PartyReference { href = "Party2" }; } return(px); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableFxOptionPremium"/> class. /// </summary> /// <param name="id">The identifier.</param> /// <param name="receiverPartyReference">The receiver.</param> /// <param name="payerIsBase">The flag determining if the payer is the base party.</param> /// <param name="amount">The amount.</param> /// <param name="settlementDate">The adjusted payment date.</param> /// <param name="payerPartyReference">The payer.</param> /// <param name="premiumQuote">The premium quote </param> /// <param name="settlementInformation">The settlement information. </param> /// <param name="paymentCalendar">Type paymentCalendar.</param> public PriceableFxOptionPremium ( string id , string payerPartyReference , string receiverPartyReference , bool payerIsBase , Money amount , DateTime settlementDate , PremiumQuote premiumQuote , SettlementInformation settlementInformation , IBusinessCalendar paymentCalendar) : base(id, "DiscountedCashflow", payerIsBase, amount, AdjustableOrAdjustedDateHelper.CreateAdjustedDate(settlementDate), PaymentTypeHelper.Create("Certain"), CashflowTypeHelper.Create(CashflowTypeEnum.Premium.ToString()), false, paymentCalendar) { PayerPartyReference = PartyReferenceFactory.Create(payerPartyReference); ReceiverPartyReference = PartyReferenceFactory.Create(receiverPartyReference); OrderedPartyNames.Add(PayerPartyReference.href); OrderedPartyNames.Add(ReceiverPartyReference.href); if (premiumQuote != null) { PremiumQuote = new PremiumQuote { quoteBasis = premiumQuote.quoteBasis, quoteBasisSpecified = true, value = premiumQuote.value, valueSpecified = true }; } if (settlementInformation == null) { return; } SettlementInformation = new SettlementInformation(); var item = BinarySerializerHelper.Clone(settlementInformation.Item); SettlementInformation.Item = item; }
/// <summary> /// /// </summary> /// <param name="logger"></param> /// <param name="cache"></param> /// <param name="nameSpace"></param> /// <param name="legCalendars"></param> /// <param name="trade"></param> /// <param name="tradeProps"></param> /// <param name="forecastRateInterpolation"></param> public TradePricer(ILogger logger, ICoreCache cache, String nameSpace, List <Pair <IBusinessCalendar, IBusinessCalendar> > legCalendars, Trade trade, NamedValueSet tradeProps, bool forecastRateInterpolation) { if (tradeProps == null) { tradeProps = new NamedValueSet();//TODO Need to generate properties for the FpML examples. } var tradeIdentifier = new TradeIdentifier(tradeProps); TradeIdentifier = tradeIdentifier; TradeHeader = trade.tradeHeader; //Get the baseParty, which in GWML is the originating party. BaseParty = tradeProps.GetValue <string>(TradeProp.BaseParty, false) ?? TradeProp.Party1; var party1 = tradeProps.GetValue <string>(TradeProp.Party1, true); var party2 = tradeProps.GetValue <string>(TradeProp.Party2, true); Parties = new List <Party> { new Party { partyName = new PartyName { Value = party1 } }, new Party { partyName = new PartyName { Value = party2 } } }; TradeType = trade.ItemElementName; //Determine the product type, so that the appropriate productPricer can be instantiated. //Set the product type var productType = tradeIdentifier.ProductType; //Check whether the business calendars list is null. Pair <IBusinessCalendar, IBusinessCalendar> firstCalendarPair = null; if (legCalendars?.Count > 0) { firstCalendarPair = legCalendars[0]; } //Instantiate the productPricer. if (productType != null && productType != ProductTypeSimpleEnum.Undefined) { ProductType = (ProductTypeSimpleEnum)productType; switch (ProductType) { case ProductTypeSimpleEnum.PropertyTransaction: { IBusinessCalendar settlementCalendar = null; if (firstCalendarPair != null) { settlementCalendar = firstCalendarPair.First; } var property = (PropertyTransaction)trade.Item; var tradeDate = tradeProps.GetValue <DateTime>(TradeProp.TradeDate, false); var referenceProperty = tradeProps.GetValue <String>(PropertyProp.ReferenceProperty, false); //Get the instrument configuration data. //Modify the pricer to include this data. PriceableProduct = new PropertyTransactionPricer(logger, cache, nameSpace, tradeDate, referenceProperty, settlementCalendar, property, BaseParty, forecastRateInterpolation); ProductReporter = new PropertyTransactionReporter(); } break; case ProductTypeSimpleEnum.EquityTransaction: { IBusinessCalendar settlementCalendar = null; if (firstCalendarPair != null) { settlementCalendar = firstCalendarPair.First; } var equity = (EquityTransaction)trade.Item; var tradeDate = tradeProps.GetValue <DateTime>(TradeProp.TradeDate, true); var effectiveDate = tradeProps.GetValue <DateTime>(TradeProp.EffectiveDate, true); var referenceEquity = tradeProps.GetValue <String>(EquityProp.ReferenceEquity, false); //Get the instrument configuration data. //Modify the pricer to include this data. PriceableProduct = new EquityTransactionPricer(logger, cache, nameSpace, tradeDate, effectiveDate, referenceEquity, settlementCalendar, equity, BaseParty, forecastRateInterpolation); ProductReporter = new EquityTransactionReporter(); } break; case ProductTypeSimpleEnum.BondTransaction: { IBusinessCalendar settlementCalendar = null; if (firstCalendarPair != null) { settlementCalendar = firstCalendarPair.First; } var bond = (BondTransaction)trade.Item; var tradeDate = tradeProps.GetValue <DateTime>(TradeProp.TradeDate, true); var effectiveDate = tradeProps.GetValue <DateTime>(TradeProp.EffectiveDate, true); var bondType = tradeProps.GetValue <string>(BondProp.BondType, false); //Get the instrument configuration data. //Modify the pricer to include this data. PriceableProduct = new BondTransactionPricer(logger, cache, nameSpace, tradeDate, effectiveDate, settlementCalendar, settlementCalendar, bond, BaseParty, bondType, forecastRateInterpolation); ProductReporter = new BondTransactionReporter(); } break; case ProductTypeSimpleEnum.FutureTransaction: { IBusinessCalendar settlementCalendar = null; if (firstCalendarPair != null) { settlementCalendar = firstCalendarPair.First; } var future = (FutureTransaction)trade.Item; var tradeDate = tradeProps.GetValue <DateTime>(TradeProp.TradeDate, false); var type = tradeProps.GetValue <String>(FuturesProp.FuturesType, true); var futureType = EnumHelper.Parse <ExchangeContractTypeEnum>(type); //Get the instrument configuration data. //Modify the pricer to include this data. PriceableProduct = new FutureTransactionPricer(logger, cache, nameSpace, tradeDate, futureType, settlementCalendar, future, BaseParty, forecastRateInterpolation); ProductReporter = new FutureTransactionReporter(); } break; case ProductTypeSimpleEnum.InterestRateSwap: { var swap = (Swap)trade.Item; PriceableProduct = new InterestRateSwapPricer(logger, cache, nameSpace, legCalendars, swap, BaseParty, forecastRateInterpolation); ProductReporter = new InterestRateSwapReporter(); } break; case ProductTypeSimpleEnum.AssetSwap: { var swap = (Swap)trade.Item; //TODO set for the payer. This needs to be modified for the base counterparty. PriceableProduct = new AssetSwapPricer(logger, cache, nameSpace, legCalendars, swap, BaseParty, new Bond(), forecastRateInterpolation); ProductReporter = new InterestRateSwapReporter(); } break; case ProductTypeSimpleEnum.CrossCurrencySwap: { var swap = (Swap)trade.Item; //TODO set for the payer. This needs to be modified for the base counterparty. PriceableProduct = new CrossCurrencySwapPricer(logger, cache, nameSpace, legCalendars, swap, BaseParty, forecastRateInterpolation); ProductReporter = new InterestRateSwapReporter(); } break; case ProductTypeSimpleEnum.FRA: // todo { var fra = (Fra)trade.Item; IBusinessCalendar fixingCalendar = null; IBusinessCalendar paymentCalendar = null; if (firstCalendarPair != null) { fixingCalendar = firstCalendarPair.First; paymentCalendar = firstCalendarPair.Second; } PriceableProduct = new FraPricer(logger, cache, fixingCalendar, paymentCalendar, fra, BaseParty, nameSpace) { ForecastRateInterpolation = forecastRateInterpolation }; ProductReporter = new ForwardRateAgreementReporter(); } break; //case ProductTypeSimpleEnum.InflationSwap: // break; //case ProductTypeSimpleEnum.CreditDefaultSwap: // break; //case ProductTypeSimpleEnum.TotalReturnSwap: // break; //case ProductTypeSimpleEnum.VarianceSwap: // break; case ProductTypeSimpleEnum.CapFloor: { var capFloor = (CapFloor)trade.Item; IBusinessCalendar fixingCalendar = null; IBusinessCalendar paymentCalendar = null; if (firstCalendarPair != null) { fixingCalendar = firstCalendarPair.First; paymentCalendar = firstCalendarPair.Second; } PriceableProduct = new CapFloorPricer(logger, cache, nameSpace, fixingCalendar, paymentCalendar, capFloor, BaseParty); ProductReporter = new CapFloorReporter(); } break; case ProductTypeSimpleEnum.FxSpot: { var fxForward = (FxSingleLeg)trade.Item; PriceableProduct = new FxSingleLegPricer(fxForward, BaseParty, ProductTypeSimpleEnum.FxSpot); ProductReporter = new FxSingleLegReporter(); } break; case ProductTypeSimpleEnum.FxForward: { var fxForward = (FxSingleLeg)trade.Item; PriceableProduct = new FxSingleLegPricer(fxForward, BaseParty, ProductTypeSimpleEnum.FxForward); ProductReporter = new FxSingleLegReporter(); } break; case ProductTypeSimpleEnum.BulletPayment: { if (trade.Item is BulletPayment bullet) { IBusinessCalendar paymentCalendar = null; if (firstCalendarPair != null) { paymentCalendar = firstCalendarPair.Second; } //The calendars if (paymentCalendar == null) { if (bullet.payment.paymentDate != null) { var containsPaymentDateAdjustments = AdjustableOrAdjustedDateHelper.Contains(bullet.payment.paymentDate, ItemsChoiceType.dateAdjustments, out object dateAdjustments); if (containsPaymentDateAdjustments && dateAdjustments != null) { paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, ((BusinessDayAdjustments)dateAdjustments). businessCenters, nameSpace); } } } PriceableProduct = new BulletPaymentPricer(bullet, BaseParty, paymentCalendar); ProductReporter = new BulletPaymentReporter(); } } break; case ProductTypeSimpleEnum.FxSwap: { var fxSwap = (FxSwap)trade.Item; PriceableProduct = new FxSwapPricer(fxSwap, BaseParty); ProductReporter = new FxSwapReporter(); } break; //case ProductTypeSimpleEnum.EquityOption: // break; //case ProductTypeSimpleEnum.BondOption: // break; case ProductTypeSimpleEnum.FxOption: { IBusinessCalendar fixingCalendar = null; IBusinessCalendar paymentCalendar = null; if (firstCalendarPair != null) { fixingCalendar = firstCalendarPair.First; paymentCalendar = firstCalendarPair.Second; } var fxOption = (FxOption)trade.Item; PriceableProduct = new VanillaEuropeanFxOptionPricer(logger, cache, nameSpace, fixingCalendar, paymentCalendar, fxOption, BaseParty); ProductReporter = new FxOptionLegReporter(); } break; //case ProductTypeSimpleEnum.FxOptionStrategy: // break; //case ProductTypeSimpleEnum.CreditDefaultIndex: // break; //case ProductTypeSimpleEnum.CreditDefaultIndexTranche: // break; //case ProductTypeSimpleEnum.CreditDefaultBasket: // break; //case ProductTypeSimpleEnum.CreditDefaultBasketTranche: // break; //case ProductTypeSimpleEnum.CreditDefaultOption: // break; //case ProductTypeSimpleEnum.EquityForward: // break; case ProductTypeSimpleEnum.InterestRateSwaption: { var interestRateSwaption = (Swaption)trade.Item; PriceableProduct = new InterestRateSwaptionPricer(logger, cache, nameSpace, interestRateSwaption, BaseParty, forecastRateInterpolation); ProductReporter = new InterestRateSwaptionReporter(); } break; case ProductTypeSimpleEnum.TermDeposit: { //var party1 = tradeProps.GetValue<string>(TradeProp.Party1, true); //var party2 = tradeProps.GetValue<string>(TradeProp.Party2, true); //var reportingParty = baseParty == party1 ? "Party1" : "Party2"; // TODO this is for backward compatability. var deposit = (TermDeposit)trade.Item; PriceableProduct = new TermDepositPricer(logger, cache, deposit, TradeProp.Party1); //The payment date must be correct before calling this! ProductReporter = new TermDepositReporter(); } break; //case ProductTypeSimpleEnum.DividendSwap: // break; //case ProductTypeSimpleEnum.ConvertibleBondOption: // break; //case ProductTypeSimpleEnum.Loan: // break; //case ProductTypeSimpleEnum.Repo: // break; default: throw new NotSupportedException("Unsupported ProductType: " + ProductType); } } else { switch (TradeType) { case ItemChoiceType15.propertyTransaction: { var equity = (PropertyTransaction)trade.Item; IBusinessCalendar settlementCalendar = null; if (firstCalendarPair != null) { settlementCalendar = firstCalendarPair.First; } var tradeDate = tradeProps.GetValue <DateTime>(TradeProp.TradeDate, false); var referenceProperty = tradeProps.GetValue <String>(PropertyProp.ReferenceProperty, false); PriceableProduct = new PropertyTransactionPricer(logger, cache, nameSpace, tradeDate, referenceProperty, settlementCalendar, equity, BaseParty, forecastRateInterpolation); ProductReporter = new PropertyTransactionReporter(); } break; case ItemChoiceType15.equityTransaction: { var equity = (EquityTransaction)trade.Item; IBusinessCalendar settlementCalendar = null; if (firstCalendarPair != null) { settlementCalendar = firstCalendarPair.First; } var tradeDate = tradeProps.GetValue <DateTime>(TradeProp.TradeDate, false); var effectiveDate = tradeProps.GetValue <DateTime>(TradeProp.EffectiveDate, true); var referenceEquity = tradeProps.GetValue <String>(EquityProp.ReferenceEquity, false); PriceableProduct = new EquityTransactionPricer(logger, cache, nameSpace, tradeDate, effectiveDate, referenceEquity, settlementCalendar, equity, BaseParty, forecastRateInterpolation); ProductReporter = new EquityTransactionReporter(); } break; case ItemChoiceType15.bondTransaction: { var bond = (BondTransaction)trade.Item; IBusinessCalendar settlementCalendar = null; IBusinessCalendar paymentCalendar = null; if (firstCalendarPair != null) { settlementCalendar = firstCalendarPair.First; paymentCalendar = firstCalendarPair.Second; } var tradeDate = tradeProps.GetValue <DateTime>(TradeProp.TradeDate, true); var effectiveDate = tradeProps.GetValue <DateTime>(TradeProp.EffectiveDate, true); var bondType = tradeProps.GetValue <string>(BondProp.BondType, false); PriceableProduct = new BondTransactionPricer(logger, cache, nameSpace, tradeDate, effectiveDate, settlementCalendar, paymentCalendar, bond, BaseParty, bondType, forecastRateInterpolation); ProductReporter = new BondTransactionReporter(); } break; case ItemChoiceType15.futureTransaction: { IBusinessCalendar settlementCalendar = null; if (firstCalendarPair != null) { settlementCalendar = firstCalendarPair.First; } var future = (FutureTransaction)trade.Item; var tradeDate = tradeProps.GetValue <DateTime>(TradeProp.TradeDate, false); var type = tradeProps.GetValue <String>(FuturesProp.FuturesType, true); var futureType = EnumHelper.Parse <ExchangeContractTypeEnum>(type); //Get the instrument configuration data. //Modify the pricer to include this data. PriceableProduct = new FutureTransactionPricer(logger, cache, nameSpace, tradeDate, futureType, settlementCalendar, future, BaseParty, forecastRateInterpolation); ProductReporter = new FutureTransactionReporter(); } break; case ItemChoiceType15.swap: { var swap = (Swap)trade.Item; //TODO this needs to be emnhanced ProductType = ProductTypeSimpleEnum.InterestRateSwap; PriceableProduct = new CrossCurrencySwapPricer(logger, cache, nameSpace, legCalendars, swap, BaseParty, forecastRateInterpolation); ProductReporter = new InterestRateSwapReporter(); //var report = } break; case ItemChoiceType15.fra: // todo { var fra = (Fra)trade.Item; IBusinessCalendar fixingCalendar = null; IBusinessCalendar paymentCalendar = null; if (firstCalendarPair != null) { fixingCalendar = firstCalendarPair.First; paymentCalendar = firstCalendarPair.Second; } ProductType = ProductTypeSimpleEnum.FRA; PriceableProduct = new FraPricer(logger, cache, fixingCalendar, paymentCalendar, fra, BaseParty) { ForecastRateInterpolation = forecastRateInterpolation }; ProductReporter = new ForwardRateAgreementReporter(); } break; case ItemChoiceType15.capFloor: { var capFloor = (CapFloor)trade.Item; IBusinessCalendar fixingCalendar = null; IBusinessCalendar paymentCalendar = null; if (firstCalendarPair != null) { fixingCalendar = firstCalendarPair.First; paymentCalendar = firstCalendarPair.Second; } ProductType = ProductTypeSimpleEnum.CapFloor; PriceableProduct = new CapFloorPricer(logger, cache, nameSpace, fixingCalendar, paymentCalendar, capFloor, BaseParty); ProductReporter = new CapFloorReporter(); } break; case ItemChoiceType15.fxSingleLeg: { var fxForward = (FxSingleLeg)trade.Item; ProductType = ProductTypeSimpleEnum.FxSpot; PriceableProduct = new FxSingleLegPricer(fxForward, BaseParty, ProductType); ProductReporter = new FxSingleLegReporter(); } break; case ItemChoiceType15.fxSwap: { var fxSwap = (FxSwap)trade.Item; ProductType = ProductTypeSimpleEnum.FxSwap; PriceableProduct = new FxSwapPricer(fxSwap, BaseParty); ProductReporter = new FxSwapReporter(); } break; case ItemChoiceType15.bulletPayment: { if (trade.Item is BulletPayment bullet) { IBusinessCalendar paymentCalendar = null; if (firstCalendarPair != null) { paymentCalendar = firstCalendarPair.Second; } //The calendars if (paymentCalendar == null) { if (bullet.payment.paymentDate != null) { var containsPaymentDateAdjustments = AdjustableOrAdjustedDateHelper.Contains(bullet.payment.paymentDate, ItemsChoiceType.dateAdjustments, out object dateAdjustments); if (containsPaymentDateAdjustments && dateAdjustments != null) { paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, ((BusinessDayAdjustments)dateAdjustments). businessCenters, nameSpace); } } } ProductType = ProductTypeSimpleEnum.BulletPayment; PriceableProduct = new BulletPaymentPricer(bullet, BaseParty, paymentCalendar); ProductReporter = new BulletPaymentReporter(); } } break; case ItemChoiceType15.termDeposit: { var deposit = (TermDeposit)trade.Item; ProductType = ProductTypeSimpleEnum.TermDeposit; PriceableProduct = new TermDepositPricer(logger, cache, deposit, TradeProp.Party1); //The payment date must be correct before calling this! ProductReporter = new TermDepositReporter(); } break; case ItemChoiceType15.swaption: { var interestRateSwaption = (Swaption)trade.Item; ProductType = ProductTypeSimpleEnum.InterestRateSwaption; PriceableProduct = new InterestRateSwaptionPricer(logger, cache, nameSpace, interestRateSwaption, BaseParty, forecastRateInterpolation); ProductReporter = new InterestRateSwaptionReporter(); } break; case ItemChoiceType15.fxOption: { IBusinessCalendar fixingCalendar = null; IBusinessCalendar paymentCalendar = null; if (firstCalendarPair != null) { fixingCalendar = firstCalendarPair.First; paymentCalendar = firstCalendarPair.Second; } var fxOption = (FxOption)trade.Item; ProductType = ProductTypeSimpleEnum.FxOption; PriceableProduct = new VanillaEuropeanFxOptionPricer(logger, cache, nameSpace, fixingCalendar, paymentCalendar, fxOption, BaseParty); ProductReporter = new FxOptionLegReporter(); } break; default: throw new NotSupportedException("Unsupported TradeType: " + TradeType); } //Adds the extra party info now required. PriceableProduct.OrderedPartyNames.Add(party1); PriceableProduct.OrderedPartyNames.Add(party2); //Check if collateralised if (trade.collateral != null) { PriceableProduct.IsCollateralised = true; } } }
/// <summary> /// Converts to an adjustable date type. /// </summary> /// <param name="unadjustedDate"></param> /// <param name="businessDayConvention"></param> /// <param name="businessCentersAsString"></param> /// <returns></returns> public static AdjustableOrAdjustedDate ToAdjustableOrAdjustedDate(DateTime unadjustedDate, BusinessDayConventionEnum businessDayConvention, string businessCentersAsString) { var result = AdjustableOrAdjustedDateHelper.CreateUnadjustedDate(unadjustedDate, businessDayConvention.ToString(), businessCentersAsString); return(result); }
/// <summary> /// Converts to an adjustable date type. /// </summary> /// <param name="adjustedDate"></param> /// <returns></returns> public static AdjustableOrAdjustedDate ToAdjustableOrAdjustedDate(DateTime adjustedDate) { var result = AdjustableOrAdjustedDateHelper.CreateAdjustedDate(adjustedDate); return(result); }