Example #1
0
        /// <summary>
        /// Generates a perturbed curve for those items specified.
        /// If the instruments are not valid they are excluded.
        /// </summary>
        /// <param name="perturbationArray">The perturbation Array: instrumentId and value.</param>
        /// <returns></returns>
        public IPricingStructure PerturbCurve(List <Pair <string, decimal> > perturbationArray)
        {
            if (PriceableOptionAssets == null)
            {
                return(null);
            }
            //Set the parameters and properties.
            NamedValueSet properties = GetPricingStructureId().Properties.Clone();
            string        uniqueId   = GetPricingStructureId().UniqueIdentifier;
            //Clone the properties.
            NamedValueSet curveProperties = properties.Clone();

            curveProperties.Set("PerturbedCurve", true);
            curveProperties.Set("BaseCurve", uniqueId);
            curveProperties.Set(CurveProp.UniqueIdentifier, uniqueId + "." + "PerturbedCurve");
            foreach (var instrument in perturbationArray)
            {
                //TODO clone the priceable assets.
                var asset = PriceableOptionAssets.FindAll(a => a.Id.Equals(instrument.First));
                if (asset[0] == null)
                {
                    continue;
                }
                var temp = asset[0];
                temp.MarketQuote.value = temp.MarketQuote.value + instrument.Second / 10000;
            }
            //Create the new curve.
            var capVolatilityCurve = new CapVolatilityCurve(curveProperties, PriceableOptionAssets, DiscountCurve, ForecastCurve, Holder);

            return(capVolatilityCurve);
        }
Example #2
0
        /// <summary>
        /// Creates the basic rate curve risk set, using the current curve as the base curve.
        /// This function takes a curves, creates a rate curve for each instrument and applying
        /// supplied basis point pertubation/spread to the underlying instrument in the spread curve
        /// </summary>
        /// <param name="basisPointPerturbation">The basis point perturbation.</param>
        /// <returns>A list of pertubed rate curves</returns>
        public override List <IPricingStructure> CreateCurveRiskSet(decimal basisPointPerturbation)
        {
            if (PriceableOptionAssets == null)
            {
                return(null);
            }
            //Set the parameters and properties.
            decimal       perturbation = basisPointPerturbation / 10000.0m;
            NamedValueSet properties   = GetPricingStructureId().Properties.Clone();

            properties.Set("PerturbedAmount", basisPointPerturbation);
            string uniqueId = GetPricingStructureId().UniqueIdentifier;
            //Get the assets
            int index      = 0;
            var structures = new List <IPricingStructure>();
            //Get the original quotes
            var quotes = GetMarketQuotes(PriceableOptionAssets);
            //Copy the assets.
            var priceableRateOptionAssets = new IPriceableOptionAssetController[PriceableOptionAssets.Count];

            PriceableOptionAssets.CopyTo(priceableRateOptionAssets);
            foreach (var instrument in priceableRateOptionAssets)
            {
                var perturbations = new decimal[quotes.Count];
                quotes.CopyTo(perturbations);
                //Clone the properties.
                NamedValueSet curveProperties = properties.Clone();
                perturbations[index] = quotes[index] + perturbation;
                curveProperties.Set("PerturbedAsset", instrument.Id);
                curveProperties.Set("BaseCurve", uniqueId);
                curveProperties.Set(CurveProp.UniqueIdentifier, uniqueId + "." + instrument.Id);
                curveProperties.Set(CurveProp.Tolerance, Tolerance);
                //Perturb the quotes
                PerturbedPriceableAssets(priceableRateOptionAssets.ToList(), perturbations);
                IPricingStructure rateCurve = new CapVolatilityCurve(curveProperties, priceableRateOptionAssets.ToList(), DiscountCurve, ForecastCurve, Holder);
                structures.Add(rateCurve);
                //Set the counter.
                perturbations[index] = 0;
                index++;
            }
            return(structures);
        }