Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RateBasisCurve"/> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace">The client namespace</param>
        /// <param name="referenceCurveData">The market data. This must contain both the underlying base curve and the spread curve.
        /// Otherwise the RateBasisInterpolator can not instantiate.</param>
        /// <param name="derivedCurveData">The spread Curve Data</param>
        /// <param name="fixingCalendar">The fixingCalendar.</param>
        /// <param name="rollCalendar">The rollCalendar.</param>
        public ClearedRateCurve(ILogger logger, ICoreCache cache, String nameSpace,
                                Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> referenceCurveData,
                                Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> derivedCurveData, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
            : base(derivedCurveData.Third, GenerateHolder(logger, cache, nameSpace, derivedCurveData.Third))
        {
            PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Rates, derivedCurveData.Third);
            var curveId = GetRateCurveId();
            //Set the identifier.
            var nvs = derivedCurveData.Third;
            var pricingStructureId = GetRateCurveId();
            var refCurveId         = PropertyHelper.ExtractReferenceCurveUniqueId(nvs);

            ReferenceDiscountingCurveId = refCurveId != null ? new Identifier(refCurveId) : ReferenceDiscountingCurveId = null;
            if (pricingStructureId.PricingStructureType != PricingStructureTypeEnum.ClearedRateCurve)
            {
                return;
            }
            //Set the reference curve
            var baseCurveFpml  = new Pair <PricingStructure, PricingStructureValuation>(referenceCurveData.First, referenceCurveData.Second);
            var baseCurveProps = referenceCurveData.Third;

            BaseDiscountingCurve = (IRateCurve)PricingStructureFactory.Create(logger, cache, nameSpace, fixingCalendar, rollCalendar, baseCurveFpml, baseCurveProps);
            //Get the spread Data
            var spreadCurveFpml = new Pair <PricingStructure, PricingStructureValuation>(derivedCurveData.First, derivedCurveData.Second);
            //Override properties.
            //var optimize = PropertyHelper.ExtractOptimizeBuildFlag(properties);
            var bootstrap    = PropertyHelper.ExtractBootStrapOverrideFlag(nvs);
            var tempFpml     = (YieldCurveValuation)spreadCurveFpml.Second;
            var spreadAssets = tempFpml.inputs;
            //This is to catch it when there are no discount factor points.
            var discountsAbsent = tempFpml.discountFactorCurve?.point == null || tempFpml.discountFactorCurve.point.Length == 0;
            var indexTenor      = curveId.ForecastRateIndex?.indexTenor;

            if (bootstrap || discountsAbsent)
            {
                //There must be a valid quoted asset set in order to bootstrap.
                if (!XsdClassesFieldResolver.QuotedAssetSetIsValid(spreadAssets))
                {
                    return;
                }
                PriceableClearedRateAssets =
                    PriceableAssetFactory.CreatePriceableClearedRateAssetsWithBasisSwaps(logger, cache, nameSpace, indexTenor, spreadAssets, pricingStructureId.BaseDate, fixingCalendar, rollCalendar);
                GetYieldCurveValuation().zeroCurve = null;
                TermCurve termCurve = tempFpml.discountFactorCurve ?? SetConfigurationData();
                DateTime  baseDate  = GetYieldCurveValuation().baseDate.Value;
                termCurve.point = ClearedRateBootstrapper.Bootstrap(PriceableClearedRateAssets, BaseDiscountingCurve, baseDate, termCurve.extrapolationPermitted, termCurve.interpolationMethod, Tolerance);
                SetFpMLData(new Pair <PricingStructure, PricingStructureValuation>(PricingStructure, PricingStructureValuation), false);
                SetInterpolator(termCurve);
            }
            else
            {
                // the discount curve is already built, so don't rebuild
                PriceableClearedRateAssets = PriceableAssetFactory.CreatePriceableClearedRateAssetsWithBasisSwaps(logger, cache, nameSpace, indexTenor, spreadAssets, pricingStructureId.BaseDate, fixingCalendar, rollCalendar);
                //Order the assets.
                PriceableClearedRateAssets = PriceableClearedRateAssets.OrderBy(a => a.GetRiskMaturityDate()).ToList();
                CreatePricingStructure(pricingStructureId, tempFpml.discountFactorCurve, spreadAssets);
                // CreatePricingStructure(pricingStructureId, tempFpml.discountFactorCurve, PriceableAssetFactory.Parse(PriceableClearedRateAssets));
                SetInterpolator(GetYieldCurveValuation().discountFactorCurve);
            }
        }
