Exemplo n.º 1
0
        public FloatingLoan(Type type, double nominal,
                            Schedule floatingSchedule, double floatingSpread, DayCounter floatingDayCount,
                            Schedule principalSchedule, BusinessDayConvention?paymentConvention, IborIndex index) :
            base(2)
        {
            type_              = type;
            nominal_           = nominal;
            floatingSchedule_  = floatingSchedule;
            floatingSpread_    = floatingSpread;
            floatingDayCount_  = floatingDayCount;
            principalSchedule_ = principalSchedule;
            iborIndex_         = index;

            if (paymentConvention.HasValue)
            {
                paymentConvention_ = paymentConvention.Value;
            }
            else
            {
                paymentConvention_ = floatingSchedule_.businessDayConvention();
            }

            List <CashFlow> principalLeg = new PricipalLeg(principalSchedule, floatingDayCount)
                                           .withNotionals(nominal)
                                           .withPaymentAdjustment(paymentConvention_)
                                           .withSign(type == Type.Loan ? -1 : 1);

            // temporary
            for (int i = 0; i < principalLeg.Count - 1; i++)
            {
                Principal p = (Principal)principalLeg[i];
                notionals_.Add(p.nominal());
            }

            List <CashFlow> floatingLeg = new IborLeg(floatingSchedule, iborIndex_)
                                          .withPaymentDayCounter(floatingDayCount_)
                                          .withSpreads(floatingSpread_)
                                          .withPaymentAdjustment(paymentConvention_)
                                          .withNotionals(notionals_);


            legs_[0] = floatingLeg;
            legs_[1] = principalLeg;
            if (type_ == Type.Loan)
            {
                payer_[0] = -1;
                payer_[1] = +1;
            }
            else
            {
                payer_[0] = +1;
                payer_[1] = -1;
            }
        }
Exemplo n.º 2
0
        public FixedLoan(Type type, double nominal,
                         Schedule fixedSchedule, double fixedRate, DayCounter fixedDayCount,
                         Schedule principalSchedule, BusinessDayConvention?paymentConvention) :
            base(2)
        {
            type_              = type;
            nominal_           = nominal;
            fixedSchedule_     = fixedSchedule;
            fixedRate_         = fixedRate;
            fixedDayCount_     = fixedDayCount;
            principalSchedule_ = principalSchedule;

            if (paymentConvention.HasValue)
            {
                paymentConvention_ = paymentConvention.Value;
            }
            else
            {
                paymentConvention_ = fixedSchedule_.businessDayConvention();
            }

            List <CashFlow> principalLeg = new PricipalLeg(principalSchedule, fixedDayCount)
                                           .withNotionals(nominal)
                                           .withPaymentAdjustment(paymentConvention_)
                                           .withSign(type == Type.Loan ? -1 : 1);

            // temporary
            for (int i = 0; i < principalLeg.Count - 1; i++)
            {
                Principal p = (Principal)principalLeg[i];
                notionals_.Add(p.nominal());
            }

            List <CashFlow> fixedLeg = new FixedRateLeg(fixedSchedule)
                                       .withCouponRates(fixedRate, fixedDayCount)
                                       .withPaymentAdjustment(paymentConvention_)
                                       .withNotionals(notionals_);


            legs_[0] = fixedLeg;
            legs_[1] = principalLeg;
            if (type_ == Type.Loan)
            {
                payer_[0] = +1;
                payer_[1] = -1;
            }
            else
            {
                payer_[0] = -1;
                payer_[1] = +1;
            }
        }
Exemplo n.º 3
0
        public Cash(Type type, double nominal,
                    Schedule principalSchedule, BusinessDayConvention?paymentConvention) :
            base(1)
        {
            type_              = type;
            nominal_           = nominal;
            principalSchedule_ = principalSchedule;
            paymentConvention_ = paymentConvention.Value;

            List <CashFlow> principalLeg = new PricipalLeg(principalSchedule, new Actual365Fixed())
                                           .withNotionals(nominal)
                                           .withPaymentAdjustment(paymentConvention_)
                                           .withSign(type == Type.Loan ? -1 : 1);

            legs_[0] = principalLeg;
            if (type_ == Type.Loan)
            {
                payer_[0] = +1;
            }
            else
            {
                payer_[0] = -1;
            }
        }
Exemplo n.º 4
0
        public CommercialPaper(Type type, double nominal,
                               Schedule fixedSchedule, double fixedRate, DayCounter fixedDayCount,
                               Schedule principalSchedule, BusinessDayConvention?paymentConvention) :
            base(2)
        {
            type_              = type;
            nominal_           = nominal;
            fixedSchedule_     = fixedSchedule;
            fixedRate_         = fixedRate;
            fixedDayCount_     = fixedDayCount;
            principalSchedule_ = principalSchedule;

            if (paymentConvention.HasValue)
            {
                paymentConvention_ = paymentConvention.Value;
            }
            else
            {
                paymentConvention_ = fixedSchedule_.businessDayConvention();
            }

            List <CashFlow> principalLeg = new PricipalLeg(principalSchedule, fixedDayCount)
                                           .withNotionals(nominal)
                                           .withPaymentAdjustment(paymentConvention_)
                                           .withSign(type == Type.Loan ? -1 : 1);

            // temporary
            for (int i = 0; i < principalLeg.Count - 1; i++)
            {
                Principal p = (Principal)principalLeg[i];
                notionals_.Add(p.nominal());
            }

            List <CashFlow> fixedLeg = new FixedRateLeg(fixedSchedule)
                                       .withCouponRates(fixedRate, fixedDayCount)
                                       .withPaymentAdjustment(paymentConvention_)
                                       .withNotionals(notionals_);

            // Discounting Pricipal
            notionals_.Clear();
            double n;

            for (int i = 0; i < fixedLeg.Count; i++)
            {
                FixedRateCoupon c = (FixedRateCoupon)fixedLeg[i];
                n = i > 0 ? notionals_.Last() : c.nominal();
                notionals_.Add(n / (1 + (c.rate() * c.dayCounter().yearFraction(c.referencePeriodStart, c.referencePeriodEnd))));
            }

            // New Leg
            List <CashFlow> discountedFixedLeg = new FixedRateLeg(fixedSchedule)
                                                 .withCouponRates(fixedRate, fixedDayCount)
                                                 .withPaymentAdjustment(paymentConvention_)
                                                 .withNotionals(notionals_);
            // Adjust Principal
            Principal p0 = (Principal)principalLeg[0];

            p0.setAmount(notionals_.Last());

            legs_[0] = discountedFixedLeg;
            legs_[1] = principalLeg;
            if (type_ == Type.Loan)
            {
                payer_[0] = +1;
                payer_[1] = -1;
            }
            else
            {
                payer_[0] = -1;
                payer_[1] = +1;
            }
        }