Exemple #1
0
        protected static PricingStructureAlgorithmsHolder GenerateHolder(ILogger logger, ICoreCache cache, String nameSpace, NamedValueSet properties)
        {
            var pricingStructureId = new RateCurveIdentifier(properties);
            var holder             = new PricingStructureAlgorithmsHolder(logger, cache, nameSpace, pricingStructureId.PricingStructureType, pricingStructureId.Algorithm);

            return(holder);
        }
Exemple #2
0
        //Clones a curve, maps the quoted assets specified and then returns an FpML structure back.
        //
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="nameSpace"></param>
        /// <param name="referenceCurve"></param>
        /// <param name="spreadValues"></param>
        /// <param name="properties"></param>
        /// <param name="fixingCalendar"></param>
        /// <param name="rollCalendar"></param>
        /// <returns></returns>
        public static Pair <PricingStructure, PricingStructureValuation> ProcessQuotedAssetSet(ILogger logger, ICoreCache cache,
                                                                                               string nameSpace, IRateCurve referenceCurve,
                                                                                               QuotedAssetSet spreadValues, NamedValueSet properties, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
        {
            var pricingStructureId = new RateCurveIdentifier(properties);
            Pair <PricingStructure, PricingStructureValuation> fpml = null;

            if (pricingStructureId.PricingStructureType != PricingStructureTypeEnum.RateBasisCurve)
            {
                //Clone the ref curves.
                //
                fpml = CloneCurve(referenceCurve.GetFpMLData(), pricingStructureId.UniqueIdentifier);
                //var ycCurveCloned = (YieldCurve)fpml.First;
                var ycvCurveCloned = (YieldCurveValuation)fpml.Second;
                //  assign id to the cloned YieldCurve
                //
                ycvCurveCloned.discountFactorCurve.point = null;
                ycvCurveCloned.zeroCurve    = null;
                ycvCurveCloned.forwardCurve = null;
                //Manipulate the quoted asset set.
                //
                ycvCurveCloned.inputs = MappedQuotedAssetSet(logger, cache, nameSpace, referenceCurve, spreadValues, properties, fixingCalendar, rollCalendar);
            }
            return(fpml);
        }
Exemple #3
0
        public void RateCurveIdConstructorWithCurveIdTest()
        {
            var rateCurve = new RateCurveIdentifier("RateCurve.AUD-ZERO-BANK-3M", DateTime.Today);

            Assert.IsNotNull(rateCurve);
            Assert.AreEqual(DateTime.Today, rateCurve.BaseDate);
            Assert.AreEqual("AUD-ZERO-BANK-3M", rateCurve.CurveName);
            Assert.AreEqual("AUD", rateCurve.Currency.Value);
            Assert.AreEqual("ZERO-BANK", rateCurve.Index);
            Assert.AreEqual("3M", rateCurve.IndexTenor);
        }
Exemple #4
0
        public void PricingStructureIdTestWithProperties10()
        {
            var props = new NamedValueSet();

            props.Set(CurveProp.PricingStructureType, "DiscountCurve");
            props.Set(CurveProp.CurveName, "AUD-NAB-SENIOR");
            props.Set("BuildDateTime", _baseDate);
            props.Set(CurveProp.BaseDate, _baseDate);
            props.Set("Algorithm", "Default");
            props.Set("Identifier", "Alex");
            var rateCurveId = new RateCurveIdentifier(props);

            Debug.Print("RateCurveIdentifier : {0} BuildDateTime : {1} CurveName : {2} PricingStructureType : {3} Algorithm : {4} Currency : {5} BaseDate : {6} CreditInstrumentId : {7} CreditSeniority : {8}",
                        rateCurveId.Id, rateCurveId.BuildDateTime, rateCurveId.CurveName, rateCurveId.PricingStructureType,
                        rateCurveId.Algorithm, rateCurveId.Currency.Value, rateCurveId.BaseDate, rateCurveId.CreditInstrumentId.Value, rateCurveId.CreditSeniority.Value);
        }
Exemple #5
0
        public void PricingStructureIdTestWithProperties11()
        {
            var props = new NamedValueSet();

            props.Set(CurveProp.PricingStructureType, "InflationCurve");
            props.Set(CurveProp.CurveName, LiborIndexName);
            props.Set("BuildDateTime", _baseDate);
            props.Set(CurveProp.BaseDate, _baseDate);
            props.Set("Algorithm", "Default");
            props.Set("Identifier", "Alex");
            props.Set(CurveProp.IndexName, "AUD-LIBOR-BBA");
            props.Set(CurveProp.IndexTenor, "3M");
            props.Set("InflationLag", "3M");
            var rateCurveId = new RateCurveIdentifier(props);

            Debug.Print("RateCurveIdentifier : {0} BuildDateTime : {1} CurveName : {2} PricingStructureType : {3} Algorithm : {4}Currency : {5} BaseDate : {6} InflationLag : {7}",
                        rateCurveId.Id, rateCurveId.BuildDateTime, rateCurveId.CurveName, rateCurveId.PricingStructureType,
                        rateCurveId.Algorithm, rateCurveId.Currency.Value, rateCurveId.BaseDate, rateCurveId.InflationLag);
        }
Exemple #6
0
 private static IRateCurve ExtractCurve(ILogger logger, ICoreCache cache,
                                        string nameSpace, IEnumerable <BasicAssetValuation> assetQuote,
                                        string curveName, string algorithm, DateTime baseDate, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
 {
     if (assetQuote != null)
     {
         var      basicAssetValuations = assetQuote as BasicAssetValuation[] ?? assetQuote.ToArray();
         string[] instruments          = ExtractInstruments(basicAssetValuations, curveName);
         if (!instruments.Any())
         {
             return(null);
         }
         var       curveId = new RateCurveIdentifier(PricingStructureTypeEnum.RateCurve, instruments[0], baseDate, algorithm);
         decimal[] values  = ExtractValues(basicAssetValuations, curveName);
         var       qas     = AssetHelper.Parse(instruments, values, null);
         return(new RateCurve(logger, cache, nameSpace, curveId, qas, fixingCalendar, rollCalendar));
     }
     return(null);
 }
        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);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RateXccySpreadCurve"/> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace">THe client namespace</param>
        /// <param name="baseCurveData">The market data. This must contain both the underlying base curve and the spread curve.
        /// Otherwise the RateBasisInterpolator can not instantiate.</param>
        /// <param name="referenceFxCurveData">The fxcurve referenced.</param>
        /// <param name="currency2CurveData">The curve data for the non base curve. This is normally the domestic curve i.e. AUD,
        /// as FX is quotes as xccy basis swaps adjust on the non-USD leg.</param>
        /// <param name="spreadCurveData">The spread Curve Data</param>
        /// <param name="fixingCalendar">The fixingCalendar.</param>
        /// <param name="rollCalendar">The rollCalendar.</param>
        public RateXccySpreadCurve(ILogger logger, ICoreCache cache, string nameSpace,
                                   Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> baseCurveData,
                                   Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> referenceFxCurveData,
                                   Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> currency2CurveData,
                                   Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> spreadCurveData, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
            : base(logger, cache, nameSpace, spreadCurveData, fixingCalendar, rollCalendar)
        {
            //Set the identifier.
            var nvs = spreadCurveData.Third;
            var pricingStructureId = new RateCurveIdentifier(nvs);

            PricingStructureIdentifier = pricingStructureId;
            var refCurveId = nvs.GetValue <string>(CurveProp.ReferenceCurveUniqueId);

            ReferenceCurveId = refCurveId != null ? new Identifier(refCurveId) : ReferenceCurveId = null;
            if (pricingStructureId.PricingStructureType != PricingStructureTypeEnum.RateXccyCurve)
            {
                return;
            }
            //Set the curve term.
            var cutOverTerm = spreadCurveData.Third.GetValue <string>("CutOverTerm");

            if (cutOverTerm != null)
            {
                CutOverTerm = PeriodHelper.Parse(cutOverTerm);
            }
            //Set the reference curve
            var baseCurveFpML  = new Pair <PricingStructure, PricingStructureValuation>(baseCurveData.First, baseCurveData.Second);
            var baseCurveProps = baseCurveData.Third;

            BaseCurve = (IRateCurve)PricingStructureFactory.Create(logger, cache, nameSpace, fixingCalendar, rollCalendar, baseCurveFpML, baseCurveProps);
            var fxCurveFpML  = new Pair <PricingStructure, PricingStructureValuation>(referenceFxCurveData.First, referenceFxCurveData.Second);
            var fxCurveProps = referenceFxCurveData.Third;

            ReferenceFxCurve = (IFxCurve)PricingStructureFactory.Create(logger, cache, nameSpace, fixingCalendar, rollCalendar, fxCurveFpML, fxCurveProps);
            //Set the reference curve
            var currency2CurveFpML  = new Pair <PricingStructure, PricingStructureValuation>(currency2CurveData.First, currency2CurveData.Second);
            var currency2CurveProps = currency2CurveData.Third;

            Currency2Curve = (RateCurve)PricingStructureFactory.Create(logger, cache, nameSpace, fixingCalendar, rollCalendar, currency2CurveFpML, currency2CurveProps);
            //Get the spread Data
            var spreadCurveFpML  = new Pair <PricingStructure, PricingStructureValuation>(spreadCurveData.First, spreadCurveData.Second);
            var spreadCurveProps = spreadCurveData.Third;

            IsCurrency1RateCurve = spreadCurveProps.GetValue <bool>("Currency1RateCurve");
            //Override properties.
            //var optimize = PropertyHelper.ExtractOptimizeBuildFlag(properties);TODO add this later.
            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 (cache == null)
            {
                bootstrap = false;
            }
            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
            {
                if (cache != null)
                {
                    // the discount curve is already built, so don't rebuild
                    PriceableRateSpreadAssets = PriceableAssetFactory.CreatePriceableRateSpreadAssets(logger, cache, nameSpace, pricingStructureId.BaseDate, spreadAssets, fixingCalendar, rollCalendar);
                    CreatePricingStructure(pricingStructureId, tempFpml.discountFactorCurve, PriceableAssetFactory.Parse(PriceableRateSpreadAssets));
                    SetInterpolator(BaseCurve, pricingStructureId.PricingStructureType);
                }
                else
                {
                    CreatePricingStructure(pricingStructureId, tempFpml.discountFactorCurve, spreadAssets);
                    SetInterpolator(BaseCurve, pricingStructureId.PricingStructureType);
                }
            }
        }