/// <summary>
 ///
 /// </summary>
 /// <param name="logger"></param>
 /// <param name="cache"></param>
 /// <param name="isCollateralised"></param>
 /// <param name="collateralCurrency"></param>
 /// <param name="fixingCalendar"></param>
 /// <param name="paymentCalendar"></param>
 /// <param name="isPayer"></param>
 /// <param name="commodityForwardFpML"></param>
 /// <param name="nameSpace"></param>
 public CommodityForwardPricer(ILogger logger, ICoreCache cache, bool isCollateralised,
                               string collateralCurrency, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar,
                               bool isPayer, CommodityForward commodityForwardFpML, String nameSpace)
 {
     IsCollateralised   = isCollateralised;
     CollateralCurrency = collateralCurrency;
     OrderedPartyNames  = new List <string>();
     Multiplier         = 1.0m;
     ValueDate          = commodityForwardFpML.valueDate;
     FixedLeg           = commodityForwardFpML.fixedLeg;
     BullionPhysicalLeg = commodityForwardFpML.Item;
     if (commodityForwardFpML.commonPricingSpecified)
     {
         CommonPricing = commodityForwardFpML.commonPricing;
     }
     AddCashFlows(logger, cache, fixingCalendar, paymentCalendar, commodityForwardFpML, isPayer, nameSpace);
     BasePartyPayingFixed = !isPayer;
     RiskMaturityDate     = TerminationDate;
     NumberOfDays         = (DayCounterHelper.Parse(DayCountFraction.Value)).DayCount(EffectiveDate, TerminationDate);
     //Set the product type.
     ProductType       = ProductTypeSimpleEnum.FRA;
     PaymentCurrencies = new List <string> {
         Notional.currency.Value
     };
     //Set the default discount curve name.
     DiscountCurveName = CurveNameHelpers.GetDiscountCurveName(CollateralCurrency, !IsCollateralised);
     ForecastCurveName = CurveNameHelpers.GetForecastCurveName(commodityForwardFpML.floatingRateIndex, commodityForwardFpML.indexTenor);
 }