Exemple #2
0
        public static void SetCalculationPeriodStartDate(PaymentCalculationPeriod paymentCalculationPeriod, DateTime startDate)
        {
            CalculationPeriod[] calculationPeriodArray = XsdClassesFieldResolver.GetPaymentCalculationPeriod_CalculationPeriodArray(paymentCalculationPeriod);

            calculationPeriodArray[0].adjustedStartDate          = startDate;
            calculationPeriodArray[0].adjustedStartDateSpecified = true;
        }
Exemple #3
0
        /// <summary>
        /// Gets and sets the required pricing structures to value this leg.
        /// </summary>
        public List <String> GetRequiredPricingStructures()
        {
            var result = new List <String>();
            var amount = calculationPeriodAmount.Item as Calculation;

            if (amount != null)
            {
                var currency = XsdClassesFieldResolver.Calculation_GetNotionalSchedule(amount);
                if (currency != null && currency.notionalStepSchedule != null)
                {
                    var discountCurve = Helpers.GetDiscountCurveName(currency.notionalStepSchedule.currency);
                    result.Add(discountCurve);
                }
                var floatingRateCalculation = amount.Items[0] as FloatingRateCalculation;
                if (floatingRateCalculation != null)
                {
                    result.Add(Helpers.GetForecastCurveName(floatingRateCalculation.floatingRateIndex, floatingRateCalculation.indexTenor));
                }
            }
            //TODO
            if (stubCalculationPeriodAmount != null)
            {
                foreach (var stubIndex in stubCalculationPeriodAmount.Items)
                {
                    result.AddRange(from value in stubIndex.Items
                                    where value as Money != null
                                    select Helpers.GetDiscountCurveName(((Money)value).currency));
                }
            }
            return(result);
        }
Exemple #4
0
        public static void SetCalculationPeriodEndDate(PaymentCalculationPeriod paymentCalculationPeriod, DateTime endDate)
        {
            CalculationPeriod[] calculationPeriodArray = XsdClassesFieldResolver.GetPaymentCalculationPeriod_CalculationPeriodArray(paymentCalculationPeriod);

            calculationPeriodArray[calculationPeriodArray.Length - 1].adjustedEndDate          = endDate;
            calculationPeriodArray[calculationPeriodArray.Length - 1].adjustedEndDateSpecified = true;
        }
Exemple #5
0
 public static void SetNotionalAmount(PaymentCalculationPeriod paymentCalculationPeriod, decimal notionalAmount)
 {
     foreach (CalculationPeriod calculationPeriod in XsdClassesFieldResolver.GetPaymentCalculationPeriod_CalculationPeriodArray(paymentCalculationPeriod))
     {
         XsdClassesFieldResolver.CalculationPeriod_SetNotionalAmount(calculationPeriod, notionalAmount);
     }
 }
Exemple #6
0
        public static Swaption Create(Swap swap, Money premium, string premiumPayer, string premiumReceiver,
                                      AdjustableDate paymentDate,
                                      AdjustableDate expirationDate,
                                      DateTime earliestExerciseTime, DateTime expirationTime, bool automaticExercise)
        {
            var swaption = new Swaption {
                swap = swap, premium = new[] { new Payment() }
            };

            swaption.buyerPartyReference               = PartyOrTradeSideReferenceHelper.ToPartyOrTradeSideReference(premiumPayer);
            swaption.sellerPartyReference              = PartyOrTradeSideReferenceHelper.ToPartyOrTradeSideReference(premiumReceiver);
            swaption.premium[0].paymentAmount          = premium;
            swaption.premium[0].paymentDate            = paymentDate;
            swaption.premium[0].payerPartyReference    = PartyOrAccountReferenceFactory.Create(premiumPayer);
            swaption.premium[0].receiverPartyReference = PartyOrAccountReferenceFactory.Create(premiumReceiver);
            var europeanExercise = new EuropeanExercise
            {
                expirationDate       = new AdjustableOrRelativeDate(),
                earliestExerciseTime = BusinessCenterTimeHelper.Create(earliestExerciseTime),
                expirationTime       = BusinessCenterTimeHelper.Create(expirationTime)
            };

            europeanExercise.expirationDate.Item = expirationDate;
            swaption.exerciseProcedure           = new ExerciseProcedure();
            if (automaticExercise)
            {
                XsdClassesFieldResolver.ExerciseProcedure_SetAutomaticExercise(swaption.exerciseProcedure, new AutomaticExercise());
            }
            else//manual exercise
            {
                XsdClassesFieldResolver.ExerciseProcedure_SetManualExercise(swaption.exerciseProcedure, new ManualExercise());
            }
            XsdClassesFieldResolver.Swaption_SetEuropeanExercise(swaption, europeanExercise);
            return(swaption);
        }
