Esempio n. 1
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);
 }
 /// <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);
 }
 /// <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>
        ///
        /// </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);
 }
        /// <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");
        }