Esempio n. 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="logger"></param>
 /// <param name="cache"></param>
 /// <param name="fixingCalendar"></param>
 /// <param name="paymentCalendar"></param>
 /// <param name="isBuyer"></param>
 /// <param name="fraFpML"></param>
 /// <param name="nameSpace"></param>
 public FraPricer(ILogger logger, ICoreCache cache,
                  IBusinessCalendar fixingCalendar,
                  IBusinessCalendar paymentCalendar,
                  bool isBuyer, Fra fraFpML, String nameSpace)
 {
     OrderedPartyNames     = new List <string>();
     Multiplier            = 1.0m;
     FraDiscounting        = fraFpML.fraDiscounting;
     FixingOffSet          = fraFpML.fixingDateOffset;
     FloatingRateIndex     = fraFpML.floatingRateIndex;
     DayCountFraction      = fraFpML.dayCountFraction;
     Notional              = fraFpML.notional;
     IndexTenor            = fraFpML.indexTenor;
     AdjustablePaymentDate = fraFpML.paymentDate;
     FixedRate             = fraFpML.fixedRate;
     AddCashFlows(logger, cache, fixingCalendar, paymentCalendar, fraFpML, isBuyer, nameSpace);
     BasePartyPayingFixed = !isBuyer;
     RiskMaturityDate     = TerminationDate;
     NumberOfDays         = (DayCounterHelper.Parse(DayCountFraction.Value)).DayCount(EffectiveDate, TerminationDate);
     //Set the product type.
     ProductType       = ProductTypeSimpleEnum.FRA;
     PaymentCurrencies = new List <string> {
         Notional.currency.Value
     };
     //Set the default discount curve name.
     DiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Notional.currency.Value, true);
     ForecastCurveName = CurveNameHelpers.GetForecastCurveName(fraFpML.floatingRateIndex, fraFpML.indexTenor);
 }
 protected void UpdateCouponDiscountCurveNames()
 {
     foreach (var coupon in Coupons)
     {
         coupon.DiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Currency, true);
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableCapFloorCoupon"/> class.
 /// </summary>
 /// <param name="cashlFowId">The stream id.</param>
 /// <param name="buyerIsBase">The buyer is base flag.</param>
 /// <param name="capStrike">The Cap strike.</param>
 /// <param name="floorStrike">The floor strike.</param>
 /// <param name="accrualStartDate">The accrual start date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="accrualEndDate">The accrual end date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="margin">The margin.</param>
 /// <param name="observedRate">The observed Rate. If this is not null, then it is used.</param>
 /// <param name="notionalAmount">The notional amount.</param>
 /// <param name="adjustedFixingDate">The adjusted fixing date.</param>
 /// <param name="dayCountFraction">Type of day Count fraction.</param>
 /// <param name="paymentDate">The payment date.</param>
 /// <param name="forecastRateIndex">The forecast rate index.</param>
 /// <param name="discountingType">The swap discounting type.</param>
 /// <param name="discountRate">The discount rate.</param>
 /// <param name="fraDiscounting">Determines whether the coupon is discounted or not. If this parameter is null,
 /// then it is assumed that there is no fra discounting</param>
 /// <param name="fixingCalendar"> The fixingCalendar. </param>
 /// <param name="paymentCalendar"> The paymentCalendar. </param>
 public PriceableCapFloorCoupon
 (
     string cashlFowId
     , bool buyerIsBase
     , decimal?capStrike
     , decimal?floorStrike
     , DateTime accrualStartDate
     , DateTime accrualEndDate
     , DateTime adjustedFixingDate
     , DayCountFraction dayCountFraction
     , Decimal margin
     , Decimal?observedRate
     , Money notionalAmount
     , DateTime paymentDate
     , ForecastRateIndex forecastRateIndex
     , DiscountingTypeEnum?discountingType
     , Decimal?discountRate
     , FraDiscountingEnum?fraDiscounting
     , IBusinessCalendar fixingCalendar
     , IBusinessCalendar paymentCalendar)
     : base(
         cashlFowId
         , buyerIsBase
         , accrualStartDate
         , accrualEndDate
         , adjustedFixingDate
         , dayCountFraction
         , margin
         , observedRate
         , notionalAmount
         , paymentDate
         , forecastRateIndex
         , discountingType
         , discountRate
         , fraDiscounting
         , fixingCalendar
         , paymentCalendar)
 {
     CapStrike             = capStrike;
     FloorStrike           = floorStrike;
     VolatilitySurfaceName = CurveNameHelpers.GetRateVolatilityMatrixName(forecastRateIndex);
     if (capStrike != null && floorStrike == null)
     {
         PriceableCouponType = CouponType.Cap;
         ModelIdentifier     = "DualCurveCapModel";
         IsCall = true;
     }
     if (floorStrike != null && capStrike == null)
     {
         PriceableCouponType = CouponType.Floor;
         ModelIdentifier     = "DualCurveFloorModel";
     }
     if (floorStrike != null && capStrike != null)
     {
         PriceableCouponType = CouponType.Collar;
         ModelIdentifier     = "DualCurveCollarModel";
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableFxRateCashflow"/> class.
 /// </summary>
 /// <param name="cashlfowId">The stream id.</param>
 /// <param name="payerIsBase">The payer is base flag.</param>
 /// <param name="accrualStartDate">The accrual start date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="accrualEndDate">The accrual end date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="adjustAccrualDatesIndicator">if set to <c>true</c> [adjust calculation dates indicator].</param>
 /// <param name="accrualBusinessCenters">The accrual business centers.</param>
 /// <param name="margin">The margin.</param>
 /// <param name="baseRate">The base rate for a nettable fixed/floating cash flow. </param>
 /// <param name="observedRate">The observed Rate.</param>
 /// <param name="notionalAmount">The notional amount.</param>
 /// <param name="dayCountfraction">Type of day Countfraction.</param>
 /// <param name="paymentDate">The payment date.</param>
 /// <param name="accrualRollConvention">The accrual roll convention.</param>
 /// <param name="resetRelativeTo">reset relative to?</param>
 /// <param name="fixingDateRelativeOffset">The fixing date offset.</param>
 /// <param name="forecastRateIndex">The forecastrateindex.</param>
 /// <param name="discountingType">The swap discounting type.</param>
 /// <param name="discountRate">The discount rate.</param>
 /// <param name="fraDiscounting">Determines whether the coupon is discounted or not. If this parameter is null,
 /// then it is assumed that there is no fradiscounting</param>
 /// <param name="fixingCalendar">The fixingCalendar.</param>
 /// <param name="paymentCalendar">The paymentCalendar.</param>
 public PriceableFloatingRateCoupon
 (
     string cashlfowId
     , bool payerIsBase
     , DateTime accrualStartDate
     , DateTime accrualEndDate
     , Boolean adjustAccrualDatesIndicator
     , BusinessCenters accrualBusinessCenters
     , BusinessDayConventionEnum accrualRollConvention
     , DayCountFraction dayCountfraction
     , ResetRelativeToEnum resetRelativeTo
     , RelativeDateOffset fixingDateRelativeOffset
     , Decimal margin
     , Decimal baseRate
     , Decimal?observedRate
     , Money notionalAmount
     , AdjustableOrAdjustedDate paymentDate
     , ForecastRateIndex forecastRateIndex
     , DiscountingTypeEnum?discountingType
     , Decimal?discountRate
     , FraDiscountingEnum?fraDiscounting
     , IBusinessCalendar fixingCalendar
     , IBusinessCalendar paymentCalendar)
     : base(
         cashlfowId
         , CouponType.FloatingRate
         , payerIsBase
         , accrualStartDate
         , accrualEndDate
         , adjustAccrualDatesIndicator
         , accrualBusinessCenters
         , accrualRollConvention
         , dayCountfraction
         , observedRate
         , notionalAmount
         , paymentDate
         , discountingType
         , discountRate
         , fraDiscounting
         , paymentCalendar)
 {
     BaseRate        = baseRate;
     FixingCalendar  = fixingCalendar;
     ModelIdentifier = "DualCurveCouponModel";
     Id = cashlfowId;
     ForwardStartDate         = AccrualStartDate;
     ForecastRateIndex        = forecastRateIndex;
     FixingDateRelativeOffset = fixingDateRelativeOffset;
     ResetRelativeTo          = resetRelativeTo;
     Margin             = margin;
     AdjustedFixingDate = GetResetDate(resetRelativeTo, fixingDateRelativeOffset);
     if (observedRate != null)
     {
         RateObservation = RateObservationHelper.Parse(AdjustedFixingDate, (decimal)observedRate, "1");
     }
     SetRateObservation(RateObservation, ResetDate);
     ForecastCurveName = CurveNameHelpers.GetForecastCurveName(forecastRateIndex);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableBondCouponRateStream"/> class.
 /// </summary>
 /// <param name="logger">The logger.</param>
 /// <param name="cache">The cache.</param>
 /// <param name="nameSpace">The client namespace.</param>
 /// <param name="bondId">The bond Id.</param>
 /// <param name="paymentConvention">The payment roll conventions</param>
 /// <param name="forecastRateInterpolation">ForwardEndDate = forecastRateInterpolation ? AccrualEndDate
 /// : AdjustedDateHelper.ToAdjustedDate(forecastRateIndex.indexTenor.Add(AccrualStartDate), AccrualBusinessDayAdjustments);</param>
 /// <param name="fixingCalendar">The fixingCalendar.</param>
 /// <param name="paymentCalendar">The paymentCalendar.</param>
 /// <param name="tradeDate">The trade date is used to set the base date for future coupon generation.</param>
 /// <param name="notionalAmount">The notional amount</param>
 /// <param name="couponType">The coupon type: fixed or floating.</param>
 /// <param name="bond">THe bond details.</param>
 public PriceableBondCouponRateStream
 (
     ILogger logger
     , ICoreCache cache
     , string nameSpace
     , string bondId
     , DateTime tradeDate
     , decimal notionalAmount
     , CouponStreamType couponType
     , Bond bond
     , BusinessDayAdjustments paymentConvention
     , bool forecastRateInterpolation
     , IBusinessCalendar fixingCalendar
     , IBusinessCalendar paymentCalendar)
 {
     BondId               = bondId;
     Multiplier           = 1.0m;
     PaymentCurrencies    = new List <string>();
     AnalyticsModel       = new BondStreamAnalytic();
     BondCouponStreamType = couponType;
     Id       = BuildId(bondId, BondCouponStreamType);
     Currency = bond.currency.Value;
     ForecastRateInterpolation = forecastRateInterpolation;
     //Get the currency.
     if (!PaymentCurrencies.Contains(bond.currency.Value))
     {
         PaymentCurrencies.Add(bond.currency.Value);
     }
     //The calendars
     if (paymentCalendar == null)
     {
         paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, paymentConvention.businessCenters, nameSpace);
     }
     //Set the default discount curve name.
     BondCurveName = CurveNameHelpers.GetBondCurveName(Currency, bondId);
     //Set the forecast curve name.//TODO extend this to the other types.
     //if (BondCouponStreamType != CouponStreamType.GenericFixedRate)
     //{
     //    if (fixingCalendar == null)
     //    {
     //        fixingCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, ResetDates.resetDatesAdjustments.businessCenters, nameSpace);
     //    }
     //    ForecastCurveName = null;
     //    //if (Calculation.Items != null)
     //    //{
     //    //    var floatingRateCalculation = Calculation.Items;
     //    //    var floatingRateIndex = (FloatingRateCalculation) floatingRateCalculation[0];
     //    //    ForecastCurveName = CurveNameHelpers.GetForecastCurveName(floatingRateIndex);
     //    //}
     //}
     //Build the coupons and principal exchanges.
     Coupons = PriceableInstrumentsFactory.CreatePriceableBondCoupons(tradeDate, bond, notionalAmount, BondCouponStreamType,
                                                                      paymentConvention, ForecastRateInterpolation, fixingCalendar, paymentCalendar);//TODO add the stub calculation.
     UpdateCouponDiscountCurveNames();
     UpdateCouponIds();
     //RiskMaturityDate = ;
     logger.LogInfo("Bond Coupon Stream built");
 }
Esempio n. 7
0
 /// <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);
 }
Esempio n. 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableCapFloorCoupon"/> class.
 /// </summary>
 /// <param name="uniqueId"></param>
 /// <param name="buyerIsBase">The buyer is base flag.</param>
 /// <param name="capStrike">The Cap strike.</param>
 /// <param name="floorStrike">The floor strike.</param>
 /// <param name="accrualStartDate"></param>
 /// <param name="accrualEndDate"></param>
 /// <param name="adjustCalculationDatesIndicator"></param>
 /// <param name="paymentDate"></param>
 /// <param name="notionalAmount"></param>
 /// <param name="resetRelativeTo"></param>
 /// <param name="fixingDateRelativeOffset"></param>
 /// <param name="margin"></param>
 /// <param name="calculation"></param>
 /// <param name="forecastRateIndex"></param>
 /// <param name="fixingCalendar"></param>
 /// <param name="paymentCalendar"></param>
 public PriceableCapFloorCoupon
     (string uniqueId
     , bool buyerIsBase
     , decimal?capStrike
     , decimal?floorStrike
     , DateTime accrualStartDate
     , DateTime accrualEndDate
     , Boolean adjustCalculationDatesIndicator
     , AdjustableOrAdjustedDate paymentDate
     , Money notionalAmount
     , ResetRelativeToEnum resetRelativeTo
     , RelativeDateOffset fixingDateRelativeOffset
     , Decimal margin
     , Calculation calculation
     , ForecastRateIndex forecastRateIndex
     , IBusinessCalendar fixingCalendar
     , IBusinessCalendar paymentCalendar)
     : base
         (uniqueId
         , buyerIsBase
         , accrualStartDate
         , accrualEndDate
         , adjustCalculationDatesIndicator
         , paymentDate
         , notionalAmount
         , resetRelativeTo
         , fixingDateRelativeOffset
         , margin
         , calculation
         , forecastRateIndex
         , fixingCalendar
         , paymentCalendar)
 {
     CapStrike             = capStrike;
     FloorStrike           = floorStrike;
     VolatilitySurfaceName = CurveNameHelpers.GetRateVolatilityMatrixName(forecastRateIndex);
     if (capStrike != null && floorStrike == null)
     {
         PriceableCouponType = CouponType.Cap;
         ModelIdentifier     = "DualCurveCapModel";
         IsCall = true;
     }
     if (floorStrike != null && capStrike == null)
     {
         PriceableCouponType = CouponType.Floor;
         ModelIdentifier     = "DualCurveFloorModel";
     }
     if (floorStrike != null && capStrike != null)
     {
         PriceableCouponType = CouponType.Collar;
         ModelIdentifier     = "DualCurveCollarModel";
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FxSingleLegPricer"/> 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 FxSingleLegPricer(FxSingleLeg 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.Items1ElementName[0] == Items1ChoiceType.valueDate ? fxLeg.Items1[0] : LastDate();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableFxRateCashflow"/> class.
 /// </summary>
 /// <param name="cashflowId">The stream id.</param>
 /// <param name="startIndex">The start Index. If null then the cash flow is not a differenctial.</param>
 /// <param name="observedIndex">The observed Index. If null then the cash flow is not a differenctial. </param>
 /// <param name="isCurrency1Base">The isCurrency1Base flag. </param>
 /// <param name="currency2PayerIsBase">The currency2PayerIsBase lag.</param>
 /// <param name="isSettlementInCurrency1">The isSettlementInCurrency1 flag</param>
 /// <param name="hybridValuation">Is hybrid valuation used, or the base fa curve. </param>
 /// <param name="currency1NotionalAmount">The currency1 notional amount.</param>
 /// <param name="fixingDateRelativeOffset">The fixingDateRelativeOffset.</param>
 /// <param name="paymentDate">The payment date.</param>
 /// <param name="fixingCalendar">The fixingCalendar.</param>
 /// <param name="paymentCalendar">The paymentCalendar.</param>
 protected PriceableFxRateCashflow
 (
     string cashflowId
     , FxRate startIndex
     , FxRate observedIndex
     , bool isCurrency1Base
     , bool currency2PayerIsBase
     , bool isSettlementInCurrency1
     , bool hybridValuation
     , Money currency1NotionalAmount
     , AdjustableOrAdjustedDate paymentDate
     , RelativeDateOffset fixingDateRelativeOffset
     , IBusinessCalendar fixingCalendar
     , IBusinessCalendar paymentCalendar)
     : base
     (
         cashflowId
         , FloatingIndexType.Fx
         , startIndex.rate
         , IsObserved(observedIndex)
         , currency2PayerIsBase
         , currency1NotionalAmount
         , paymentDate
         , fixingDateRelativeOffset
         , fixingCalendar
         , paymentCalendar)
 {
     ModelIdentifier         = "FloatingFxRateCashflowModel";
     StartFxRate             = startIndex;
     IsSettlementInCurrency1 = isSettlementInCurrency1;
     HybridValuation         = hybridValuation;
     if (StartFxRate.quotedCurrencyPair.quoteBasis == QuoteBasisEnum.Currency1PerCurrency2)
     {
         InvertFxRate = true;
     }
     IsCurrency1Base = isCurrency1Base;
     Currency1       = StartFxRate.quotedCurrencyPair.currency1;
     Currency2       = StartFxRate.quotedCurrencyPair.currency2;
     //Set the default discount curve name.
     Currency1DiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Currency1.Value, true);
     //Set the default discount curve name.
     Currency2DiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Currency2.Value, true);
     ForecastCurveName          = MarketEnvironmentHelper.ResolveFxCurveNames(StartFxRate.quotedCurrencyPair.currency1.Value,
                                                                              StartFxRate.quotedCurrencyPair.currency2.Value);
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="uniqueId"></param>
        /// <param name="payerIsBase"></param>
        /// <param name="accrualStartDate"></param>
        /// <param name="accrualEndDate"></param>
        /// <param name="adjustCalculationDatesIndicator"></param>
        /// <param name="paymentDate"></param>
        /// <param name="notionalAmount"></param>
        /// <param name="resetRelativeTo"></param>
        /// <param name="fixingDateRelativeOffset"></param>
        /// <param name="margin"></param>
        /// <param name="baseRate"> </param>
        /// <param name="calculation"></param>
        /// <param name="forecastRateIndex"></param>
        /// <param name="fixingCalendar"></param>
        /// <param name="paymentCalendar"></param>
        public PriceableFloatingRateCoupon
            (string uniqueId
            , bool payerIsBase
            , DateTime accrualStartDate
            , DateTime accrualEndDate
            , Boolean adjustCalculationDatesIndicator
            , AdjustableOrAdjustedDate paymentDate
            , Money notionalAmount
            , ResetRelativeToEnum resetRelativeTo
            , RelativeDateOffset fixingDateRelativeOffset
            , Decimal margin
            , Decimal baseRate
            , Calculation calculation
            , ForecastRateIndex forecastRateIndex
            , IBusinessCalendar fixingCalendar
            , IBusinessCalendar paymentCalendar)
            : base
                (uniqueId
                , CouponType.FloatingRate
                , payerIsBase
                , accrualStartDate
                , accrualEndDate
                , adjustCalculationDatesIndicator
                , BusinessDayAdjustmentsHelper.Create(fixingDateRelativeOffset.businessDayConvention, fixingDateRelativeOffset.businessCenters)
                , calculation
                , notionalAmount
                , paymentDate
                , paymentCalendar)
        {
            BaseRate                 = baseRate;
            FixingCalendar           = fixingCalendar;
            ModelIdentifier          = "DualCurveCouponModel";
            ForwardStartDate         = AccrualStartDate;
            ForwardEndDate           = AccrualEndDate;
            ForecastRateIndex        = forecastRateIndex;
            FixingDateRelativeOffset = fixingDateRelativeOffset;
            ResetRelativeTo          = resetRelativeTo;
            Margin = margin;
            var floatingRateDefinition = (FloatingRateDefinition)calculation.Items[0];

            RateObservation    = floatingRateDefinition.rateObservation[0];
            AdjustedFixingDate = GetResetDate(resetRelativeTo, fixingDateRelativeOffset);
            SetRateObservation(RateObservation, ResetDate);
            ForecastCurveName = CurveNameHelpers.GetForecastCurveName(forecastRateIndex);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableFxRateCashflow"/> class.
 /// </summary>
 /// <param name="cashlfowId">The stream id.</param>
 /// <param name="payerIsBase">The payer is base flag.</param>
 /// <param name="accrualStartDate">The accrual start date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="accrualEndDate">The accrual end date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="margin">The margin.</param>
 /// <param name="baseRate">The base rate for a nettable fixed/floating cash flow. </param>
 /// <param name="observedRate">The observed Rate. If this is not null, then it is used.</param>
 /// <param name="notionalAmount">The notional amount.</param>
 /// <param name="adjustedFixingDate">The adjusted fixing date.</param>
 /// <param name="dayCountfraction">Type of day Countfraction.</param>
 /// <param name="paymentDate">The payment date.</param>
 /// <param name="forecastRateIndex">The forecastrate index.</param>
 /// <param name="discountingType">The swap discounting type.</param>
 /// <param name="discountRate">The discount rate.</param>
 /// <param name="fraDiscounting">Determines whether the coupon is discounted or not. If this parameter is null,
 /// then it is assumed that there is no fradiscounting</param>
 /// <param name="fixingCalendar">The fixingCalendar.</param>
 /// <param name="paymentCalendar">The paymentCalendar.</param>
 public PriceableFloatingRateCoupon
 (
     string cashlfowId
     , bool payerIsBase
     , DateTime accrualStartDate
     , DateTime accrualEndDate
     , DateTime adjustedFixingDate
     , DayCountFraction dayCountfraction
     , Decimal margin
     , Decimal baseRate
     , Decimal?observedRate
     , Money notionalAmount
     , DateTime paymentDate
     , ForecastRateIndex forecastRateIndex
     , DiscountingTypeEnum?discountingType
     , Decimal?discountRate
     , FraDiscountingEnum?fraDiscounting
     , IBusinessCalendar fixingCalendar
     , IBusinessCalendar paymentCalendar)
     : base(
         cashlfowId
         , CouponType.FloatingRate
         , payerIsBase
         , accrualStartDate
         , accrualEndDate
         , notionalAmount
         , dayCountfraction
         , observedRate
         , paymentDate
         , discountingType
         , discountRate
         , fraDiscounting
         , paymentCalendar)
 {
     BaseRate        = baseRate;
     FixingCalendar  = fixingCalendar;
     ModelIdentifier = "DualCurveCouponModel";
     Id = cashlfowId;
     ForecastRateIndex  = forecastRateIndex;
     Margin             = margin;
     AdjustedFixingDate = adjustedFixingDate;
     RateObservation    = RateObservationHelper.Parse(AdjustedFixingDate, observedRate, "1");
     SetRateObservation(RateObservation, ResetDate);
     ForecastCurveName = CurveNameHelpers.GetForecastCurveName(forecastRateIndex);
 }
Esempio n. 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableLeaseAsset"/> class.
 /// </summary>
 /// <param name="baseDate">The base date.</param>
 /// <param name="paymentCalendar">The payment Calendar.</param>
 /// <param name="marketQuote">The market quote.</param>
 /// <param name="lease">The lease.</param>
 public PriceableLeaseAsset(DateTime baseDate, FpML.V5r3.Reporting.Lease lease, IBusinessCalendar paymentCalendar,
                            BasicQuotation marketQuote)
 {
     PaymentCalendar = paymentCalendar;
     Multiplier      = 1.0m;
     YearFractions   = new[] { 0.25m };
     ModelIdentifier = "LeaseAsset";
     StartAmount     = lease.startGrossPrice.amount;
     MaturityDate    = lease.leaseExpiryDate.Value;
     Frequency       = lease.paymentFrequency;
     LeaseRate       = lease.reviewChange;
     Currency        = lease.currency;
     BaseDate        = baseDate;
     SettlementDate  = baseDate;
     PaymentBusinessDayAdjustments = lease.businessDayAdjustments;
     FirstPaymentDate = lease.startDate.Value;
     ReviewFrequency  = lease.reviewFrequency;
     NextReviewDate   = lease.nextReviewDate.Value;
     if (MaturityDate > BaseDate)
     {
         var rollConvention =
             RollConventionEnumHelper.Parse(MaturityDate.Day.ToString(CultureInfo.InvariantCulture));
         UnAdjustedPeriodDates = DateScheduler.GetUnadjustedCouponDatesFromMaturityDate(SettlementDate,
                                                                                        MaturityDate,
                                                                                        Frequency,
                                                                                        rollConvention,
                                                                                        out _,
                                                                                        out var nextCouponDate);
         LastPaymentDate     = UnAdjustedPeriodDates[0];
         AdjustedPeriodDates =
             AdjustedDateScheduler.GetAdjustedDateSchedule(UnAdjustedPeriodDates,
                                                           PaymentBusinessDayAdjustments.businessDayConvention,
                                                           paymentCalendar).ToArray();
         AdjustedPeriodDates[0] = SettlementDate;
         NextPaymentDate        = nextCouponDate;
     }
     RiskMaturityDate = AdjustedPeriodDates[AdjustedPeriodDates.Length - 1];
     Weightings       =
         CreateWeightings(CDefaultWeightingValue, AdjustedPeriodDates.Length - 1);//, LeaseRate,
     //TODO Need to add a credit spread to this.
     LeaseDiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Currency.Value, true);
 }
Esempio n. 14
0
        /// <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);
            }
        }
Esempio n. 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableVanillaFxOption"/> class.
 /// </summary>
 /// <param name="cashlfowId">The stream id.</param>
 /// <param name="startIndex">The start Index. If null then the cash flow is not a differenctial.</param>
 /// <param name="observedIndex">The observed Index. If null then the cash flow is not a differenctial. </param>
 /// <param name="isCurrency1Base">The isCurrency1Base flag. </param>
 /// <param name="currency2PayerIsBase">The currency2PayerIsBase lag.</param>
 /// <param name="isSettlementInCurrency1">The isSettlementInCurrency1 flag</param>
 /// <param name="hybridValuation">Is hybrid valuation used, or the base fa curve. </param>
 /// <param name="currency1NotionalAmount">The currency1 notional amount.</param>
 /// <param name="fixingDateRelativeOffset">The fixingDateRelativeOffset.</param>
 /// <param name="strike">The strike. </param>
 /// <param name="fxOptionType">THe option type: currently only call or pt </param>
 /// <param name="paymentDate">The payment date.</param>
 /// <param name="fixingCalendar">The fixingCalendar.</param>
 /// <param name="paymentCalendar">The paymentCalendar.</param>
 protected PriceableVanillaFxOption
 (
     string cashlfowId
     , FxRate startIndex
     , FxRate observedIndex
     , bool isCurrency1Base
     , bool currency2PayerIsBase
     , bool isSettlementInCurrency1
     , bool hybridValuation
     , Money currency1NotionalAmount
     , decimal strike
     , FxOptionType fxOptionType
     , AdjustableOrAdjustedDate paymentDate
     , RelativeDateOffset fixingDateRelativeOffset
     , IBusinessCalendar fixingCalendar
     , IBusinessCalendar paymentCalendar)
     : base
     (
         cashlfowId
         , startIndex
         , observedIndex
         , isCurrency1Base
         , currency2PayerIsBase
         , isSettlementInCurrency1
         , hybridValuation
         , currency1NotionalAmount
         , paymentDate
         , fixingDateRelativeOffset
         , fixingCalendar
         , paymentCalendar)
 {
     Strike       = strike;
     FxOptionType = FxOptionType.Call;
     if (fxOptionType != FxOptionType.Call)//TODO Only call or put.
     {
         FxOptionType = FxOptionType.Put;
     }
     VolatilitySurfaceName = CurveNameHelpers.GetFxVolatilityMatrixName(startIndex, "FxSpot");
     ModelIdentifier       = "VanillaFxOptionModel";
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="nameSpace"></param>
        /// <param name="swaptionFpML"> </param>
        /// <param name="basePartyReference"></param>
        /// <param name="forecastRateInterpolation"></param>
        public InterestRateSwaptionPricer(ILogger logger, ICoreCache cache, String nameSpace,
                                          Swaption swaptionFpML, string basePartyReference, Boolean forecastRateInterpolation)
            : base(logger, cache, nameSpace, swaptionFpML, basePartyReference, forecastRateInterpolation)
        {
            ProductType = ProductTypeSimpleEnum.InterestRateSwaption;
            var underlyingSwap = new InterestRateSwapPricer(logger, cache, nameSpace, null, swaptionFpML.swap, basePartyReference, forecastRateInterpolation);

            Swap = underlyingSwap;
            //Add the currencies for the trade pricer.
            foreach (var ccy in Swap.PaymentCurrencies)
            {
                if (!PaymentCurrencies.Contains(ccy))
                {
                    PaymentCurrencies.Add(ccy);
                }
            }
            if (underlyingSwap.SwapType == SwapType.FixedFloat && underlyingSwap.ProductType == ProductTypeSimpleEnum.InterestRateSwap)
            {
                if (Swap.BasePartyPayingFixed && underlyingSwap.PayLeg.Strike != null)
                {
                    StrikeRate = (decimal)underlyingSwap.PayLeg.Strike;
                    if (!IsBasePartyBuyer)
                    {
                        IsCall = true;
                    }
                }
                if (!Swap.BasePartyPayingFixed && underlyingSwap.ReceiveLeg.Strike != null)//
                {
                    StrikeRate = (decimal)underlyingSwap.ReceiveLeg.Strike;
                    if (IsBasePartyBuyer)
                    {
                        IsCall = true;
                    }
                }
                VolatilitySurfaceName = CurveNameHelpers.GetRateVolatilityMatrixName(swaptionFpML.swap);
            }
            BucketedDates    = new DateTime[] { };
            RiskMaturityDate = Swap.RiskMaturityDate;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PriceableCapFloorStream"/> class.  All the cashflows must be signed.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="stream">The stream.</param>
        /// <param name="nameSpace">The nameSpace</param>
        /// <param name="payerIsBase">The flag for whether the payerreference is the base party.</param>
        /// <param name="forecastRateInterpolation">ForwardEndDate = forecastRateInterpolation ? AccrualEndDate
        /// : AdjustedDateHelper.ToAdjustedDate(forecastRateIndex.indexTenor.Add(AccrualStartDate), AccrualBusinessDayAdjustments);</param>
        /// <param name="fixingCalendar">The fixingCalendar.</param>
        /// <param name="paymentCalendar">The paymentCalendar.</param>
        public PriceableCapFloorStream(ILogger logger, ICoreCache cache, String nameSpace
                                       , bool payerIsBase, InterestRateStream stream, bool forecastRateInterpolation
                                       , IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar)
            : base(logger
                   , cache
                   , nameSpace
                   , payerIsBase
                   , stream
                   , forecastRateInterpolation
                   , fixingCalendar
                   , paymentCalendar)
        {
            if (Calculation.Items == null)
            {
                return;
            }
            var floatingRateCalculation = (FloatingRateCalculation)Calculation.Items[0];
            var floatingRateIndex       = floatingRateCalculation.floatingRateIndex;
            var indexTenor   = floatingRateCalculation.indexTenor.ToString();
            var forecastRate = ForecastRateIndexHelper.Parse(floatingRateIndex.Value, indexTenor);

            VolatilitySurfaceName = CurveNameHelpers.GetRateVolatilityMatrixName(forecastRate);
        }
Esempio n. 18
0
        public override AssetValuation Calculate(IInstrumentControllerData modelData)
        {
            ModelData = modelData;
            AnalyticModelParameters = null;
            AnalyticsModel          = new EquityTransactionAnalytic();
            //1. Create the equity
            UnderlyingEquity = new PriceableEquitySpot(modelData.ValuationDate, NumberOfShares, EquityTypeInfo, SettlementCalendar, Quote);
            //Setting other releavnt information
            SettlementDate = UnderlyingEquity.SettlementDate;
            var metrics         = ResolveModelMetrics(AnalyticsModel.Metrics);
            var metricsAsString = metrics.Select(metric => metric.ToString()).ToList();
            var controllerData  = PriceableAssetFactory.CreateAssetControllerData(metricsAsString.ToArray(), modelData.ValuationDate, modelData.MarketEnvironment);

            UnderlyingEquity.EquityCurveName = CurveNameHelpers.GetEquityCurveName(EquityTypeInfo.Equity.currency.Value, ReferenceEquity);
            UnderlyingEquity.Multiplier      = Multiplier;
            UnderlyingEquity.Calculate(controllerData);
            // store inputs and results from this run
            AnalyticModelParameters      = ((PriceableEquityAssetController)UnderlyingEquity).AnalyticModelParameters;
            AnalyticsModel               = ((PriceableEquityAssetController)UnderlyingEquity).AnalyticsModel;
            CalculationResults           = ((PriceableEquityAssetController)UnderlyingEquity).CalculationResults;
            CalculationPerfomedIndicator = true;
            return(GetValue(CalculationResults, modelData.ValuationDate));
        }
Esempio n. 19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PriceableInterestRateStream"/> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace">The client namespace.</param>
        /// <param name="swapId">The swap Id.</param>
        /// <param name="payerPartyReference">The payer party reference.</param>
        /// <param name="receiverPartyReference">The receiver party reference.</param>
        /// <param name="payerIsBase">The flag for whether the payer reference is the base party.</param>
        /// : AdjustedDateHelper.ToAdjustedDate(forecastRateIndex.indexTenor.Add(AccrualStartDate), AccrualBusinessDayAdjustments);</param>
        /// <param name="paymentCalendar">The paymentCalendar.</param>
        public PriceableLease
        (
            ILogger logger
            , ICoreCache cache
            , String nameSpace
            , string swapId
            , string payerPartyReference
            , string receiverPartyReference
            , bool payerIsBase
            , IBusinessCalendar paymentCalendar)
        {
            Multiplier        = 1.0m;
            Payer             = payerPartyReference;
            Receiver          = receiverPartyReference;
            PayerIsBaseParty  = payerIsBase;
            PaymentCurrencies = new List <string>();
            AnalyticsModel    = new StructuredStreamAnalytic();
            Id = BuildId(swapId, CouponStreamType);
            //Get the currency.
            var currency = XsdClassesFieldResolver.CalculationGetNotionalSchedule(Calculation);

            Currency = currency.notionalStepSchedule.currency;
            if (!PaymentCurrencies.Contains(Currency.Value))
            {
                PaymentCurrencies.Add(Currency.Value);
            }
            //The calendars
            if (paymentCalendar == null)
            {
                paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, PaymentDates.paymentDatesAdjustments.businessCenters, nameSpace);
            }
            //Set the default discount curve name.
            DiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Currency.Value, true);
            RiskMaturityDate  = LastDate();
            logger.LogInfo("Stream built");
        }
Esempio n. 20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PriceableSimpleBond"/> class.
        /// </summary>
        /// <param name="baseDate">The base date.</param>
        /// <param name="nodeStruct">The bond nodeStruct</param>
        /// <param name="settlementCalendar">The settlement Calendar.</param>
        /// <param name="paymentCalendar">The payment Calendar.</param>
        /// <param name="marketQuote">The market quote.</param>
        /// <param name="quoteType">THe quote Type</param>
        public PriceableSimpleBond(DateTime baseDate, BondNodeStruct nodeStruct, IBusinessCalendar settlementCalendar, IBusinessCalendar paymentCalendar,
                                   BasicQuotation marketQuote, BondPriceEnum quoteType)
            : base(baseDate, nodeStruct.Bond.faceAmount, nodeStruct.Bond.currency, nodeStruct.SettlementDate, nodeStruct.ExDivDate, nodeStruct.BusinessDayAdjustments, marketQuote, quoteType)
        {
            Id = nodeStruct.Bond.id;
            var tempId = Id.Split('-');
            var bondId = tempId[0];

            if (tempId.Length > 2)
            {
                bondId = tempId[2];
            }
            SettlementDateCalendar = settlementCalendar;
            Issuer      = (string)nodeStruct.Bond.Item;//Does not handle PartyReference type -> only string!
            Description = "Not Defined";
            //IsYTMQuote = true;
            if (nodeStruct.Bond.description != null)
            {
                Description = nodeStruct.Bond.description;
            }
            MaturityDate   = nodeStruct.Bond.maturity;
            CouponDayCount = new DayCountFraction {
                Value = nodeStruct.Bond.dayCountFraction.Value
            };
            CouponFrequency = new Period
            {
                period           = nodeStruct.Bond.paymentFrequency.period,
                periodMultiplier = nodeStruct.Bond.paymentFrequency.periodMultiplier
            };
            if (nodeStruct.Bond.couponRateSpecified)
            {
                CouponRate = nodeStruct.Bond.couponRate;
            }
            if (nodeStruct.Bond.parValueSpecified)
            {
                ParValue = nodeStruct.Bond.parValue;
            }
            if (nodeStruct.Bond.clearanceSystem != null)
            {
                ClearanceSystem = nodeStruct.Bond.clearanceSystem.Value;
            }
            if (nodeStruct.Bond.exchangeId != null)
            {
                Exchange = nodeStruct.Bond.exchangeId.Value;
            }
            CouponType = CouponTypeEnum.Fixed;
            if (nodeStruct.Bond.seniority != null)
            {
                Seniority = EnumHelper.Parse <CreditSeniorityEnum>(nodeStruct.Bond.seniority.Value, true);
            }
            if (nodeStruct.Bond.instrumentId != null)
            {
                InstrumentIds = new List <InstrumentId>();
                foreach (var identifier in nodeStruct.Bond.instrumentId.Select(id => InstrumentIdHelper.Parse(id.Value)))
                {
                    InstrumentIds.Add(identifier);
                }
            }
            //This handles the case of a bondforward used in curve building.
            if (MaturityDate > BaseDate)
            {
                DateTime lastCouponDate;
                DateTime nextCouponDate;
                var      rollConvention =
                    RollConventionEnumHelper.Parse(MaturityDate.Day.ToString(CultureInfo.InvariantCulture));
                Frequency = FrequencyHelper.ToFrequency(nodeStruct.Bond.paymentFrequency);
                //Get the settlement date
                SettlementDate = GetSettlementDate(baseDate, settlementCalendar, nodeStruct.SettlementDate);
                //Generate the necessary dates.
                //TODO Should the settlement date and the underlying bond be calculated on the fly when calculation occurs?
                UnAdjustedPeriodDates = DateScheduler.GetUnadjustedCouponDatesFromMaturityDate(SettlementDate,
                                                                                               MaturityDate,
                                                                                               CouponFrequency,
                                                                                               rollConvention,
                                                                                               out lastCouponDate,
                                                                                               out nextCouponDate);
                LastCouponDate      = UnAdjustedPeriodDates[0];
                NextCouponDate      = nextCouponDate;
                AdjustedPeriodDates =
                    AdjustedDateScheduler.GetAdjustedDateSchedule(UnAdjustedPeriodDates,
                                                                  nodeStruct.BusinessDayAdjustments
                                                                  .businessDayConvention, paymentCalendar)
                    .ToArray();
                AdjustedPeriodDates[0] = SettlementDate; //TODO check this!
                NextExDivDate          = GetNextExDivDate();
                IsXD = IsExDiv();
            }
            BondCurveName         = CurveNameHelpers.GetBondCurveName(Currency.Value, bondId);
            SwapDiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Currency.Value, true);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PriceableInterestRateStream"/> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace">The client namesspace.</param>
        /// <param name="swapId">The swap Id.</param>
        /// <param name="payerPartyReference">The payer party reference.</param>
        /// <param name="receiverPartyReference">The receiver party reference.</param>
        /// <param name="payerIsBase">The flag for whether the payerreference is the base party.</param>
        /// <param name="calculationPeriodDates">The caluclation period date information.</param>
        /// <param name="paymentDates">The payment dates of the swap leg.</param>
        /// <param name="resetDates">The reset dates of the swap leg.</param>
        /// <param name="principalExchanges">The principal Exchange type.</param>
        /// <param name="calculationPeriodAmount">The calculation period amount data.</param>
        /// <param name="stubCalculationPeriodAmount">The stub calculation information.</param>
        /// <param name="cashflows">The FpML cashflows for that stream.</param>
        /// <param name="settlementProvision">The settlement provision data.</param>
        /// <param name="forecastRateInterpolation">ForwardEndDate = forecastRateInterpolation ? AccrualEndDate
        /// : AdjustedDateHelper.ToAdjustedDate(forecastRateIndex.indexTenor.Add(AccrualStartDate), AccrualBusinessDayAdjustments);</param>
        /// <param name="fixingCalendar">The fixingCalendar.</param>
        /// <param name="paymentCalendar">The paymentCalendar.</param>
        public PriceableInterestRateStream
        (
            ILogger logger
            , ICoreCache cache
            , String nameSpace
            , string swapId
            , string payerPartyReference
            , string receiverPartyReference
            , bool payerIsBase
            , CalculationPeriodDates calculationPeriodDates
            , PaymentDates paymentDates
            , ResetDates resetDates
            , PrincipalExchanges principalExchanges
            , CalculationPeriodAmount calculationPeriodAmount
            , StubCalculationPeriodAmount stubCalculationPeriodAmount
            , Cashflows cashflows
            , SettlementProvision settlementProvision
            , bool forecastRateInterpolation
            , IBusinessCalendar fixingCalendar
            , IBusinessCalendar paymentCalendar)
        {
            Multiplier              = 1.0m;
            Payer                   = payerPartyReference;
            Receiver                = receiverPartyReference;
            PayerIsBaseParty        = payerIsBase;
            CalculationPeriodDates  = calculationPeriodDates;
            PaymentDates            = paymentDates;
            PaymentCurrencies       = new List <string>();
            ResetDates              = resetDates;
            PrincipalExchanges      = principalExchanges;
            CalculationPeriodAmount = calculationPeriodAmount;
            AnalyticsModel          = new StructuredStreamAnalytic();
            Calculation             = (Calculation)CalculationPeriodAmount.Item;
            if (Calculation.Items?[0] is Schedule strikeSchedule)
            {
                Strike = strikeSchedule.initialValue;//Only picks up the first fixed rate for the swaption calculation.
            }
            StubCalculationPeriodAmount = stubCalculationPeriodAmount;
            Cashflows        = cashflows;
            CouponStreamType = CouponTypeFromCalculation(Calculation);
            Id = BuildId(swapId, CouponStreamType);
            ForecastRateInterpolation = forecastRateInterpolation;
            var isThereDiscounting = XsdClassesFieldResolver.CalculationHasDiscounting(Calculation);

            if (isThereDiscounting)
            {
                IsDiscounted = true; //TODO need to include rate logic for the correct solved answers. What about reset cashflows??
            }
            //Get the currency.
            var currency = XsdClassesFieldResolver.CalculationGetNotionalSchedule(Calculation);

            Currency = currency.notionalStepSchedule.currency;
            if (!PaymentCurrencies.Contains(Currency.Value))
            {
                PaymentCurrencies.Add(Currency.Value);
            }
            //The calendars
            if (paymentCalendar == null)
            {
                paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, PaymentDates.paymentDatesAdjustments.businessCenters, nameSpace);
            }
            SettlementProvision = settlementProvision;
            //Set the default discount curve name.
            DiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Currency.Value, true);
            //Set the forecast curve name.//TODO extend this to the other types.
            if (CouponStreamType != CouponStreamType.GenericFixedRate)
            {
                if (fixingCalendar == null)
                {
                    fixingCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, ResetDates.resetDatesAdjustments.businessCenters, nameSpace);
                }
                ForecastCurveName = null;
                if (Calculation.Items != null)
                {
                    var floatingRateCalculation = Calculation.Items;
                    var floatingRateIndex       = (FloatingRateCalculation)floatingRateCalculation[0];
                    ForecastCurveName = CurveNameHelpers.GetForecastCurveName(floatingRateIndex);
                }
            }
            //Build the coupons and principal exchanges.
            if (GetCashflowPaymentCalculationPeriods() != null)
            {
                Coupons = PriceableInstrumentsFactory.CreatePriceableCoupons(PayerIsBaseParty,
                                                                             GetCashflowPaymentCalculationPeriods(),
                                                                             Calculation, ForecastRateInterpolation, fixingCalendar, paymentCalendar);//TODO add the stubcalculation.
                UpdateCouponIds();
            }
            if (GetCashflowPrincipalExchanges() != null)
            {
                var exchanges = GetCashflowPrincipalExchanges();
                Exchanges = PriceableInstrumentsFactory.CreatePriceablePrincipalExchanges(PayerIsBaseParty, exchanges, Currency.Value, paymentCalendar);
                UpdateExchangeIds();
            }
            RiskMaturityDate = LastDate();
            logger.LogInfo("Stream built");
        }