Exemple #7
0
        public static decimal GetRate(PaymentCalculationPeriod paymentCalculationPeriod)
        {
            decimal result          = 0.0m;
            decimal numberOfPeriods = 0.0m;

            foreach (CalculationPeriod calculationPeriod in XsdClassesFieldResolver.GetPaymentCalculationPeriod_CalculationPeriodArray(paymentCalculationPeriod))
            {
                if (XsdClassesFieldResolver.CalculationPeriod_HasFixedRate(calculationPeriod))
                {
                    result += XsdClassesFieldResolver.CalculationPeriod_GetFixedRate(calculationPeriod);
                }
                else if (XsdClassesFieldResolver.CalculationPeriod_HasFloatingRateDefinition(calculationPeriod))
                {
                    result += XsdClassesFieldResolver.CalculationPeriod_GetFloatingRateDefinition(calculationPeriod).calculatedRate;
                }
                else
                {
                    throw new NotImplementedException("PaymentCalculationPeriodHelper.GetRate");
                }

                numberOfPeriods += 1;
            }

            return(result / numberOfPeriods);
        }
Exemple #8
0
        //  need a based date?
        //
        ///<summary>
        ///</summary>
        ///<param name="discountCurve"></param>
        ///<param name="baseDate"></param>
        ///<param name="frequency"></param>
        ///<param name="dayCounter"></param>
        ///<returns></returns>
        ///<exception cref="System.Exception"></exception>
        public static TermCurve ToZeroCurve(TermCurve discountCurve, DateTime baseDate,
                                            CompoundingFrequencyEnum frequency, IDayCounter dayCounter)
        {
            TermCurve result = TermCurve.Create(new List <TermPoint>());

            foreach (TermPoint point in discountCurve.point)
            {
                DateTime pointDate = XsdClassesFieldResolver.TimeDimensionGetDate(point.term);
                double   zeroRateDouble;
                if (baseDate != pointDate)
                {
                    double time = dayCounter.YearFraction(baseDate, pointDate);
                    zeroRateDouble = RateAnalytics.DiscountFactorToZeroRate((double)point.mid, time, frequency);
                }
                else
                {
                    // set after the loop
                    zeroRateDouble = 0;
                }
                TermPoint zeroPoint = TermPointFactory.Create(Convert.ToDecimal(zeroRateDouble), pointDate);
                zeroPoint.id = point.id;
                result.Add(zeroPoint);
            }
            if (result.point[0].mid == 0)
            {
                result.point[0].mid = result.point[1].mid;
            }
            return(result);
        }
