示例#1
0
        public static double GetEffectiveFrequency(List <AmortisingResultItem> cashflowsSchedule,
                                                   BillsSwapPricer2TermsRange terms)
        {
            IDayCounter dayCounter         = DayCounterHelper.Parse(terms.DayCountConvention);
            double      effectiveFrequency = GetEffectiveFrequency(cashflowsSchedule, dayCounter);

            return(effectiveFrequency);
        }
示例#2
0
        ///<summary>
        ///</summary>
        ///<param name="valuationDate"></param>
        ///<param name="floatMargin"></param>
        ///<param name="fixedRate"></param>
        ///<param name="payTerms"></param>
        ///<param name="payRolls"></param>
        ///<param name="receiveTerms"></param>
        ///<param name="receiveRolls"></param>
        ///<param name="rateCurve"></param>
        ///<param name="bulletPaymentDate"></param>
        ///<param name="bulletPaymentValue"></param>
        ///<returns></returns>
        public static double CalculateFixedSidePV(DateTime valuationDate, double floatMargin, double fixedRate,
                                                  BillsSwapPricer2TermsRange payTerms, List <AmortisingResultItem> payRolls,
                                                  BillsSwapPricer2TermsRange receiveTerms, List <AmortisingResultItem> receiveRolls,
                                                  RateCurve rateCurve, DateTime bulletPaymentDate, double bulletPaymentValue)
        {
            //  pay == fixed.
            //
            IDayCounter dayCounter  = DayCounterHelper.Parse(payTerms.DayCountConvention);
            double      fixedSidePV = GetFixedSidePV(valuationDate, payRolls, receiveRolls, dayCounter, rateCurve, floatMargin, fixedRate, bulletPaymentDate, bulletPaymentValue);

            return(fixedSidePV);
        }
示例#3
0
        ///<summary>
        ///</summary>
        ///<param name="valuationDate"></param>
        ///<param name="floatMargin"></param>
        ///<param name="fixedRate"></param>
        ///<param name="payTerms"></param>
        ///<param name="payRolls"></param>
        ///<param name="receiveTerms"></param>
        ///<param name="receiveRolls"></param>
        ///<param name="originalReceiveCurve"></param>
        ///<param name="bulletPaymentDate"></param>
        ///<param name="bulletPaymentValue"></param>
        ///<param name="listInstrumentIdAndQuotes"></param>
        ///<param name="listPerturbations"></param>
        ///<param name="filterByInstruments"></param>
        ///<returns></returns>
        public static double CalculateFixedSideDelta(DateTime valuationDate, double floatMargin, double fixedRate,
                                                     BillsSwapPricer2TermsRange payTerms, List <AmortisingResultItem> payRolls,
                                                     BillsSwapPricer2TermsRange receiveTerms, List <AmortisingResultItem> receiveRolls,
                                                     RateCurve originalReceiveCurve, DateTime bulletPaymentDate, double bulletPaymentValue,
                                                     List <InstrumentIdAndQuoteRangeItem> listInstrumentIdAndQuotes, List <DoubleRangeItem> listPerturbations, string filterByInstruments)
        {
            if (null == listPerturbations)
            {
                listPerturbations = new List <DoubleRangeItem>();
                foreach (InstrumentIdAndQuoteRangeItem item in listInstrumentIdAndQuotes)
                {
                    item.InstrumentId = RemoveExtraInformationFromInstrumentId(item.InstrumentId);
                    var defaultPerturbationAmount = new DoubleRangeItem
                    {
                        Value = GetDefaultPerturbationAmount(item.InstrumentId)
                    };
                    listPerturbations.Add(defaultPerturbationAmount);
                }
            }
            var perturbationArray = new List <Pair <string, decimal> >();

            for (int i = 0; i < listInstrumentIdAndQuotes.Count; i++)
            {
                InstrumentIdAndQuoteRangeItem item = listInstrumentIdAndQuotes[i];
                item.InstrumentId = RemoveExtraInformationFromInstrumentId(item.InstrumentId);
                DoubleRangeItem perturbItem = listPerturbations[i];
                if (!String.IsNullOrEmpty(filterByInstruments))
                {
                    if (item.InstrumentId.StartsWith(filterByInstruments, true, null))
                    {
                        perturbationArray.Add(new Pair <string, decimal>(item.InstrumentId, (decimal)perturbItem.Value));
                    }
                }
                else
                {
                    perturbationArray.Add(new Pair <string, decimal>(item.InstrumentId, (decimal)perturbItem.Value));
                }
            }
            //var perturbedCurveId = originalReceiveCurve.PerturbCurve(perturbationArray);
            //  Perturb the curve
            //
            //Curves.RateCurve perturbedReceiveCurve = RateCurveInMemoryCollection.Instance.Get(perturbedCurveId);
            var perturbedReceiveCurve = (RateCurve)originalReceiveCurve.PerturbCurve(perturbationArray); //ObjectCacheHelper.GetPricingStructureFromSerialisable(perturbedCurveId);
            //  pay == fixed.
            //
            IDayCounter dayCounter  = DayCounterHelper.Parse(payTerms.DayCountConvention);
            double      sensitivity = GetFixedSideSensitivity(valuationDate, payRolls, receiveRolls, dayCounter, originalReceiveCurve, perturbedReceiveCurve, floatMargin, fixedRate, bulletPaymentDate, bulletPaymentValue);

            return(sensitivity);
        }