Esempio n. 22
0
        public FutureTransactionPricer(ILogger logger, ICoreCache cache, string nameSpace, DateTime tradeDate, ExchangeContractTypeEnum futuresType,
                                       IBusinessCalendar settlementCalendar, FutureTransaction futureFpML, string basePartyReference, Boolean forecastRateInterpolation)
        {
            logger.LogInfo("FuturesType set. Commence to build a future transaction.");
            if (futureFpML == null)
            {
                return;
            }
            Multiplier        = 1.0m;
            BuyerReference    = futureFpML.buyerPartyReference.href;
            PaymentCurrencies = new List <string> {
                futureFpML.unitPrice.currency.Value
            };
            SellerReference = futureFpML.sellerPartyReference.href;
            BasePartyBuyer  = basePartyReference == futureFpML.buyerPartyReference.href;
            if (!BasePartyBuyer)
            {
                Multiplier = -1.0m;
            }
            ForecastRateInterpolation = forecastRateInterpolation;
            SettlementCalendar        = settlementCalendar;
            FuturesType       = futuresType;
            ReferenceContract = futureFpML.future.id;
            var futuresCode = ReferenceContract.Split('-')[2];

            NumberOfContracts = Convert.ToInt16(futureFpML.numberOfUnits);
            PurchasePrice     = MoneyHelper.GetAmount(futureFpML.unitPrice.amount, futureFpML.unitPrice.currency.Value);
            var exchangeMIC = futureFpML.future.exchangeId;

            FuturesCurveName  = CurveNameHelpers.GetExchangeTradedCurveName(futureFpML.unitPrice.currency.Value, exchangeMIC.Value, futuresCode);
            DiscountCurveName = CurveNameHelpers.GetDiscountCurveName(futureFpML.unitPrice.currency, true);
            FuturesTypeInfo   = new FutureNodeStruct();
            var exchangeMICData = InstrumentDataHelper.CreateEquityExchangeKey(nameSpace, exchangeMIC.Value);
            var exchangeData    = cache.LoadItem <ExchangeConfigData>(exchangeMICData);

            if (exchangeData?.Data is ExchangeConfigData)
            {
                Exchange = (ExchangeConfigData)exchangeData.Data;
                FuturesTypeInfo.SpotDate = Exchange.SettlementDate;
            }
            if (futureFpML.future != null)
            {
                if (SettlementCalendar == null)
                {
                    SettlementCalendar = BusinessCenterHelper.ToBusinessCalendar(cache,
                                                                                 FuturesTypeInfo.SpotDate
                                                                                 .businessCenters,
                                                                                 nameSpace);
                }
                var future = XmlSerializerHelper.Clone(futureFpML.future);
                FuturesTypeInfo.Future = future;
                if (FuturesTypeInfo.SpotDate != null)
                {
                    SettlementDate = GetSettlementDate(tradeDate, SettlementCalendar,
                                                       FuturesTypeInfo.SpotDate);
                }
                //Instantiate the priceable future.
                NamedValueSet namedValueSet = PriceableAssetFactory.BuildPropertiesForAssets(nameSpace, FuturesTypeInfo.Future.id, tradeDate);
                var           asset         = AssetHelper.Parse(FuturesTypeInfo.Future.id, 0.0m, 0.0m);
                UnderlyingFuture = PriceableAssetFactory.Create(logger, cache, nameSpace, asset.Second, namedValueSet, null, null) as IPriceableFuturesAssetController;
                if (UnderlyingFuture != null)
                {
                    RiskMaturityDate = UnderlyingFuture.GetRiskMaturityDate();
                    MaturityDate     = RiskMaturityDate;
                    LastTradeDate    = UnderlyingFuture.LastTradeDate;
                }
                if (!PaymentCurrencies.Contains(futureFpML.future.currency.Value))
                {
                    PaymentCurrencies.Add(futureFpML.future.currency.Value);
                }
                logger.LogInfo("Futures transaction has been successfully created.");
            }
            else
            {
                logger.LogInfo("Futures type data not available.");
            }
            //Add payments like the settlement price
            if (!PurchasePrice.amountSpecified)
            {
                return;
            }
            var amount            = PurchasePrice.amount * NumberOfContracts / 100;
            var settlementPayment = PaymentHelper.Create("FuturesSettlemetAmount", BuyerReference, SellerReference, amount, SettlementDate);

            AdditionalPayments = PriceableInstrumentsFactory.CreatePriceablePayments(basePartyReference, new[] { settlementPayment }, SettlementCalendar);
            if (!PaymentCurrencies.Contains(settlementPayment.paymentAmount.currency.Value))
            {
                PaymentCurrencies.Add(settlementPayment.paymentAmount.currency.Value);
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PriceableSimpleBond"/> class.
        /// </summary>
        /// <param name="baseDate">The base date.</param>
        /// <param name="bond">The bond</param>
        /// <param name="settlementDate">The settlement date.</param>
        /// <param name="exDivDate">The ex dividend date.</param>
        /// <param name="businessDayAdjustments">The business day adjustments.</param>
        /// <param name="paymentCalendar">The payment Calendar.</param>
        /// <param name="marketQuote">The market quote.</param>
        /// <param name="quoteType">The quote type</param>
        public PriceableSimpleBond(DateTime baseDate, Bond bond, DateTime settlementDate, DateTime exDivDate,
                                   BusinessDayAdjustments businessDayAdjustments, IBusinessCalendar paymentCalendar, BasicQuotation marketQuote, BondPriceEnum quoteType)
            : base(baseDate, bond.faceAmount, bond.currency, null, null, businessDayAdjustments, marketQuote, quoteType)
        {
            Id = bond.id;
            var tempId = Id.Split('-');
            var bondId = tempId[0];

            if (tempId.Length > 2)
            {
                bondId = tempId[2];
            }
            Issuer      = (string)bond.Item;//Does not handle PartyReference type -> only string!
            Description = "Not Defined";
            if (bond.description != null)
            {
                Description = bond.description;
            }
            MaturityDate   = bond.maturity;
            CouponDayCount = new DayCountFraction {
                Value = bond.dayCountFraction.Value
            };
            if (bond.parValueSpecified)
            {
                ParValue = bond.parValue;
            }
            if (bond.couponRateSpecified)
            {
                CouponRate = bond.couponRate;
            }
            CouponFrequency = new Period
            {
                period           = bond.paymentFrequency.period,
                periodMultiplier = bond.paymentFrequency.periodMultiplier
            };
            CouponType = CouponTypeEnum.Fixed;
            if (bond.clearanceSystem != null)
            {
                ClearanceSystem = bond.clearanceSystem.Value;
            }
            if (bond.exchangeId != null)
            {
                Exchange = bond.exchangeId.Value;
            }
            if (bond.seniority != null)
            {
                Seniority = EnumHelper.Parse <CreditSeniorityEnum>(bond.seniority.Value);
            }
            if (bond.instrumentId != null)
            {
                InstrumentIds = new List <InstrumentId>();
                foreach (var identifier in bond.instrumentId.Select(id => InstrumentIdHelper.Parse(id.Value)))
                {
                    InstrumentIds.Add(identifier);
                }
            }
            //This handles the case of a bond forward used in curve building.
            if (MaturityDate > BaseDate)
            {
                var rollConvention =
                    RollConventionEnumHelper.Parse(MaturityDate.Day.ToString(CultureInfo.InvariantCulture));
                Frequency             = FrequencyHelper.ToFrequency(bond.paymentFrequency);
                SettlementDate        = settlementDate;
                UnAdjustedPeriodDates = DateScheduler.GetUnadjustedCouponDatesFromMaturityDate(SettlementDate,
                                                                                               MaturityDate,
                                                                                               CouponFrequency,
                                                                                               rollConvention,
                                                                                               out _,
                                                                                               out var nextCouponDate);
                LastCouponDate      = UnAdjustedPeriodDates[0];
                NextCouponDate      = nextCouponDate;
                AdjustedPeriodDates =
                    AdjustedDateScheduler.GetAdjustedDateSchedule(UnAdjustedPeriodDates,
                                                                  PaymentBusinessDayAdjustments.businessDayConvention,
                                                                  paymentCalendar).ToArray();
                AdjustedPeriodDates[0] = SettlementDate;
                NextExDivDate          = exDivDate;
                IsXD = IsExDiv();
            }
            BondCurveName         = CurveNameHelpers.GetBondCurveName(Currency.Value, bondId);
            SwapDiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Currency.Value, true);
        }
Esempio n. 24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableCapFloorCoupon"/> class.
 /// </summary>
 /// <param name="cashFlowId">The stream id.</param>
 /// <param name="buyerIsBase">The buyer is base flag.</param>
 /// <param name="capStrike">The Cap strike.</param>
 /// <param name="floorStrike">The floor strike.</param>
 /// <param name="accrualStartDate">The accrual start date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="accrualEndDate">The accrual end date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="adjustAccrualDatesIndicator">if set to <c>true</c> [adjust calculation dates indicator].</param>
 /// <param name="accrualBusinessCenters">The accrual business centers.</param>
 /// <param name="margin">The margin.</param>
 /// <param name="observedRate">The observed Rate.</param>
 /// <param name="notionalAmount">The notional amount.</param>
 /// <param name="dayCountFraction">Type of day Count fraction.</param>
 /// <param name="paymentDate">The payment date.</param>
 /// <param name="accrualRollConvention">The accrual roll convention.</param>
 /// <param name="resetRelativeTo">reset relative to?</param>
 /// <param name="fixingDateRelativeOffset">The fixing date offset.</param>
 /// <param name="forecastRateIndex">The forecast rate index.</param>
 /// <param name="discountingType">The swap discounting type.</param>
 /// <param name="discountRate">The discount rate.</param>
 /// <param name="fraDiscounting">Determines whether the coupon is discounted or not. If this parameter is null,
 /// then it is assumed that there is no fra discounting</param>
 /// <param name="fixingCalendar">The fixingCalendar.</param>
 /// <param name="paymentCalendar">The paymentCalendar.</param>
 public PriceableCapFloorCoupon
 (
     string cashFlowId
     , bool buyerIsBase
     , decimal?capStrike
     , decimal?floorStrike
     , DateTime accrualStartDate
     , DateTime accrualEndDate
     , Boolean adjustAccrualDatesIndicator
     , BusinessCenters accrualBusinessCenters
     , BusinessDayConventionEnum accrualRollConvention
     , DayCountFraction dayCountFraction
     , ResetRelativeToEnum resetRelativeTo
     , RelativeDateOffset fixingDateRelativeOffset
     , Decimal margin
     , Decimal?observedRate
     , Money notionalAmount
     , AdjustableOrAdjustedDate paymentDate
     , ForecastRateIndex forecastRateIndex
     , DiscountingTypeEnum?discountingType
     , Decimal?discountRate
     , FraDiscountingEnum?fraDiscounting
     , IBusinessCalendar fixingCalendar
     , IBusinessCalendar paymentCalendar)
     : base(
         cashFlowId
         , buyerIsBase
         , accrualStartDate
         , accrualEndDate
         , adjustAccrualDatesIndicator
         , accrualBusinessCenters
         , accrualRollConvention
         , dayCountFraction
         , resetRelativeTo
         , fixingDateRelativeOffset
         , margin
         , observedRate
         , notionalAmount
         , paymentDate
         , forecastRateIndex
         , discountingType
         , discountRate
         , fraDiscounting
         , fixingCalendar
         , paymentCalendar)
 {
     CapStrike             = capStrike;
     FloorStrike           = floorStrike;
     VolatilitySurfaceName = CurveNameHelpers.GetRateVolatilityMatrixName(forecastRateIndex);
     if (capStrike != null && floorStrike == null)
     {
         PriceableCouponType = CouponType.Cap;
         ModelIdentifier     = "DualCurveCapModel";
         IsCall = true;
     }
     if (floorStrike != null && capStrike == null)
     {
         PriceableCouponType = CouponType.Floor;
         ModelIdentifier     = "DualCurveFloorModel";
     }
     if (floorStrike != null && capStrike != null)
     {
         PriceableCouponType = CouponType.Collar;
         ModelIdentifier     = "DualCurveCollarModel";
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="nameSpace"></param>
        /// <param name="tradeDate"></param>
        /// <param name="settlementDate">The payment settlement date.</param>
        /// <param name="settlementCalendar"></param>
        /// <param name="paymentCalendar"></param>
        /// <param name="bondFpML"></param>
        /// <param name="basePartyReference"></param>
        /// <param name="bondType"></param>
        /// <param name="forecastRateInterpolation"></param>
        public BondTransactionPricer(ILogger logger, ICoreCache cache, string nameSpace, DateTime tradeDate,
                                     DateTime settlementDate, IBusinessCalendar settlementCalendar, IBusinessCalendar paymentCalendar,
                                     BondTransaction bondFpML, string basePartyReference, string bondType, bool forecastRateInterpolation)
        {
            Multiplier = 1.0m;
            TradeDate  = tradeDate;
            BondType   = EnumHelper.Parse <BondTypesEnum>(bondType);
            logger.LogInfo("BondType set. Commence to build a bond transaction.");
            if (bondFpML == null)
            {
                return;
            }
            BuyerReference    = bondFpML.buyerPartyReference.href;
            PaymentCurrencies = new List <string> {
                bondFpML.notionalAmount.currency.Value
            };
            SellerReference = bondFpML.sellerPartyReference.href;
            BasePartyBuyer  = basePartyReference == bondFpML.buyerPartyReference.href;
            if (!BasePartyBuyer)
            {
                Multiplier = -1.0m;
            }
            ForecastRateInterpolation = forecastRateInterpolation;
            SettlementCalendar        = settlementCalendar;
            PaymentCalendar           = paymentCalendar;
            //Set the bond price information
            BondPrice = new BondPrice();
            if (bondFpML.price.accrualsSpecified)
            {
                BondPrice.accrualsSpecified = true;
                BondPrice.accruals          = bondFpML.price.accruals;
            }
            if (bondFpML.price.dirtyPriceSpecified)
            {
                BondPrice.dirtyPriceSpecified = true;
                BondPrice.dirtyPrice          = bondFpML.price.dirtyPrice;
            }
            BondPrice.cleanOfAccruedInterest = bondFpML.price.cleanOfAccruedInterest;
            BondPrice.cleanPrice             = bondFpML.price.cleanPrice;
            //Set the currencies
            CouponCurrency  = bondFpML.notionalAmount.currency;
            PaymentCurrency = bondFpML.notionalAmount.currency;//This could be another currency!
            //Set the notional information
            NotionalAmount = MoneyHelper.GetAmount(bondFpML.notionalAmount.amount, bondFpML.notionalAmount.currency.Value);
            //Determines the quotation and units
            QuoteType = BondPriceEnum.YieldToMaturity;
            //We need to get the ytm in until there is a bond market price/spread.
            if (BondPrice.dirtyPriceSpecified)
            {
                QuoteType = BondPriceEnum.DirtyPrice;
                Quote     = BasicQuotationHelper.Create(BondPrice.dirtyPrice, RateQuotationType);
            }
            //Get the instrument configuration information.
            var            assetIdentifier = bondFpML.bond.currency.Value + "-Bond-" + BondType;
            BondNodeStruct bondTypeInfo    = null;
            //TODO Set the swap curves for asset swap valuation.
            //
            //Gets the template bond type
            var instrument = InstrumentDataHelper.GetInstrumentConfigurationData(cache, nameSpace, assetIdentifier);

            if (instrument != null)
            {
                bondTypeInfo = instrument.InstrumentNodeItem as BondNodeStruct;
            }
            if (bondFpML.bond != null && bondTypeInfo != null)
            {
                if (SettlementCalendar == null)
                {
                    SettlementCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, bondTypeInfo.SettlementDate.businessCenters, nameSpace);
                }
                if (PaymentCalendar == null)
                {
                    PaymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, bondTypeInfo.BusinessDayAdjustments.businessCenters, nameSpace);
                }
                //Pre-processes the data for the priceable asset.
                var bond = XmlSerializerHelper.Clone(bondFpML.bond);
                Bond = bond;
                bondTypeInfo.Bond = Bond;
                //Set the curves to use for valuations.
                BondCurveName = CurveNameHelpers.GetBondCurveName(Bond.currency.Value, Bond.id);
                //THe discount curve is only for credit calculations.
                DiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Bond.currency.Value, true);
                if (bond.maturitySpecified)
                {
                    MaturityDate = bond.maturity;
                }
                SettlementDateConvention = bondTypeInfo.SettlementDate;
                BusinessDayAdjustments   = bondTypeInfo.BusinessDayAdjustments;
                ExDivDateConvention      = bondTypeInfo.ExDivDate;
                //This is done because the config data is not stored in the correct way. Need to add a price quote units.
                if (bond.couponRateSpecified)
                {
                    var coupon = bond.couponRate;
                    Bond.couponRate = coupon;
                }
                bondTypeInfo.Bond.faceAmount          = NotionalAmount.amount;
                bondTypeInfo.Bond.faceAmountSpecified = true;
                Bond.faceAmount = NotionalAmount.amount;
                if (Bond.maturitySpecified)
                {
                    RiskMaturityDate = Bond.maturity;
                }
                SettlementDate = settlementDate;
                if (!PaymentCurrencies.Contains(bondFpML.bond.currency.Value))
                {
                    PaymentCurrencies.Add(bondFpML.bond.currency.Value);
                }
                logger.LogInfo("Bond transaction has been successfully created.");
            }
            else
            {
                logger.LogInfo("Bond type data not available.");
            }
            //Set the underlying bond
            UnderlyingBond = new PriceableSimpleBond(tradeDate, bondTypeInfo, SettlementCalendar, PaymentCalendar, Quote, QuoteType);
            BondIssuer     = UnderlyingBond.Issuer;
            if (BondPrice.dirtyPriceSpecified)
            {
                UnderlyingBond.PurchasePrice = BondPrice.dirtyPrice / 100; //PriceQuoteUnits
            }
            //Set the coupons
            var bondId = Bond.id;//Could use one of the instrumentIds

            //bondStream is an interest Rate Stream but needs to be converted to a bond stream.
            //It automatically contains the coupon currency.
            Coupons = new PriceableBondCouponRateStream(logger, cache, nameSpace, bondId, tradeDate,
                                                        bondFpML.notionalAmount.amount, CouponStreamType.GenericFixedRate, Bond,
                                                        BusinessDayAdjustments, ForecastRateInterpolation, null, PaymentCalendar);
            //Add payments like the settlement price
            if (!BondPrice.dirtyPriceSpecified)
            {
                return;
            }
            var amount            = BondPrice.dirtyPrice * NotionalAmount.amount / 100;
            var settlementPayment = PaymentHelper.Create(BuyerReference, SellerReference, PaymentCurrency.Value, amount, SettlementDate);

            AdditionalPayments = PriceableInstrumentsFactory.CreatePriceablePayments(basePartyReference, new[] { settlementPayment }, SettlementCalendar);
            //
            var finalPayment = PaymentHelper.Create(BondIssuer, BuyerReference, CouponCurrency.Value, NotionalAmount.amount, RiskMaturityDate);

            FinalRedemption =
                PriceableInstrumentsFactory.CreatePriceablePayment(basePartyReference, finalPayment, PaymentCalendar);
            AdditionalPayments.Add(FinalRedemption);
            if (!PaymentCurrencies.Contains(settlementPayment.paymentAmount.currency.Value))
            {
                PaymentCurrencies.Add(settlementPayment.paymentAmount.currency.Value);
            }
        }