Exemple #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClearedRateCurve"/> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace">The client namespace</param>
        /// <param name="fpmlData">The FPML data.</param>
        /// <param name="properties">The properties.</param>
        /// <param name="fixingCalendar">The fixingCalendar.</param>
        /// <param name="rollCalendar">The rollCalendar.</param>
        public ClearedRateCurve(ILogger logger, ICoreCache cache, string nameSpace,
                                Pair <PricingStructure, PricingStructureValuation> fpmlData,
                                NamedValueSet properties, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
            : base(logger, cache, nameSpace, new RateCurveIdentifier(properties), fixingCalendar, rollCalendar)
        {
            PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Rates, properties);
            var refCurveId = PropertyHelper.ExtractReferenceCurveUniqueId(properties);

            ReferenceDiscountingCurveId = refCurveId != null ? new Identifier(refCurveId) : ReferenceDiscountingCurveId = null;
            var tempFpml = (YieldCurveValuation)fpmlData.Second;
            var curveId  = GetRateCurveId();

            Initialize(properties, Holder);
            FixingCalendar  = fixingCalendar;
            PaymentCalendar = rollCalendar;
            //Override properties.
            //var optimize = PropertyHelper.ExtractOptimizeBuildFlag(properties);//TODO removed optimisation as it means that partial hedges can not be undertaken.
            var bootstrap  = PropertyHelper.ExtractBootStrapOverrideFlag(properties);
            var termCurve  = SetConfigurationData();
            var qas        = tempFpml.inputs;
            var indexTenor = curveId.ForecastRateIndex?.indexTenor;
            //This is to catch it when there are no discount factor points.
            var discountsAbsent = tempFpml.discountFactorCurve?.point == null || tempFpml.discountFactorCurve.point.Length == 0;

            //This is an override if the cache is null, as the bootstrapper will not work.
            if (cache == null)
            {
                //optimize = true;
                bootstrap = false;
            }
            bool validAssets = XsdClassesFieldResolver.QuotedAssetSetIsValid(qas);

            //Test to see if a bootstrap is required.
            if (bootstrap || discountsAbsent)
            {
                //There must be a valid quoted asset set in order to bootstrap.
                if (!validAssets)
                {
                    return;
                }
                PriceableClearedRateAssets = PriceableAssetFactory.CreatePriceableClearedRateAssetsWithBasisSwaps(logger, cache, nameSpace, indexTenor, qas, GetRateCurveId().BaseDate, fixingCalendar, rollCalendar);
                termCurve.point            = RateBootstrapper.Bootstrap(PriceableClearedRateAssets, curveId.BaseDate,
                                                                        termCurve.extrapolationPermitted,
                                                                        termCurve.interpolationMethod,
                                                                        Tolerance);
                CreatePricingStructure(curveId, termCurve, qas);
                SetInterpolator(termCurve);
            }
            else
            {
                // the discount curve is already built, so don't rebuild
                SetFpMLData(fpmlData, false);
                SetInterpolator(((YieldCurveValuation)PricingStructureValuation).discountFactorCurve);
                //Set the priceable assets.
                if (validAssets)//!optimize &&
                {
                    PriceableClearedRateAssets = PriceableAssetFactory.CreatePriceableClearedRateAssetsWithBasisSwaps(logger, cache, nameSpace, indexTenor, qas, GetRateCurveId().BaseDate, fixingCalendar, rollCalendar);
                }
            }
        }
Exemple #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="interestRateStream"></param>
        /// <param name="stubCalculationPeriod"></param>
        /// <param name="stubValue"></param>
        public static void UpdateStubCalculationPeriod(InterestRateStream interestRateStream, CalculationPeriod stubCalculationPeriod, StubValue stubValue)
        {
            if (XsdClassesFieldResolver.StubValueHasStubRateArray(stubValue))
            {
                Decimal fixedRate = XsdClassesFieldResolver.GetStubValueStubRateArray(stubValue)[0];
                // Fixed rate
                //
                XsdClassesFieldResolver.SetCalculationPeriodFixedRate(stubCalculationPeriod, fixedRate);
            }
            //else if (XsdClassesFieldResolver.StubValue_HasFloatingRateArray(stubValue))
            //{
            //    //Calculation calculation = XsdClassesFieldResolver.CalculationPeriodAmount_GetCalculation(interestRateStream.calculationPeriodAmount);

            //    //FloatingRate floatingRate = XsdClassesFieldResolver.GetStubValue_FloatingRateArray(stubValue)[0];

            //    //FloatingRateDefinition floatingRateDefinition = ForecastRateHelper.UpdateFloatingRateDefinition(floatingRate,
            //    //                                                                             calculation.dayCountFraction,
            //    //                                                                             stubCalculationPeriod);

            //    // no observed, no calculated rate, spread == 0.0
            //    //
            //    FloatingRateDefinition floatingRateDefinition = ForecastRateHelper.CreateFloatingRateDefinition(stubCalculationPeriod);
            //    XsdClassesFieldResolver.CalculationPeriod_SetFloatingRateDefinition(stubCalculationPeriod, floatingRateDefinition);


            //    //// Floating rate is set on UpdateCashflows phase.
            //    ////
            //    //XsdClassesFieldResolver.CalculationPeriod_SetFloatingRateDefinition(stubCalculationPeriod, floatingRateDefinition);
            //    //throw new NotImplementedException("");
            //}
            else if (XsdClassesFieldResolver.StubValueHasStubAmountArray(stubValue))
            {
                throw new NotImplementedException("stubCalculationPeriodAmount with stubAmount is not implemented.");
            }
        }
 /// <summary>
 /// Gets the unadjusted calculation date schedule.
 /// </summary>
 /// <param name="calculationPeriodDates">The calculation period dates.</param>
 /// <returns></returns>
 public List <CalculationPeriod> GetUnadjustedCalculationDateSchedule(CalculationPeriodDates calculationPeriodDates)
 {
     CalculationPeriodDates = calculationPeriodDates;
     PeriodInterval         = CalculationPeriodHelper.CalculationPeriodFrequencyToInterval(calculationPeriodDates.calculationPeriodFrequency);
     _effectiveDate         = XsdClassesFieldResolver.CalculationPeriodDatesGetEffectiveDate(calculationPeriodDates).unadjustedDate.Value;
     _termDate      = XsdClassesFieldResolver.CalculationPeriodDatesGetTerminationDate(calculationPeriodDates).unadjustedDate.Value;
     RollConvention = calculationPeriodDates.calculationPeriodFrequency.rollConvention;
     _unadjustedDateScheduleList = CalculationPeriodHelper.GenerateUnadjustedCalculationDates(_effectiveDate, _termDate, calculationPeriodDates);
     return(_unadjustedDateScheduleList);
 }
