Example #1
0
        /// <summary>
        /// Gets the quoted asset set.
        /// </summary>
        /// <returns></returns>
        public sealed override void Build(ILogger logger, ICoreCache cache, string nameSpace,
                                          IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
        {
            var pricingStructureId = (RateCurveIdentifier)PricingStructureIdentifier;

            //Order the assets.
            PriceableRateSpreadAssets = PriceableRateSpreadAssets.OrderBy(a => a.GetRiskMaturityDate()).ToList();
            var termCurve = SetConfigurationData();

            //Get the reference interpolated curve.
            termCurve.point = RateSpreadBootstrapper.Bootstrap(PriceableRateSpreadAssets,//TODO what about the interpoation.
                                                               BaseCurve,
                                                               pricingStructureId.BaseDate,
                                                               termCurve.extrapolationPermitted,
                                                               Tolerance);
            CreatePricingStructure(pricingStructureId, termCurve, PriceableAssetFactory.Parse(PriceableRateSpreadAssets));
            SetInterpolator(BaseCurve, pricingStructureId.PricingStructureType);
            // Set the Zero curve, just for reference
            YieldCurveValuation yieldCurveValuation = GetYieldCurveValuation();

            if (yieldCurveValuation.zeroCurve?.rateCurve == null)
            {
                //var curveId = (RateCurveIdentifier)PricingStructureIdentifier;
                //var psType = PricingStructureIdentifier.PricingStructureType;
                TermCurve curve = YieldCurveAnalytics.ToZeroCurve(termCurve, GetBaseDate(), CompoundingFrequency, DayCounter);
                curve.interpolationMethod = InterpolationMethodHelper.Parse(Holder.GetValue("CurveInterpolation"));
                var zeroCurve = new ZeroRateCurve
                {
                    rateCurve            = curve,
                    compoundingFrequency = FpML.V5r3.Reporting.CompoundingFrequency.Create(CompoundingFrequency)
                };
                yieldCurveValuation.zeroCurve = zeroCurve;
            }
        }
Example #2
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="spreadCurveData">The spread Curve Data</param>
        /// <param name="fixingCalendar">The fixingCalendar.</param>
        /// <param name="rollCalendar">The rollCalendar.</param>
        public RateBasisCurve(ILogger logger, ICoreCache cache, String nameSpace,
                              Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> referenceCurveData,
                              Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> spreadCurveData, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
            : base(spreadCurveData.Third, GenerateHolder(logger, cache, nameSpace, spreadCurveData.Third))
        {
            PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Rates, spreadCurveData.Third);
            //Set the identifier.
            var nvs = spreadCurveData.Third;
            var pricingStructureId = GetRateCurveId();
            var refCurveId         = PropertyHelper.ExtractReferenceCurveUniqueId(nvs);

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

            BaseCurve = (IRateCurve)PricingStructureFactory.Create(logger, cache, nameSpace, fixingCalendar, rollCalendar, baseCurveFpml, baseCurveProps);
            //Get the spread Data
            var spreadCurveFpml = new Pair <PricingStructure, PricingStructureValuation>(spreadCurveData.First, spreadCurveData.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;

            if (bootstrap || discountsAbsent)
            {
                //There must be a valid quoted asset set in order to bootstrap.
                if (!XsdClassesFieldResolver.QuotedAssetSetIsValid(spreadAssets))
                {
                    return;
                }
                PriceableRateSpreadAssets =
                    PriceableAssetFactory.CreatePriceableRateSpreadAssets(logger, cache, nameSpace, pricingStructureId.BaseDate, spreadAssets, fixingCalendar, rollCalendar);
                Build(logger, cache, nameSpace, fixingCalendar, rollCalendar);
            }
            else
            {
                // the discount curve is already built, so don't rebuild
                PriceableRateSpreadAssets = PriceableAssetFactory.CreatePriceableRateSpreadAssets(logger, cache, nameSpace, pricingStructureId.BaseDate, spreadAssets, fixingCalendar, rollCalendar);
                //Order the assets.
                PriceableRateSpreadAssets = PriceableRateSpreadAssets.OrderBy(a => a.GetRiskMaturityDate()).ToList();
                CreatePricingStructure(pricingStructureId, tempFpml.discountFactorCurve, PriceableAssetFactory.Parse(PriceableRateSpreadAssets));
                SetInterpolator(BaseCurve, pricingStructureId.PricingStructureType);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="nameSpace"></param>
        /// <param name="fixingCalendar"></param>
        /// <param name="rollCalendar"></param>
        public sealed override void Build(ILogger logger, ICoreCache cache, string nameSpace,
                                          IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)//TODO need to define the cutover point.
        {
            var pricingStructureId = (RateCurveIdentifier)PricingStructureIdentifier;

            //Order the assets.
            PriceableRateSpreadAssets = PriceableRateSpreadAssets.OrderBy(a => a.GetRiskMaturityDate()).ToList();
            //Generate the rate curve from the fx curve.
            var  fxProps        = ReferenceFxCurve.GetPricingStructureId().Properties;
            var  quoteBasisEnum = PropertyHelper.ExtractQuoteBasis(fxProps);
            bool isBaseCurve    = IsCurrency1RateCurve && quoteBasisEnum == QuoteBasisEnum.Currency2PerCurrency1;

            //var fxCurve = ReferenceFxCurve as FxCurve;
            //priceableAsset is PriceableCapRateAsset asset
            if (ReferenceFxCurve is FxCurve fxCurve)//fxCurve != null
            {
                var rateCurve = fxCurve.GenerateRateCurve(logger, cache, nameSpace, BaseCurve, isBaseCurve, pricingStructureId.GetProperties(), fixingCalendar, rollCalendar);
                //remove all points after the CutOverTerm.
                var rateCurvePoints = RemovePoints(rateCurve);
                //Retrieve the term curve.
                var termCurve = new TermCurve
                {
                    extrapolationPermitted          = rateCurve.GetTermCurve().extrapolationPermitted,
                    extrapolationPermittedSpecified =
                        rateCurve.GetTermCurve().extrapolationPermittedSpecified,
                    interpolationMethod = rateCurve.GetTermCurve().interpolationMethod,
                    point = rateCurvePoints
                };
                //Get the reference interpolated curve.
                termCurve.point = RateXccySpreadBootstrapper.Bootstrap(PriceableRateSpreadAssets,
                                                                       Currency2Curve,
                                                                       pricingStructureId.BaseDate,
                                                                       termCurve);
                CreatePricingStructure(pricingStructureId, termCurve, PriceableAssetFactory.Parse(PriceableRateSpreadAssets));
            }
            SetInterpolator(Currency2Curve, pricingStructureId.PricingStructureType);
        }