示例#4
0
        ///<summary>
        ///</summary>
        ///<param name="termsRange"></param>
        ///<param name="metaScheduleDefinitionRange"></param>
        ///<param name="paymentCalendar"></param>
        ///<returns></returns>
        public static List <AmortisingResultItem> GenerateCashflowSchedule(BillsSwapPricer2TermsRange termsRange,
                                                                           List <MetaScheduleRangeItem> metaScheduleDefinitionRange, IBusinessCalendar paymentCalendar)
        {
            RollConventionEnum     rollConventionEnum     = RollConventionEnumHelper.Parse(termsRange.RollDay);
            BusinessDayAdjustments businessDayAdjustments = BusinessDayAdjustmentsHelper.Create(termsRange.DateRollConvention, termsRange.Calendar);
            bool            backwardGeneration            = (termsRange.BuildDates.ToLower() == "backward");
            List <DateTime> adjustedDatesResult;
            List <DateTime> unadjustedDatesResult;

            if (termsRange.RollFrequency.ToLower().Contains("custom"))
            {
                var rollsMetaSchedule = metaScheduleDefinitionRange.Select(item => new MetaScheduleItem
                {
                    RollFrequency = PeriodHelper.Parse(item.RollFrequency), Period = PeriodHelper.Parse(item.Period), RollConvention = RollConventionEnumHelper.Parse(item.RollConvention)
                }).ToList();
                unadjustedDatesResult = DatesMetaSchedule.GetUnadjustedDates3(termsRange.StartDate, termsRange.EndDate,
                                                                              rollsMetaSchedule, backwardGeneration);
                adjustedDatesResult = AdjustedDatesMetaSchedule.GetAdjustedDates3(termsRange.StartDate, termsRange.EndDate,
                                                                                  rollsMetaSchedule, backwardGeneration, businessDayAdjustments, paymentCalendar);
            }
            else
            {
                Period interval = PeriodHelper.Parse(termsRange.RollFrequency);
                unadjustedDatesResult = DatesMetaSchedule.GetUnadjustedDates2(termsRange.StartDate, termsRange.EndDate,
                                                                              interval, rollConventionEnum, backwardGeneration);
                adjustedDatesResult = AdjustedDatesMetaSchedule.GetAdjustedDates2(termsRange.StartDate, termsRange.EndDate,
                                                                                  interval, rollConventionEnum, backwardGeneration, businessDayAdjustments, paymentCalendar);
            }
            var result = new List <AmortisingResultItem>();

            for (int i = 0; i < adjustedDatesResult.Count; i++)
            {
                DateTime adjustedTime         = adjustedDatesResult[i];
                DateTime unadjustedTime       = unadjustedDatesResult[i];
                var      amortisingResultItem = new AmortisingResultItem
                {
                    WasRolled        = (adjustedTime == unadjustedTime) ? "No" : "Yes",
                    RollDate         = adjustedTime,
                    AmortisingAmount = 0,
                    OutstandingValue = termsRange.FaceValue
                };
                result.Add(amortisingResultItem);
            }
            return(result);
        }
