public static void SetFloorRateSchedule(InterestRateStream stream, Schedule floorRateSchedule, bool isReceiverBuyer)
        {
            Calculation             calculation             = XsdClassesFieldResolver.CalculationPeriodAmountGetCalculation(stream.calculationPeriodAmount);
            FloatingRateCalculation floatingRateCalculation = XsdClassesFieldResolver.CalculationGetFloatingRateCalculation(calculation);
            var schedule = new StrikeSchedule
            {
                initialValue = floorRateSchedule.initialValue,
                step         = floorRateSchedule.step
            };

            floatingRateCalculation.floorRateSchedule = new[] { schedule };
            if (isReceiverBuyer)
            {
                floatingRateCalculation.floorRateSchedule[0].buyer = new IdentifiedPayerReceiver {
                    Value = PayerReceiverEnum.Receiver
                };
                floatingRateCalculation.floorRateSchedule[0].seller = new IdentifiedPayerReceiver {
                    Value = PayerReceiverEnum.Payer
                };
            }
            else
            {
                floatingRateCalculation.floorRateSchedule[0].buyer = new IdentifiedPayerReceiver {
                    Value = PayerReceiverEnum.Payer
                };
                floatingRateCalculation.floorRateSchedule[0].seller = new IdentifiedPayerReceiver {
                    Value = PayerReceiverEnum.Receiver
                };
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Updates forecastRate, forecastPaymentAmount, discountFactor and presentValueAmount of each paymentCalculation period.
        /// </summary>
        /// <param name="interestRateStream">The interest rate stream.</param>
        /// <param name="forecastCurve">The forecast curve.</param>
        /// <param name="discountCurve">The discount curve.</param>
        /// <param name="valuationDate">The valuation date.</param>
        public static void UpdateCashflowsAmounts(InterestRateStream interestRateStream,
                                                  IRateCurve forecastCurve, IRateCurve discountCurve,
                                                  DateTime valuationDate)
        {
            //FixAfterManualUpdate(interestRateStream);//should it be removed, since it might produce subtle errors which will be effectively hidden.
            Calculation calculation = XsdClassesFieldResolver.CalculationPeriodAmountGetCalculation(interestRateStream.calculationPeriodAmount);

            UpdateNumberOfDaysAndYearFraction(new List <PaymentCalculationPeriod>(interestRateStream.cashflows.paymentCalculationPeriod), calculation);
            FloatingRateCalculation floatingRateCalculation =
                XsdClassesFieldResolver.CalculationHasFloatingRateCalculation(calculation)
                    ? XsdClassesFieldResolver.CalculationGetFloatingRateCalculation(calculation) : null;

            // calculate forecast payment amount for each payment calculation period
            //
            foreach (PaymentCalculationPeriod period in interestRateStream.cashflows.paymentCalculationPeriod)
            {
                CalculateForecastPaymentAmount(calculation, floatingRateCalculation, period, forecastCurve, discountCurve, valuationDate);
            }
            //  principle exchanges
            //
            if (interestRateStream.cashflows.principalExchange != null)
            {
                foreach (PrincipalExchange principalExchange in interestRateStream.cashflows.principalExchange)
                {
                    CalculateForecastPaymentAmount(principalExchange, discountCurve, valuationDate);
                }
            }
        }
        public static void SetSpreadSchedule(InterestRateStream stream, Schedule spreadSchedule)
        {
            Calculation             calculation             = XsdClassesFieldResolver.CalculationPeriodAmountGetCalculation(stream.calculationPeriodAmount);
            FloatingRateCalculation floatingRateCalculation = XsdClassesFieldResolver.CalculationGetFloatingRateCalculation(calculation);
            var schedule = new SpreadSchedule {
                initialValue = spreadSchedule.initialValue, step = spreadSchedule.step
            };

            floatingRateCalculation.spreadSchedule = new[] { schedule };
        }
        private static void UpdateCalculationPeriodData(Calculation calculation, CalculationPeriod calculationPeriod, Notional notionalSchedule)
        {
            bool hasFloatingRateCalculation = XsdClassesFieldResolver.CalculationHasFloatingRateCalculation(calculation);
            bool hasFixedRate = XsdClassesFieldResolver.CalculationHasFixedRateSchedule(calculation);

            if (!(hasFloatingRateCalculation ^ hasFixedRate))
            {
                throw new System.Exception("at least one type of rate (floating or fixed) must be specified.");
            }
            decimal notional = NotionalHelper.GetNotionalValue(notionalSchedule, calculationPeriod.adjustedStartDate);

            // Notional amount
            //
            XsdClassesFieldResolver.CalculationPeriodSetNotionalAmount(calculationPeriod, notional);
            // Fixed rate
            //
            if (hasFixedRate)
            {
                Schedule fixedRateSchedule = XsdClassesFieldResolver.CalculationGetFixedRateSchedule(calculation);
                decimal  fixedRate         = ScheduleHelper.GetValue(fixedRateSchedule, calculationPeriod.adjustedStartDate);
                XsdClassesFieldResolver.SetCalculationPeriodFixedRate(calculationPeriod, fixedRate);
            }
            //  Floating rate
            //
            else// if (hasFloatingRateCalculation)
            {
                // no observed, no calculated rate, spread == 0.0
                //
                var floatingRateDefinition = (FloatingRateDefinition)calculationPeriod.Item1 ?? new FloatingRateDefinition();
                //  check if stream has spreadSchedule
                //
                if (XsdClassesFieldResolver.CalculationHasSpreadSchedule(calculation))
                {
                    Schedule spreadSchedule = XsdClassesFieldResolver.GetCalculationSpreadSchedule(calculation);
                    decimal  spread         = ScheduleHelper.GetValue(spreadSchedule, calculationPeriod.adjustedStartDate);
                    floatingRateDefinition.spread          = spread;
                    floatingRateDefinition.spreadSpecified = true;
                }
                FloatingRateCalculation floatingRateCalculation = XsdClassesFieldResolver.CalculationGetFloatingRateCalculation(calculation);
                //  Check if there's a capRateSchedule
                //
                if (null != floatingRateCalculation.capRateSchedule)
                {
                    StrikeSchedule capRateSchedule = floatingRateCalculation.capRateSchedule[0];
                    var            capStrike       = new Strike();
                    var            capRate         = ScheduleHelper.GetValue(capRateSchedule, calculationPeriod.adjustedStartDate);
                    capStrike.strikeRate           = capRate;
                    floatingRateDefinition.capRate = new[] { capStrike };
                }
                //  Check if there's a capRateSchedule
                //
                if (null != floatingRateCalculation.floorRateSchedule)
                {
                    StrikeSchedule floorRateSchedule = floatingRateCalculation.floorRateSchedule[0];
                    var            floorStrike       = new Strike();
                    decimal        floorRate         = ScheduleHelper.GetValue(floorRateSchedule, calculationPeriod.adjustedStartDate);
                    floorStrike.strikeRate           = floorRate;
                    floatingRateDefinition.floorRate = new[] { floorStrike };
                }
                calculationPeriod.Item1 = floatingRateDefinition;
            }
        }