Beispiel #1
0
        public static Discounting Create(decimal discountingRate, DayCountFraction dayCountFraction, DiscountingTypeEnum discountingTypeEnum)
        {
            var discounting = new Discounting
            {
                discountingType = discountingTypeEnum,
                discountRate    = discountingRate,
                discountRateDayCountFraction = dayCountFraction
                                               //discountRateSpecified = true
            };

            return(discounting);
        }
Beispiel #2
0
        public static Discounting Parse(decimal discountingRate, string dayCountFraction, DiscountingTypeEnum discountingTypeEnum)
        {
            var discounting = new Discounting
            {
                discountingType = discountingTypeEnum,
                discountRate    = discountingRate,
                discountRateDayCountFraction =
                    DayCountFractionHelper.Parse(dayCountFraction)
                    //discountRateSpecified = true
            };

            return(discounting);
        }
Beispiel #3
0
        public static Discounting Create(decimal?discountingRate, DayCountFraction dayCountFraction, DiscountingTypeEnum discountingTypeEnum)
        {
            var discounting = new Discounting
            {
                discountingType = discountingTypeEnum,
                discountRateDayCountFraction = dayCountFraction
                                               //discountRateSpecified = true
            };

            if (discountingRate != null)
            {
                discounting.discountRate = (decimal)discountingRate;
            }
            return(discounting);
        }
Beispiel #4
0
        public ActionResult DiscountingRevoke()
        {
            using (FATContainer dataContainer = new FATContainer())
            {
                int             tchRoutineID = dataContainer.TeachingNode.Find(Convert.ToInt32(RouteData.Values["id"])).RoutineID;
                TeachingRoutine routine      = SharedCasePool.GetCasePool().GetRoutine(tchRoutineID);
                TeachingNode    node         = routine.NodeList[Convert.ToInt32(RouteData.Values["id"])];
                Discounting     tcInfo       = dataContainer.Discounting.FirstOrDefault(info => (info.TchRoutineID == node.RoutineID));
                ViewData[ConstDefine.ViewData_CaseText] = SharedCasePool.GetCasePool().GetRoutine(node.RoutineID).GroupList[node.GroupIdx].GroupText;
                ViewBag.RoutineName = routine.RelTmpRoutine.RoutineName;
                ViewBag.NodeName    = node.RelTmpNode.NodeName;
                ViewBag.TchNodeID   = node.Row_ID;

                return(View(node.RelTmpNode.Tag, tcInfo));
            }
        }