示例#5
0
        ///<summary>
        ///</summary>
        ///<param name="valuationDate"></param>
        ///<param name="floatMargin"></param>
        ///<param name="fixedRate"></param>
        ///<param name="payTerms"></param>
        ///<param name="payRolls"></param>
        ///<param name="receiveTerms"></param>
        ///<param name="receiveRolls"></param>
        ///<param name="originalCurve"></param>
        ///<param name="bulletPaymentDate"></param>
        ///<param name="bulletPaymentValue"></param>
        ///<param name="listInstrumentIdAndQuotes"></param>
        ///<param name="listPerturbations"></param>
        ///<returns></returns>
        public static List <DoubleRangeItem> CalculateFixedSideSensitivity2(DateTime valuationDate, double floatMargin, double fixedRate,
                                                                            BillsSwapPricer2TermsRange payTerms, List <AmortisingResultItem> payRolls,
                                                                            BillsSwapPricer2TermsRange receiveTerms, List <AmortisingResultItem> receiveRolls,
                                                                            RateCurve originalCurve, DateTime bulletPaymentDate, double bulletPaymentValue,
                                                                            List <InstrumentIdAndQuoteRangeItem> listInstrumentIdAndQuotes, List <DoubleRangeItem> listPerturbations)
        {
            var result = new List <DoubleRangeItem>();

            if (null == listPerturbations)
            {
                listPerturbations = new List <DoubleRangeItem>();
                foreach (InstrumentIdAndQuoteRangeItem item in listInstrumentIdAndQuotes)
                {
                    item.InstrumentId = RemoveExtraInformationFromInstrumentId(item.InstrumentId);
                    var defaultPerturbationAmount = new DoubleRangeItem
                    {
                        Value = GetDefaultPerturbationAmount(item.InstrumentId)
                    };
                    listPerturbations.Add(defaultPerturbationAmount);
                }
            }
            for (int i = 0; i < listInstrumentIdAndQuotes.Count; i++)
            {
                InstrumentIdAndQuoteRangeItem item = listInstrumentIdAndQuotes[i];
                item.InstrumentId = RemoveExtraInformationFromInstrumentId(item.InstrumentId);
                DoubleRangeItem perturbItem = listPerturbations[i];
                //  pay == fixed.
                //
                IDayCounter dayCounter        = DayCounterHelper.Parse(payTerms.DayCountConvention);
                var         perturbationArray = new List <Pair <string, decimal> > {
                    new Pair <string, decimal>(item.InstrumentId, (decimal)perturbItem.Value)
                };
                //var perturbedCurveId = ObjectCacheHelper.PerturbRateCurve(curveId, perturbationArray);

                //  Perturb the curve
                //
                var    perturbedReceiveCurve = (RateCurve)originalCurve.PerturbCurve(perturbationArray);
                double sensitivity           = GetFixedSideSensitivity(valuationDate, payRolls, receiveRolls, dayCounter, originalCurve, perturbedReceiveCurve, floatMargin, fixedRate, bulletPaymentDate, bulletPaymentValue);
                var    bucketSensitivityItem = new DoubleRangeItem {
                    Value = sensitivity
                };
                result.Add(bucketSensitivityItem);
            }
            return(result);
        }
示例#6
0
        public static double CalculateFixedSideSensitivity(DateTime valuationDate, double floatMargin, double fixedRate,
                                                           BillsSwapPricer2TermsRange payTerms, List <AmortisingResultItem> payRolls,
                                                           BillsSwapPricer2TermsRange receiveTerms, List <AmortisingResultItem> receiveRolls,
                                                           RateCurve rateCurve, DateTime bulletPaymentDate, double bulletPaymentValue,
                                                           string curveInstrumentId, double perturbationAmount)
        {
            //  pay == fixed.
            var perturbationArray = new List <Pair <string, decimal> >
            {
                new Pair <string, decimal>(curveInstrumentId, (decimal)perturbationAmount)
            };
            IDayCounter dayCounter = DayCounterHelper.Parse(payTerms.DayCountConvention);
            //var originalCurve = (RateCurve)cache.LoadObject(curveId);
            var perturbedCurve = rateCurve.PerturbCurve(perturbationArray) as RateCurve;
            //  Perturb the curve
            //
            //var perturbedReceiveCurve = (RateCurve)ObjectCacheHelper.GetPricingStructureFromSerialisable(perturbedCurveId);
            double sensitivity = GetFixedSideSensitivity(valuationDate, payRolls, receiveRolls, dayCounter, rateCurve, perturbedCurve,
                                                         floatMargin, fixedRate, bulletPaymentDate, bulletPaymentValue);

            return(sensitivity);
        }