Пример #1
0
        private void SolveBondYield()
        {
            DateTime previousCoupon;
            DateTime nextCoupon;

            Basis.GetPreviousNextCoupons(this.Settlement, this.Maturity, this.Period, out previousCoupon, out nextCoupon);

            var accruedPeriod = Basis.AccruedPeriod(this.Settlement, previousCoupon, this.Period, this.DayCountBasis);
            var payments      = Basis.PaymentCount(this.Maturity, nextCoupon, this.Period);

            this.Accrued = accruedPeriod * (this.Rate / this.Period) * this.Principal;

            Func <double, double> bondPrice = (calcYield =>
            {
                var pv = 0d;
                for (var i = 0; i < payments; ++i)
                {
                    var payment = (this.Rate / this.Period);
                    var discountFactor = Math.Pow(1 + calcYield / this.Period, -(1 - accruedPeriod + i));
                    pv += (i == payments - 1) ? (payment + 1) * discountFactor : payment * discountFactor;
                }
                return(pv - accruedPeriod * (this.Rate / this.Period) - this.Clean);
            });

            this.YieldToMaturity = Mathematics.FindRoot(bondPrice, 0d, 0.5d);
            this.PV = this.Clean * this.Principal + this.Accrued;
        }
Пример #2
0
        public void CalculateYieldToHorizon()
        {
            DateTime previousCoupon;
            DateTime nextCoupon;

            Basis.GetPreviousNextCoupons(this.HorizonDate, this.Maturity, this.Period, out previousCoupon, out nextCoupon);
            var accruedPeriod = Basis.AccruedPeriod(this.HorizonDate, previousCoupon, this.Period, this.DayCountBasis);

            var lastCoupon = previousCoupon;

            Basis.GetPreviousNextCoupons(this.Settlement, lastCoupon, this.Period, out previousCoupon, out nextCoupon);
            var payments = Basis.PaymentCount(lastCoupon, nextCoupon, this.Period);

            Basis.GetPreviousNextCoupons(this.Settlement, this.Maturity, this.Period, out previousCoupon, out nextCoupon);
            var accruedToPay = Basis.AccruedPeriod(this.Settlement, previousCoupon, this.Period, this.DayCountBasis);

            var couponsToHorizon = 0d;
            var payment          = (this.Rate / this.Period) * this.Principal;

            for (var i = 0; i < payments; ++i)
            {
                couponsToHorizon += payment * Math.Pow(1 + this.HorizonReinvestment / this.Period, i + accruedPeriod);
            }

            this.HorizonPV    = this.HorizonPrice * this.Principal + (accruedPeriod * this.Principal * this.Rate / this.Period) + couponsToHorizon;
            this.HorizonYield = Math.Pow(Math.Pow(this.HorizonPV / this.PV, 1 / (payments + accruedPeriod - accruedToPay)), this.Period) - 1;
            this.HorizonGross = this.HorizonPV - this.PV;
        }
Пример #3
0
        public double GetAdjustedCurrentYield()
        {
            if (Math.Abs(this.Clean) < Mathematics.Error)
            {
                CalculateClean();
            }

            DateTime previousCoupon;
            DateTime nextCoupon;

            Basis.GetPreviousNextCoupons(this.Settlement, this.Maturity, this.Period, out previousCoupon, out nextCoupon);

            var accruedPeriod = Basis.AccruedPeriod(nextCoupon, this.Settlement, this.Period, this.DayCountBasis) / this.Period;
            var payments      = Basis.PaymentCount(this.Maturity, nextCoupon, this.Period) / this.Period;

            return((this.Rate + ((1 - this.Clean) / (payments + accruedPeriod))) / this.Clean);
        }
Пример #4
0
        private void CalculateClean()
        {
            DateTime previousCoupon;
            DateTime nextCoupon;

            Basis.GetPreviousNextCoupons(this.Settlement, this.Maturity, this.Period, out previousCoupon, out nextCoupon);

            var accruedPeriod = Basis.AccruedPeriod(this.Settlement, previousCoupon, this.Period, this.DayCountBasis);
            var payments      = Basis.PaymentCount(this.Maturity, nextCoupon, this.Period);

            this.Accrued = accruedPeriod * (this.Rate / this.Period) * this.Principal;
            this.PV      = 0d;

            for (var i = 0; i < payments; ++i)
            {
                var payment        = (this.Rate / this.Period) * this.Principal;
                var discountFactor = Math.Pow(1 + this.YieldToMaturity / this.Period, -(1 - accruedPeriod + i));
                this.PV += (i == payments - 1) ? (payment + this.Principal) * discountFactor : payment *discountFactor;
            }

            this.Clean = this.PV - this.Accrued;
        }