Esempio n. 1
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);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Generate a set of perturbed rate curves by just changing the market quote values of the priceable assets and
        /// thus not requiring the use of the cache or business calendars.
        /// THIS ONLY WORKS FOR MARKET QUOTES.
        /// </summary>
        /// <param name="baseDate"></param>
        /// <param name="perturbation"></param>
        /// <param name="priceableRateAssets"></param>
        /// <param name="extrapolationPermitted"></param>
        /// <param name="interpolationMethod"></param>
        /// <param name="tolerance"></param>
        /// <returns></returns>
        public static List <TermCurve> GenerateCurvesWithPerturbedMarketQuotes(DateTime baseDate, Decimal perturbation, List <IPriceableRateAssetController> priceableRateAssets,
                                                                               bool extrapolationPermitted, InterpolationMethod interpolationMethod, double tolerance)
        {
            var termCurves = new List <TermCurve>();

            //Modify the quotes.
            if (priceableRateAssets != null)
            {
                foreach (var rateAsset in priceableRateAssets)
                {
                    //Set up the new term curve.
                    var termCurve = new TermCurve
                    {
                        extrapolationPermitted = extrapolationPermitted, interpolationMethod = interpolationMethod
                    };
                    //Perturb the asset quote.
                    var quote          = rateAsset.MarketQuote.value;
                    var perturbedQuote = rateAsset.MarketQuote.value + perturbation;
                    rateAsset.MarketQuote.value = perturbedQuote;
                    termCurve.point             = RateBootstrapper.Bootstrap(priceableRateAssets, baseDate, extrapolationPermitted,
                                                                             interpolationMethod, tolerance);
                    //Reset the old value.
                    rateAsset.MarketQuote.value = quote;
                    //Add the perturbed term curve
                    termCurves.Add(termCurve);
                }
            }
            return(termCurves);
        }
Esempio n. 3
0
        /// <summary>
        /// Generate a set of perturbed rate curves by just changing the market quote values of the priceable assets and
        /// thus not requiring the use of the cache or business calendars.
        /// </summary>
        /// <param name="baseDate"></param>
        /// <param name="value"></param>
        /// <param name="assetPosition"></param>
        /// <param name="priceableRateAssets"></param>
        /// <param name="extrapolationPermitted"></param>
        /// <param name="interpolationMethod"></param>
        /// <param name="tolerance"></param>
        /// <returns></returns>
        public static TermCurve PerturbSpecificAsset(DateTime baseDate, Decimal value, int assetPosition, List <IPriceableRateAssetController> priceableRateAssets,
                                                     bool extrapolationPermitted, InterpolationMethod interpolationMethod, double tolerance)
        {
            //Set up the new term curve.
            var termCurve = new TermCurve();

            termCurve.extrapolationPermitted = extrapolationPermitted;
            termCurve.interpolationMethod    = interpolationMethod;
            //Modify the quotes.
            if (priceableRateAssets != null && assetPosition <= priceableRateAssets.Count)
            {
                //Perturb the aset quote.
                var quote          = priceableRateAssets[assetPosition].MarketQuote.value;
                var pertrubedQuote = priceableRateAssets[assetPosition].MarketQuote.value + value;
                priceableRateAssets[assetPosition].MarketQuote.value = pertrubedQuote;
                termCurve.point = RateBootstrapper.Bootstrap(priceableRateAssets, baseDate, extrapolationPermitted,
                                                             interpolationMethod, tolerance);
                //Reset the old value.
                priceableRateAssets[assetPosition].MarketQuote.value = quote;
            }
            return(termCurve);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the quoted asset set.
        /// </summary>
        /// <param name="baseDate"></param>
        /// <param name="values"></param>
        /// <param name="priceableRateAssets"></param>
        /// <param name="extrapolationPermitted"></param>
        /// <param name="interpolationMethod"></param>
        /// <param name="tolerance"></param>
        /// <returns></returns>
        public static TermCurve PerturbAllAssets(DateTime baseDate, Decimal[] values, List <IPriceableRateAssetController> priceableRateAssets,
                                                 bool extrapolationPermitted, InterpolationMethod interpolationMethod, double tolerance)
        {
            //Set up the new term curve.
            var termCurve = new TermCurve
            {
                extrapolationPermitted = extrapolationPermitted, interpolationMethod = interpolationMethod
            };

            //Modify the quotes.
            if (priceableRateAssets != null)
            {
                var quotes         = new List <decimal>();
                var numControllers = priceableRateAssets.Count;
                var valuesArray    = new decimal[numControllers];
                if (values.Length == numControllers)
                {
                    valuesArray = values;
                }
                if (values.Length < numControllers)
                {
                    for (var i = 0; i < values.Length; i++)
                    {
                        valuesArray[i] = values[i];
                    }
                    for (var i = values.Length; i < numControllers; i++)
                    {
                        valuesArray[i] = values[values.Length - 1];
                    }
                }
                else
                {
                    for (var i = 0; i < numControllers; i++)
                    {
                        valuesArray[i] = values[i];
                    }
                }
                var index = 0;
                foreach (var rateController in priceableRateAssets)
                {
                    //Perturb the asset quote.
                    var quote = rateController.MarketQuote.value;
                    quotes.Add(quote);
                    var perturbedQuote = quote + valuesArray[index];
                    rateController.MarketQuote.value = perturbedQuote;
                    index++;
                }
                termCurve.point =
                    RateBootstrapper.Bootstrap(priceableRateAssets, baseDate,
                                               extrapolationPermitted,
                                               interpolationMethod, tolerance);

                index = 0;
                foreach (var rateController in priceableRateAssets)
                {
                    //Reset the asset quote.
                    rateController.MarketQuote.value = quotes[index];
                    index++;
                }
            }
            return(termCurve);
        }