Exemple #12
0
        ///<summary>
        /// Gets all the Forecast curve name.
        ///</summary>
        ///<returns></returns>
        public static string GetRateVolatilityMatrixName(Swap swap)
        {
            AdjustableDate adjustableEffectiveDate   = XsdClassesFieldResolver.CalculationPeriodDates_GetEffectiveDate(swap.swapStream[0].calculationPeriodDates);
            AdjustableDate adjustableTerminationDate = XsdClassesFieldResolver.CalculationPeriodDates_GetTerminationDate(swap.swapStream[0].calculationPeriodDates);
            var            years       = adjustableTerminationDate.unadjustedDate.Value.Year - adjustableEffectiveDate.unadjustedDate.Value.Year;
            var            calculation = (Calculation)swap.swapStream[0].calculationPeriodAmount.Item;
            var            notional    = XsdClassesFieldResolver.Calculation_GetNotionalSchedule(calculation);
            var            currency    = notional.notionalStepSchedule.currency.Value;

            return("RateVolatilityMatrix." + currency + "-IRSwap-" + years + "Y");
        }
Exemple #13
0
        public static int GetNumberOfDays(PaymentCalculationPeriod paymentCalculationPeriod)
        {
            int result = 0;

            foreach (CalculationPeriod calculationPeriod in XsdClassesFieldResolver.GetPaymentCalculationPeriod_CalculationPeriodArray(paymentCalculationPeriod))
            {
                result += int.Parse(calculationPeriod.calculationPeriodNumberOfDays);
            }

            return(result);
        }
Exemple #14
0
        public List <String> GetRequiredCurrencies()
        {
            var result = new List <string>();
            var item   = XsdClassesFieldResolver.Calculation_GetNotionalSchedule((Calculation)calculationPeriodAmount.Item);

            if (item != null && item.notionalStepSchedule != null && item.notionalStepSchedule.currency != null)
            {
                result.Add(item.notionalStepSchedule.currency.Value);
            }
            return(result);
        }
Exemple #15
0
        public List <DateTime> GetListTermDates()
        {
            List <DateTime> result = new List <DateTime>();

            foreach (TermPoint eachPoint in point)
            {
                DateTime dateTime = XsdClassesFieldResolver.TimeDimension_GetDate(eachPoint.term);
                result.Add(dateTime);
            }

            return(result);
        }
Exemple #16
0
        public static decimal GetNotionalAmount(PaymentCalculationPeriod paymentCalculationPeriod)
        {
            decimal result = 0.0m;

            decimal numberOfPeriods = 0.0m;

            foreach (CalculationPeriod calculationPeriod in XsdClassesFieldResolver.GetPaymentCalculationPeriod_CalculationPeriodArray(paymentCalculationPeriod))
            {
                result          += XsdClassesFieldResolver.CalculationPeriod_GetNotionalAmount(calculationPeriod);
                numberOfPeriods += 1;
            }

            return(result / numberOfPeriods);
        }
Exemple #17
0
        public static TermPoint Create(decimal mid, DateTime term)
        {
            TermPoint termPoint = new TermPoint();

            termPoint.mid          = mid;
            termPoint.midSpecified = true;

            TimeDimension timeDimension = new TimeDimension();

            XsdClassesFieldResolver.TimeDimension_SetDate(timeDimension, term);
            termPoint.term = timeDimension;

            return(termPoint);
        }
