Esempio n. 1
0
        protected SwapPricer(ILogger logger, ICoreCache cache, String nameSpace,
                             List <Pair <IBusinessCalendar, IBusinessCalendar> > legCalendars,
                             Swap swapFpML, string basePartyReference,
                             ProductTypeSimpleEnum productType, Boolean forecastRateInterpolation)
        {
            Multiplier = 1.0m;
            if (swapFpML == null)
            {
                return;
            }
            BusinessCentersResolver.ResolveBusinessCenters(swapFpML);
            ForecastRateInterpolation = forecastRateInterpolation;
            //Get the effective date
            AdjustableDate adjustableEffectiveDate = XsdClassesFieldResolver.CalculationPeriodDatesGetEffectiveDate(swapFpML.swapStream[0].calculationPeriodDates);

            EffectiveDate = adjustableEffectiveDate.unadjustedDate.Value;
            //We make the assumption that the termination date is the same for all legs.
            AdjustableDate adjustableTerminationDate = XsdClassesFieldResolver.CalculationPeriodDatesGetTerminationDate(swapFpML.swapStream[0].calculationPeriodDates);
            var            paymentCalendar           = BusinessCenterHelper.ToBusinessCalendar(cache, adjustableTerminationDate.dateAdjustments.businessCenters, nameSpace);

            TerminationDate  = AdjustedDateHelper.ToAdjustedDate(paymentCalendar, adjustableTerminationDate);
            RiskMaturityDate = TerminationDate;
            //EffectiveDate is not set;
            ProductType       = productType;
            PaymentCurrencies = new List <string>();
            //Resolve the payer
            var legs = swapFpML.swapStream.Length;

            if (legs == 0)
            {
                return;
            }
            var flag  = false;
            var index = 0;

            if (legCalendars != null && legCalendars.Count == legs)
            {
                flag = true;
            }
            foreach (var swapStream in swapFpML.swapStream)
            {
                bool payerIsBase = basePartyReference == swapStream.payerPartyReference.href;//TODO add in the calendar functionality.
                //Set the id of the first stream.
                PriceableInterestRateStream leg = flag ? new PriceableInterestRateStream(logger, cache, nameSpace, payerIsBase, swapStream, ForecastRateInterpolation, legCalendars[index].First, legCalendars[index].Second)
                    : new PriceableInterestRateStream(logger, cache, nameSpace, payerIsBase, swapStream, ForecastRateInterpolation, null, null);
                Legs.Add(leg);
                //Add the currencies for the trade pricer.
                if (!PaymentCurrencies.Contains(leg.Currency.Value))
                {
                    PaymentCurrencies.Add(leg.Currency.Value);
                }
                index++;
            }
            if (swapFpML.additionalPayment != null)
            {
                AdditionalPayments = PriceableInstrumentsFactory.CreatePriceablePayments(basePartyReference, swapFpML.additionalPayment, null);
                foreach (var payment in swapFpML.additionalPayment)
                {
                    if (!PaymentCurrencies.Contains(payment.paymentAmount.currency.Value))
                    {
                        PaymentCurrencies.Add(payment.paymentAmount.currency.Value);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="paymentCalendar"> </param>
        /// <param name="capFloorFpML"></param>
        /// <param name="basePartyReference"></param>
        /// <param name="forecastRateInterpolation"></param>
        /// <param name="nameSpace"></param>
        /// <param name="fixingCalendar"> </param>
        public CapFloorPricer(ILogger logger, ICoreCache cache, String nameSpace,
                              IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar,
                              CapFloor capFloorFpML, string basePartyReference, Boolean forecastRateInterpolation)
        {
            if (capFloorFpML == null)
            {
                return;
            }
            //AnalyticsModel = new SimpleIRSwapInstrumentAnalytic();
            BusinessCentersResolver.ResolveBusinessCenters(capFloorFpML);
            ForecastRateInterpolation = forecastRateInterpolation;
            //We make the assumption that the termination date is the same for all legs..
            AdjustableDate adjustableTerminationDate = XsdClassesFieldResolver.CalculationPeriodDatesGetTerminationDate(capFloorFpML.capFloorStream.calculationPeriodDates);

            if (paymentCalendar == null)
            {
                paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, adjustableTerminationDate.dateAdjustments.businessCenters, nameSpace);
            }
            RiskMaturityDate  = AdjustedDateHelper.ToAdjustedDate(paymentCalendar, adjustableTerminationDate);
            ProductType       = ProductTypeSimpleEnum.CapFloor;
            PaymentCurrencies = new List <string>();
            //Resolve the payer
            if (capFloorFpML.capFloorStream == null)
            {
                return;
            }
            var calculation             = capFloorFpML.capFloorStream.calculationPeriodAmount.Item as Calculation;
            var floatingRatecalculation = calculation?.Items[0] as FloatingRateCalculation;

            if (floatingRatecalculation == null)
            {
                return;
            }
            if (floatingRatecalculation.capRateSchedule != null)
            {
                var schedule            = floatingRatecalculation.capRateSchedule[0];
                var buyerPartyReference = schedule.buyer.Value;
                if (buyerPartyReference == PayerReceiverEnum.Receiver)
                {
                    BuyerPartyReference  = capFloorFpML.capFloorStream.receiverPartyReference.href;
                    SellerPartyReference = capFloorFpML.capFloorStream.payerPartyReference.href;
                }
                else
                {
                    BuyerPartyReference  = capFloorFpML.capFloorStream.payerPartyReference.href;
                    SellerPartyReference = capFloorFpML.capFloorStream.receiverPartyReference.href;
                }
            }
            if (floatingRatecalculation.capRateSchedule == null && floatingRatecalculation.floorRateSchedule != null)
            {
                var schedule            = floatingRatecalculation.floorRateSchedule[0];
                var buyerPartyReference = schedule.buyer.Value;
                if (buyerPartyReference == PayerReceiverEnum.Receiver)
                {
                    BuyerPartyReference  = capFloorFpML.capFloorStream.receiverPartyReference.href;
                    SellerPartyReference = capFloorFpML.capFloorStream.payerPartyReference.href;
                }
                else
                {
                    BuyerPartyReference  = capFloorFpML.capFloorStream.payerPartyReference.href;
                    SellerPartyReference = capFloorFpML.capFloorStream.receiverPartyReference.href;
                }
            }
            BasePartyBuyer = basePartyReference == BuyerPartyReference;//TODO add in the calendar functionality.
            //Set the id of the first stream. THe generator requires the flag: BasePartyPayer.
            var capFloorLeg = new PriceableCapFloorStream(logger, cache, nameSpace, !BasePartyBuyer, capFloorFpML.capFloorStream, ForecastRateInterpolation, fixingCalendar, paymentCalendar);

            Legs.Add(capFloorLeg);
            //Add the currencies for the trade pricer.
            if (!PaymentCurrencies.Contains(capFloorLeg.Currency.Value))
            {
                PaymentCurrencies.Add(capFloorLeg.Currency.Value);
            }
            if (capFloorFpML.additionalPayment != null)
            {
                AdditionalPayments = PriceableInstrumentsFactory.CreatePriceablePayments(basePartyReference, capFloorFpML.additionalPayment, null);
                foreach (var payment in capFloorFpML.additionalPayment)
                {
                    if (!PaymentCurrencies.Contains(payment.paymentAmount.currency.Value))
                    {
                        PaymentCurrencies.Add(payment.paymentAmount.currency.Value);
                    }
                }
            }
        }