Exemplo n.º 1
0
        public DiscretizedSwap(VanillaSwap.Arguments args,
            Date referenceDate,
            DayCounter dayCounter)
        {
            arguments_ = args;
            fixedResetTimes_ = new InitializedList<double>(args.fixedResetDates.Count);
            for (int i = 0; i < fixedResetTimes_.Count; ++i)
                fixedResetTimes_[i] =
                    dayCounter.yearFraction(referenceDate,
                                            args.fixedResetDates[i]);

            fixedPayTimes_ = new InitializedList<double>(args.fixedPayDates.Count);
            for (int i = 0; i < fixedPayTimes_.Count; ++i)
                fixedPayTimes_[i] =
                    dayCounter.yearFraction(referenceDate,
                                            args.fixedPayDates[i]);

            floatingResetTimes_ = new InitializedList<double>(args.floatingResetDates.Count);
            for (int i = 0; i < floatingResetTimes_.Count; ++i)
                floatingResetTimes_[i] =
                    dayCounter.yearFraction(referenceDate,
                                            args.floatingResetDates[i]);

            floatingPayTimes_ = new InitializedList<double>(args.floatingPayDates.Count);
            for (int i = 0; i < floatingPayTimes_.Count; ++i)
                floatingPayTimes_[i] =
                    dayCounter.yearFraction(referenceDate,
                                            args.floatingPayDates[i]);
        }
Exemplo n.º 2
0
        public override void setupArguments(IPricingEngineArguments args)
        {
            base.setupArguments(args);

            VanillaSwap.Arguments arguments = args as VanillaSwap.Arguments;
            if (arguments == null) // it's a swap engine...
            {
                return;
            }

            arguments.type    = type_;
            arguments.nominal = nominal_;

            List <CashFlow> fixedCoupons = fixedLeg();

            arguments.fixedResetDates = new InitializedList <Date>(fixedCoupons.Count);
            arguments.fixedPayDates   = new InitializedList <Date>(fixedCoupons.Count);
            arguments.fixedCoupons    = new InitializedList <double>(fixedCoupons.Count);

            for (int i = 0; i < fixedCoupons.Count; ++i)
            {
                FixedRateCoupon coupon = (FixedRateCoupon)fixedCoupons[i];

                arguments.fixedPayDates[i]   = coupon.date();
                arguments.fixedResetDates[i] = coupon.accrualStartDate();
                arguments.fixedCoupons[i]    = coupon.amount();
            }

            List <CashFlow> floatingCoupons = floatingLeg();

            arguments.floatingResetDates   = new InitializedList <Date>(floatingCoupons.Count);
            arguments.floatingPayDates     = new InitializedList <Date>(floatingCoupons.Count);
            arguments.floatingFixingDates  = new InitializedList <Date>(floatingCoupons.Count);
            arguments.floatingAccrualTimes = new InitializedList <double>(floatingCoupons.Count);
            arguments.floatingSpreads      = new InitializedList <double>(floatingCoupons.Count);
            arguments.floatingCoupons      = new InitializedList <double>(floatingCoupons.Count);
            for (int i = 0; i < floatingCoupons.Count; ++i)
            {
                IborCoupon coupon = (IborCoupon)floatingCoupons[i];

                arguments.floatingResetDates[i] = coupon.accrualStartDate();
                arguments.floatingPayDates[i]   = coupon.date();

                arguments.floatingFixingDates[i]  = coupon.fixingDate();
                arguments.floatingAccrualTimes[i] = coupon.accrualPeriod();
                arguments.floatingSpreads[i]      = coupon.spread();
                try
                {
                    arguments.floatingCoupons[i] = coupon.amount();
                }
                catch
                {
                    arguments.floatingCoupons[i] = default(double);
                }
            }
        }
Exemplo n.º 3
0
        public DiscretizedSwap(VanillaSwap.Arguments args,
                               Date referenceDate,
                               DayCounter dayCounter)
        {
            arguments_       = args;
            fixedResetTimes_ = new InitializedList <double>(args.fixedResetDates.Count);
            for (int i = 0; i < fixedResetTimes_.Count; ++i)
            {
                fixedResetTimes_[i] =
                    dayCounter.yearFraction(referenceDate,
                                            args.fixedResetDates[i]);
            }

            fixedPayTimes_ = new InitializedList <double>(args.fixedPayDates.Count);
            for (int i = 0; i < fixedPayTimes_.Count; ++i)
            {
                fixedPayTimes_[i] =
                    dayCounter.yearFraction(referenceDate,
                                            args.fixedPayDates[i]);
            }

            floatingResetTimes_ = new InitializedList <double>(args.floatingResetDates.Count);
            for (int i = 0; i < floatingResetTimes_.Count; ++i)
            {
                floatingResetTimes_[i] =
                    dayCounter.yearFraction(referenceDate,
                                            args.floatingResetDates[i]);
            }

            floatingPayTimes_ = new InitializedList <double>(args.floatingPayDates.Count);
            for (int i = 0; i < floatingPayTimes_.Count; ++i)
            {
                floatingPayTimes_[i] =
                    dayCounter.yearFraction(referenceDate,
                                            args.floatingPayDates[i]);
            }
        }