Exemple #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableSimpleInflationAsset"/> class.
 /// </summary>
 /// <param name="baseDate">The base date.</param>
 /// <param name="nodeStruct"></param>
 /// <param name="fixingCalendar"></param>
 /// <param name="paymentCalendar"></param>
 /// <param name="fixedRate">The fixed rate.</param>
 public PriceableSimpleZeroCouponInflationSwap(DateTime baseDate, SimpleIRSwapNodeStruct nodeStruct,
                                               IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fixedRate)
     : base(baseDate,
            XsdClassesFieldResolver.CalculationGetNotionalSchedule(nodeStruct.Calculation).notionalStepSchedule.initialValue, nodeStruct.DateAdjustments, fixedRate)
 {
     Id = nodeStruct.SimpleIRSwap.id;
     SimpleInflationSwap = nodeStruct.SimpleIRSwap;
     SpotDateOffset      = nodeStruct.SpotDate;
     Calculation         = nodeStruct.Calculation;
     UnderlyingRateIndex = nodeStruct.UnderlyingRateIndex;
     DayCounter          = DayCounterHelper.Parse(Calculation.dayCountFraction.Value);
     AdjustedStartDate   = GetSpotDate(baseDate, fixingCalendar, SpotDateOffset);
     RiskMaturityDate    = GetEffectiveDate(AdjustedStartDate, paymentCalendar, SimpleInflationSwap.term, nodeStruct.DateAdjustments.businessDayConvention);
     YearFraction        = GetYearFractions()[0];
 }
Exemple #19
0
        public static void SetSpread(PaymentCalculationPeriod paymentCalculationPeriod, decimal value)
        {
            foreach (CalculationPeriod calculationPeriod in XsdClassesFieldResolver.GetPaymentCalculationPeriod_CalculationPeriodArray(paymentCalculationPeriod))
            {
                if (XsdClassesFieldResolver.CalculationPeriod_HasFloatingRateDefinition(calculationPeriod))
                {
                    FloatingRateDefinition floatingRateDefinition = XsdClassesFieldResolver.CalculationPeriod_GetFloatingRateDefinition(calculationPeriod);

                    floatingRateDefinition.spread          = value;
                    floatingRateDefinition.spreadSpecified = true;
                }
                else
                {
                    throw new NotImplementedException("PaymentCalculationPeriodHelper.SetSpread cannot be called on a fixed rate cashflow.");
                }
            }
        }
Exemple #20
0
 public static void SetRate(PaymentCalculationPeriod paymentCalculationPeriod, decimal rate)
 {
     foreach (CalculationPeriod calculationPeriod in XsdClassesFieldResolver.GetPaymentCalculationPeriod_CalculationPeriodArray(paymentCalculationPeriod))
     {
         if (XsdClassesFieldResolver.CalculationPeriod_HasFixedRate(calculationPeriod))
         {
             XsdClassesFieldResolver.SetCalculationPeriod_FixedRate(calculationPeriod, rate);
         }
         else if (XsdClassesFieldResolver.CalculationPeriod_HasFloatingRateDefinition(calculationPeriod))
         {
             throw new NotImplementedException("Cannot modify floating rate, PaymentCalculationPeriodHelper.SetRate");
             //XsdClassesFieldResolver.CalculationPeriod_GetFloatingRateDefinition(calculationPeriod).calculatedRate;
         }
         else
         {
             throw new NotImplementedException("PaymentCalculationPeriodHelper.SetRate");
         }
     }
 }
Exemple #21
0
        public static Swaption Create(Swap swap, Payment[] premium, EuropeanExercise exercise, bool automaticExercise)
        {
            var swaption = new Swaption {
                swap = swap, premium = premium
            };
            var europeanExercise = exercise;

            swaption.exerciseProcedure = new ExerciseProcedure();
            if (automaticExercise)
            {
                XsdClassesFieldResolver.ExerciseProcedure_SetAutomaticExercise(swaption.exerciseProcedure, new AutomaticExercise());
            }
            else//manual exercise
            {
                XsdClassesFieldResolver.ExerciseProcedure_SetManualExercise(swaption.exerciseProcedure, new ManualExercise());
            }
            XsdClassesFieldResolver.Swaption_SetEuropeanExercise(swaption, europeanExercise);
            return(swaption);
        }
