Beispiel #1
0
        public double Compute(Bond bond, DateTime pricerDate)
        {
            #region Objects

            double    Po = 1;
            RateCurve pricerRateCurve;
            var       RateCurveDatePricer = RatesCurves.Where(x => x.RatesDate == pricerDate);
            #endregion
            if (!PricingDateIsInCsvDateRange(pricerDate))
            {
                return(default(double));
            }

            if (pricerDate >= bond.IssueDate && pricerDate <= bond.GetLastDate() && RateCurveDatePricer.Count() == 0)
            {
                return(prevBondPrice);
            }
            if (pricerDate < bond.IssueDate || pricerDate > bond.GetLastDate())
            {
                return(default(double));
            }
            else
            {
                pricerRateCurve = RateCurveDatePricer.First();
            }



            if (pricerRateCurve != null)
            {
                #region Objects
                var nextFluxDate = GetNextFluxDate(bond, pricerDate);

                var reelDurations = GetReelDurations(rateRepository.GetDurations());
                var alpha         = ComputeAlpha(pricerDate, nextFluxDate);

                var nbrCoupons = bond.GetCouponsNumber();
                Po = 0;
                double k        = alpha;
                double dynAlpha = 0;
                var    nbr      = GetNbrFluxRestant(bond, nextFluxDate);
                double alphaMin;
                double alphaMax;
                double alphaMinRate;
                double alphaMaxRate;
                #endregion
                for (int i = 1; i <= nbr; i++)
                {
                    #region Objects

                    alphaMin     = GetAlphaMin(reelDurations, k);
                    alphaMax     = GetAlphaMax(reelDurations, k);
                    alphaMinRate = Convert.ToDouble(pricerRateCurve.Rates[alphaMin * 100]);
                    alphaMaxRate = Convert.ToDouble(pricerRateCurve.Rates[alphaMax * 100]);
                    dynAlpha     = interpolation.ComputeRate(alphaMin, alphaMax, alphaMinRate, alphaMaxRate, k);
                    #endregion
                    if (i != nbr)
                    {
                        if (dynAlpha == 0)
                        {
                            return(prevBondPrice);
                        }
                        //Calcule du Prix
                        Po += bond.Coupon / Math.Pow((1 + dynAlpha), k);

                        k += bond.DurationBeetweenTwoFlux();
                    }
                    else
                    {
                        Po += (bond.Coupon + bond.Nominal) / Math.Pow((1 + dynAlpha), k);
                    }
                }
            }



            prevBondPrice = Po;
            return(Po);
        }