Beispiel #5
0
        public async Task TenPercentDiscount()
        {
            var discounting = new Discounting {
                Data = new Discounting.DiscountingData()
            };

            var order1 = new SubmitOrder {
                Total = 60
            };
            var order2 = new SubmitOrder {
                Total = 60
            };
            var order3 = new SubmitOrder {
                Total = 10
            };
            var order4 = new SubmitOrder {
                Total = 20
            };

            var context = new TestableMessageHandlerContext();

            // week total 0
            await discounting.Handle(order1, context);

            Assert.Equal(0, context.SentMessages.Select(m => m.Message).OfType <ProcessOrder>().Last().Discount);

            // week total 60
            await discounting.Handle(order2, context);

            Assert.Equal(0, context.SentMessages.Select(m => m.Message).OfType <ProcessOrder>().Last().Discount);

            // week total 120
            await discounting.Handle(order3, context);

            Assert.Equal(10, context.SentMessages.Select(m => m.Message).OfType <ProcessOrder>().Last().Discount);

            // week total 130
            // 1 week since order 1!!!
            await discounting.Timeout(order1, context);

            // week total 70
            await discounting.Handle(order4, context);

            Assert.Equal(0, context.SentMessages.Select(m => m.Message).OfType <ProcessOrder>().Last().Discount);
        }
        public static Calculation CreateFloating(Money notional, FloatingRateIndex floatingRateIndex, Period tenor, DayCountFraction dayCountFraction, DiscountingTypeEnum discountingType)
        {
            var calculation = new Calculation
            {
                Items                      = new object[] { NotionalFactory.Create(notional) },
                compoundingMethod          = CompoundingMethodEnum.None,
                compoundingMethodSpecified = true,
                dayCountFraction           = dayCountFraction
            };
            var discounting = new Discounting
            {
                discountingType = discountingType,
                discountRateDayCountFraction = dayCountFraction
            };

            calculation.discounting = discounting;
            calculation.Items       = new object[] { FloatingRateCalculationHelper.CreateFloating(floatingRateIndex, tenor) };
            return(calculation);
        }
        private static InterestRateStream GenerateFixedStreamDefinition(SwapLegParametersRange legParametersRange)
        {
            var discountingType = legParametersRange.DiscountingType;
            InterestRateStream stream;
            Discounting        discounting = null;

            if (discountingType != null && discountingType.ToUpper() != "NONE")
            {
                discounting = new Discounting {
                    discountingType = EnumHelper.Parse <DiscountingTypeEnum>(legParametersRange.DiscountingType), discountingTypeSpecified = true
                };
                stream = InterestRateStreamFactory.CreateFixedRateStream(DiscountingTypeToPayRelativeTo(discounting.discountingType));
            }
            else
            {
                stream = InterestRateStreamFactory.CreateFixedRateStream(DiscountingTypeToPayRelativeTo(null));
            }
            // Set effective and termination dates of the stream.
            //
            SetEffectiveAndTerminationDates(stream, legParametersRange.EffectiveDate, legParametersRange.MaturityDate, legParametersRange.PaymentBusinessDayAdjustments, legParametersRange.PaymentCalendar);
            //Set the FirstRegularPeriodStartDate
            SetFirstRegularPeriodStartDate(stream, legParametersRange.FirstRegularPeriodStartDate);
            //Set the LastRegularPeriodEndDate
            SetLastRegularPeriodEndDate(stream, legParametersRange.LastRegularPeriodEndDate);
            // Adjusted or unadjusted swap
            //
            var dateAdjustments = AdjustedType.Adjusted != legParametersRange.AdjustedType ? BusinessDayAdjustmentsHelper.Create(BusinessDayConventionEnum.NONE, legParametersRange.PaymentCalendar) : BusinessDayAdjustmentsHelper.Create(legParametersRange.PaymentBusinessDayAdjustments, legParametersRange.PaymentCalendar);

            stream.calculationPeriodDates.calculationPeriodDatesAdjustments = dateAdjustments;
            stream.calculationPeriodDates.calculationPeriodFrequency        = CalculationPeriodFrequencyHelper.Parse(legParametersRange.PaymentFrequency, legParametersRange.RollConvention);
            //Set FirstPeriodStartDate i.e. Full or Partial period.
            if (legParametersRange.FirstCouponType == FirstCouponType.Full)
            {
                var firstCouponStartDate = new AdjustableDate
                {
                    dateAdjustments = dateAdjustments, id = "FullFirstCoupon"
                };
                SetFirstPeriodStartDate(stream, firstCouponStartDate);
            }
            // Set payment dates frequency and adjustments
            //
            stream.paymentDates.paymentFrequency        = PeriodHelper.Parse(legParametersRange.PaymentFrequency).ToFrequency();
            stream.paymentDates.paymentDatesAdjustments = BusinessDayAdjustmentsHelper.Create(legParametersRange.PaymentBusinessDayAdjustments, legParametersRange.PaymentCalendar);
            Calculation calculation = XsdClassesFieldResolver.CalculationPeriodAmountGetCalculation(stream.calculationPeriodAmount);

            //  Set discounting type
            //
            calculation.discounting = discounting;
            // Set notional amount (as the initial value in notional schedule)
            //
            SetNotional(calculation, legParametersRange.NotionalAmount, legParametersRange.Currency);
            // Set fixed rate (as the initial value in fixed-rate schedule)
            //
            Schedule fixedRateSchedule = ScheduleHelper.Create(legParametersRange.CouponOrLastResetRate);

            XsdClassesFieldResolver.CalculationSetFixedRateSchedule(calculation, fixedRateSchedule);
            // Set the 'day count convention'
            //
            calculation.dayCountFraction = DayCountFractionHelper.Parse(legParametersRange.DayCount);
            // Initial stub
            //
            //if (paymentCalendar==null)
            //{
            //    paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, stream.paymentDates.paymentDatesAdjustments.businessCenters);
            //}
            //ProcessStubs(stream, legParametersRange, paymentCalendar);
            return(stream);
        }
        private static InterestRateStream GenerateCapFloorStreamDefinition(CapFloorLegParametersRange legParametersRange)
        {
            Discounting        discounting = null;
            InterestRateStream stream;

            if (legParametersRange.DiscountingType != null && legParametersRange.DiscountingType.ToUpper() != "NONE")
            {
                discounting = new Discounting
                {
                    discountingType =
                        EnumHelper.Parse <DiscountingTypeEnum>(legParametersRange.DiscountingType)
                };
                stream = InterestRateStreamFactory.CreateFloatingRateStream(DiscountingTypeToPayRelativeTo(discounting.discountingType));
            }
            // Create the stream object
            //
            else
            {
                stream = InterestRateStreamFactory.CreateFloatingRateStream(DiscountingTypeToPayRelativeTo(null));
            }
            // Set effective and termination dates of the stream.
            //
            SetEffectiveAndTerminationDates(stream, legParametersRange.EffectiveDate, legParametersRange.MaturityDate, legParametersRange.PaymentBusinessDayAdjustments, legParametersRange.PaymentCalendar);
            // Adjusted or unadjusted swap
            //
            stream.calculationPeriodDates.calculationPeriodDatesAdjustments = AdjustedType.Adjusted != legParametersRange.AdjustedType ? BusinessDayAdjustmentsHelper.Create(BusinessDayConventionEnum.NONE, legParametersRange.PaymentCalendar) : BusinessDayAdjustmentsHelper.Create(legParametersRange.PaymentBusinessDayAdjustments, legParametersRange.PaymentCalendar);
            stream.calculationPeriodDates.calculationPeriodFrequency        = CalculationPeriodFrequencyHelper.Parse(legParametersRange.PaymentFrequency, legParametersRange.RollConvention);
            stream.paymentDates.paymentFrequency        = PeriodHelper.Parse(legParametersRange.PaymentFrequency).ToFrequency();
            stream.paymentDates.paymentDatesAdjustments = BusinessDayAdjustmentsHelper.Create(legParametersRange.PaymentBusinessDayAdjustments, legParametersRange.PaymentCalendar);
            stream.resetDates.fixingDates           = RelativeDateOffsetHelper.Create(legParametersRange.PaymentFrequency, DayTypeEnum.Business, BusinessDayConventionEnum.NONE.ToString(), legParametersRange.FixingCalendar, "resetDates");//"NONE" & "resedDates" - hardcoded
            stream.resetDates.resetFrequency        = ResetFrequencyHelper.Parse(legParametersRange.PaymentFrequency);
            stream.resetDates.resetDatesAdjustments = BusinessDayAdjustmentsHelper.Create(legParametersRange.FixingBusinessDayAdjustments, legParametersRange.FixingCalendar);
            Calculation calculation = XsdClassesFieldResolver.CalculationPeriodAmountGetCalculation(stream.calculationPeriodAmount);

            //  Set discounting type
            //
            calculation.discounting = discounting;
            // Set notional amount (as the initial value in notional schedule)
            //
            SetNotional(calculation, legParametersRange.NotionalAmount, legParametersRange.Currency);
            // Set floating rate index name
            //
            string indexTenor = legParametersRange.PaymentFrequency;
            string indexName  = legParametersRange.ForecastIndexName;
            FloatingRateCalculation floatingRateCalculation = FloatingRateCalculationFactory.Create(indexName, indexTenor, legParametersRange.FloatingRateSpread);

            XsdClassesFieldResolver.CalculationSetFloatingRateCalculation(calculation, floatingRateCalculation);
            if (legParametersRange.CapOrFloor == CapFloorType.Cap)
            {
                floatingRateCalculation.capRateSchedule = new[] { new StrikeSchedule() };
                floatingRateCalculation.capRateSchedule[0].initialValue = legParametersRange.StrikeRate;
                floatingRateCalculation.capRateSchedule[0].buyer        = new IdentifiedPayerReceiver {
                    Value = PayerReceiverEnum.Receiver
                };
                floatingRateCalculation.capRateSchedule[0].seller = new IdentifiedPayerReceiver {
                    Value = PayerReceiverEnum.Payer
                };
            }
            else
            {
                floatingRateCalculation.floorRateSchedule = new[] { new StrikeSchedule() };
                floatingRateCalculation.floorRateSchedule[0].initialValue = legParametersRange.StrikeRate;
                floatingRateCalculation.floorRateSchedule[0].buyer        = new IdentifiedPayerReceiver {
                    Value = PayerReceiverEnum.Receiver
                };
                floatingRateCalculation.floorRateSchedule[0].seller = new IdentifiedPayerReceiver {
                    Value = PayerReceiverEnum.Payer
                };
            }
            // Set day count convention
            //
            calculation.dayCountFraction = DayCountFractionHelper.Parse(legParametersRange.DayCount);
            return(stream);
        }
        private static InterestRateStream GenerateFloatingStreamDefinition(SwapLegParametersRange legParametersRange)
        {
            Discounting        discounting = null;
            InterestRateStream stream;

            if (legParametersRange.DiscountingType != null && legParametersRange.DiscountingType.ToUpper() != "NONE")
            {
                discounting = new Discounting {
                    discountingType = EnumHelper.Parse <DiscountingTypeEnum>(legParametersRange.DiscountingType)
                };
                // Create the stream object
                stream = InterestRateStreamFactory.CreateFloatingRateStream(DiscountingTypeToPayRelativeTo(discounting.discountingType));
            }
            else
            {
                // Create the stream object
                //
                stream = InterestRateStreamFactory.CreateFloatingRateStream(DiscountingTypeToPayRelativeTo(null));
            }
            // Set effective and termination dates of the stream.
            //
            SetEffectiveAndTerminationDates(stream, legParametersRange.EffectiveDate, legParametersRange.MaturityDate, legParametersRange.PaymentBusinessDayAdjustments, legParametersRange.PaymentCalendar);
            //Set the FirstRegularPeriodStartDate
            SetFirstRegularPeriodStartDate(stream, legParametersRange.FirstRegularPeriodStartDate);
            //Set the LastRegularPeriodEndDate
            SetLastRegularPeriodEndDate(stream, legParametersRange.LastRegularPeriodEndDate);
            // Adjusted or unadjusted swap
            //Set the stub period type
            var dateAdjustments = AdjustedType.Adjusted != legParametersRange.AdjustedType
                ? BusinessDayAdjustmentsHelper.Create(BusinessDayConventionEnum.NONE, legParametersRange.PaymentCalendar)
                : BusinessDayAdjustmentsHelper.Create(legParametersRange.PaymentBusinessDayAdjustments, legParametersRange.PaymentCalendar);

            stream.calculationPeriodDates.calculationPeriodDatesAdjustments = dateAdjustments;
            stream.calculationPeriodDates.calculationPeriodFrequency        = CalculationPeriodFrequencyHelper.Parse(legParametersRange.PaymentFrequency, legParametersRange.RollConvention);
            if (legParametersRange.FirstCouponType == FirstCouponType.Full)
            {
                var firstCouponStartDate = new AdjustableDate
                {
                    dateAdjustments = dateAdjustments, id = "FullFirstCoupon"
                };
                SetFirstPeriodStartDate(stream, firstCouponStartDate);
            }
            //Set the payment dates
            stream.paymentDates.paymentFrequency        = PeriodHelper.Parse(legParametersRange.PaymentFrequency).ToFrequency();
            stream.paymentDates.paymentDatesAdjustments = BusinessDayAdjustmentsHelper.Create(legParametersRange.PaymentBusinessDayAdjustments, legParametersRange.PaymentCalendar);
            stream.resetDates.fixingDates           = RelativeDateOffsetHelper.Create(legParametersRange.PaymentFrequency, DayTypeEnum.Business, BusinessDayConventionEnum.NONE.ToString(), legParametersRange.FixingCalendar, "resetDates");//"NONE" & "resedDates" - hardcoded
            stream.resetDates.resetFrequency        = ResetFrequencyHelper.Parse(legParametersRange.PaymentFrequency);
            stream.resetDates.resetDatesAdjustments = BusinessDayAdjustmentsHelper.Create(legParametersRange.FixingBusinessDayAdjustments, legParametersRange.FixingCalendar);
            Calculation calculation = XsdClassesFieldResolver.CalculationPeriodAmountGetCalculation(stream.calculationPeriodAmount);

            //  Set discounting type
            //
            calculation.discounting = discounting;
            // Set notional amount (as the initial value in notional schedule)
            //
            SetNotional(calculation, legParametersRange.NotionalAmount, legParametersRange.Currency);
            // Set floating rate index name
            //
            string indexTenor = legParametersRange.PaymentFrequency;
            //string indexName = legParametersRange.ForecastCurve;
            string indexName = legParametersRange.ForecastIndexName;
            FloatingRateCalculation floatingRateCalculation = FloatingRateCalculationFactory.Create(indexName, indexTenor, legParametersRange.FloatingRateSpread);

            XsdClassesFieldResolver.CalculationSetFloatingRateCalculation(calculation, floatingRateCalculation);
            // Set day count convention
            //
            calculation.dayCountFraction = DayCountFractionHelper.Parse(legParametersRange.DayCount);
            return(stream);
        }
 public static void CalculationSetDiscounting(Calculation calculation, Discounting discounting)
 {
     calculation.discounting = discounting;
 }