Exemple #22
0
 public static void ReplaceFloatingRateWithFixedRate(PaymentCalculationPeriod paymentCalculationPeriod, decimal fixedRate)
 {
     foreach (CalculationPeriod calculationPeriod in XsdClassesFieldResolver.GetPaymentCalculationPeriod_CalculationPeriodArray(paymentCalculationPeriod))
     {
         if (XsdClassesFieldResolver.CalculationPeriod_HasFixedRate(calculationPeriod))
         {
             throw new Exception("calculation period already uses a fixed rate.");
         }
         else if (XsdClassesFieldResolver.CalculationPeriod_HasFloatingRateDefinition(calculationPeriod))
         {
             // Replace FloatingRateDefinition with decimal (fixed rate)
             //
             XsdClassesFieldResolver.SetCalculationPeriod_FixedRate(calculationPeriod, fixedRate);
         }
         else
         {
             throw new NotSupportedException("PaymentCalculationPeriodHelper.ReplaceFloatingRateWithFixedRate");
         }
     }
 }
Exemple #23
0
        public static Swaption Create(Swap swap, decimal premiumAmount, DateTime expirationDate)
        {
            var swaption = new Swaption {
                swap = swap, premium = new[] { new Payment() }
            };

            swaption.premium[0].paymentAmount = MoneyHelper.GetAmount(premiumAmount);
            var europeanExercise = new EuropeanExercise
            {
                expirationDate = new AdjustableOrRelativeDate()
            };
            var adjustableDate = new AdjustableDate
            {
                unadjustedDate = new IdentifiedDate
                {
                    Value = expirationDate
                }
            };

            europeanExercise.expirationDate.Item = adjustableDate;
            XsdClassesFieldResolver.Swaption_SetEuropeanExercise(swaption, europeanExercise);
            return(swaption);
        }
Exemple #24
0
        public static decimal GetSpread(PaymentCalculationPeriod paymentCalculationPeriod)
        {
            decimal result          = 0.0m;
            decimal numberOfPeriods = 0.0m;

            foreach (CalculationPeriod calculationPeriod in XsdClassesFieldResolver.GetPaymentCalculationPeriod_CalculationPeriodArray(paymentCalculationPeriod))
            {
                if (XsdClassesFieldResolver.CalculationPeriod_HasFloatingRateDefinition(calculationPeriod))
                {
                    FloatingRateDefinition floatingRateDefinition = XsdClassesFieldResolver.CalculationPeriod_GetFloatingRateDefinition(calculationPeriod);

                    result += floatingRateDefinition.spread;
                }
                else
                {
                    throw new NotImplementedException("PaymentCalculationPeriodHelper.GetSpread cannot be called on fixed rate cashflow.");
                }

                numberOfPeriods += 1;
            }

            return(result / numberOfPeriods);
        }
        internal static TermCurve ConstructDiscountFactors(ILogger logger, ICoreCache cache, string nameSpace, TermCurve inputCurve, DateTime baseDate, string currency)
        {
            List <DateTime> dates      = inputCurve.point.Select(a => (DateTime)a.term.Items[0]).ToList();
            List <decimal>  values     = inputCurve.point.Select(a => a.mid).ToList();
            var             properties = new NamedValueSet();

            properties.Set(CurveProp.PricingStructureType, PricingStructureTypeEnum.RateCurve.ToString());
            properties.Set(CurveProp.Market, "ConstructDiscountFactors");
            properties.Set(CurveProp.IndexTenor, "0M");
            properties.Set(CurveProp.Currency1, currency);
            properties.Set(CurveProp.IndexName, "XXX-XXX");
            properties.Set(CurveProp.Algorithm, "FastLinearZero");
            properties.Set(CurveProp.BaseDate, baseDate);
            var curveId         = new RateCurveIdentifier(properties);
            var algorithmHolder = new PricingStructureAlgorithmsHolder(logger, cache, nameSpace, curveId.PricingStructureType, curveId.Algorithm);
            var curve           = new RateCurve(properties, algorithmHolder, dates, values);
            var termPoints      = new List <TermPoint>();

            for (DateTime date = dates.First(); date <= dates.Last(); date = date.AddMonths(1))
            {
                var discountFactor = (decimal)curve.GetDiscountFactor(date);
                var timeDimension  = new TimeDimension();
                XsdClassesFieldResolver.TimeDimensionSetDate(timeDimension, date);
                var termPoint = new TermPoint
                {
                    mid          = discountFactor,
                    midSpecified = true,
                    term         = timeDimension
                };
                termPoints.Add(termPoint);
            }
            var termCurve = new TermCurve {
                point = termPoints.ToArray()
            };

            return(termCurve);
        }
Exemple #26
0
        public List <ValuationInfoRangeItem> GetInfo(ICoreCache cache, string nameSpace, string valuationId)
        {
            var list = new List <ValuationInfoRangeItem>();
            var item = cache.LoadItem <ValuationReport>(nameSpace + "." + valuationId);

            if (item != null)
            {
                var valuationReport = (ValuationReport)item.Data;
                var envelope        = new ValuationInfoRangeItem
                {
                    Id          = valuationReport.header.messageId.Value,
                    Description = "envelope"
                };
                list.Add(envelope);
                foreach (TradeValuationItem tradeValuationItem in valuationReport.tradeValuationItem)
                {
                    foreach (Trade trade in tradeValuationItem.Items)
                    {
                        if (trade.tradeHeader.partyTradeIdentifier[0].Items[0] is TradeId tradeId)
                        {
                            var product = new ValuationInfoRangeItem
                            {
                                Id = tradeId.Value
                            };
                            if (trade.Item is Swap swap1)
                            {
                                product.Description = "swap";
                                var    swap     = swap1;
                                string leg1Type = GetInterestRateStreamType(swap.swapStream[0]);
                                string leg2Type = GetInterestRateStreamType(swap.swapStream[1]);

                                product.Description += $"({leg1Type}/{leg2Type})";
                            }
                            else if (trade.Item is Swaption)
                            {
                                product.Description = "swaption";
                            }
                            else
                            {
                                if (trade.Item is CapFloor floor)//could be cap, floor, or collar
                                {
                                    var         capFloor    = floor;
                                    Calculation calculation = XsdClassesFieldResolver.CalculationPeriodAmountGetCalculation(
                                        capFloor.capFloorStream.calculationPeriodAmount);
                                    FloatingRateCalculation floatingRateCalculation = XsdClassesFieldResolver.CalculationGetFloatingRateCalculation(calculation);
                                    if (null != floatingRateCalculation.capRateSchedule & null != floatingRateCalculation.floorRateSchedule)
                                    {
                                        product.Description = "collar";
                                    }
                                    else if (null != floatingRateCalculation.capRateSchedule)
                                    {
                                        product.Description = "cap";
                                    }
                                    else
                                    {
                                        product.Description = null != floatingRateCalculation.floorRateSchedule ? "floor" : "unknown product";
                                    }
                                }
                                else
                                {
                                    product.Description = "unknown product";
                                }
                            }
                            list.Add(product);
                        }
                    }
                }
            }
            return(list);
        }
Exemple #27
0
        private static string GetInterestRateStreamType(InterestRateStream interestRateStream)
        {
            Calculation calculation = XsdClassesFieldResolver.CalculationPeriodAmountGetCalculation(interestRateStream.calculationPeriodAmount);

            return(XsdClassesFieldResolver.CalculationHasFloatingRateCalculation(calculation) ? "float" : "fixed");
        }
Exemple #28
0
 public static CalculationPeriod[] GetCalculationPeriods(PaymentCalculationPeriod paymentCalculationPeriod)
 {
     return(XsdClassesFieldResolver.GetPaymentCalculationPeriod_CalculationPeriodArray(paymentCalculationPeriod));
 }
Exemple #29
0
        public static DateTime GetCalculationPeriodEndDate(PaymentCalculationPeriod paymentCalculationPeriod)
        {
            CalculationPeriod[] calculationPeriodArray = XsdClassesFieldResolver.GetPaymentCalculationPeriod_CalculationPeriodArray(paymentCalculationPeriod);

            return(calculationPeriodArray[calculationPeriodArray.Length - 1].adjustedEndDate);
        }
Exemple #30
0
 public static CalculationPeriod GetFirstCalculationPeriod(PaymentCalculationPeriod paymentCalculationPeriod)
 {
     return(XsdClassesFieldResolver.GetPaymentCalculationPeriod_CalculationPeriodArray(paymentCalculationPeriod)[0]);
 }