Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="ratecurve"></param>
        /// <param name="fixingCalendar"></param>
        /// <param name="paymentCalendar"></param>
        /// <returns></returns>
        public virtual decimal[] CalculatePDH(ILogger logger, ICoreCache cache, CurveBase ratecurve, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar)
        {
            if (AnalyticsModel == null)
            {
                switch (ModelIdentifier)
                {
                case "SimpleSwapAsset":
                case "ClearedSwapAsset":
                    AnalyticsModel = new SimpleSwapAssetAnalytic();
                    break;

                case "SimpleDiscountSwapAsset":
                case "DiscountClearedSwapAsset":
                    AnalyticsModel = new SimpleDiscountSwapAssetAnalytic();
                    break;
                }
            }
            var result = new List <decimal>();

            if (ratecurve != null)
            {
                var riskCurves = ratecurve.CreateCurveRiskSet(1);
                ISwapAssetParameters analyticModelParameters = new IRSwapAssetParameters
                {
                    NotionalAmount = Notional,
                    //2. Get the discount factors
                    DiscountFactors =
                        GetDiscountFactors(ratecurve,
                                           AdjustedPeriodDates.ToArray(),
                                           BaseDate),
                    //3. Get the respective year fractions
                    YearFractions = YearFractions,
                    Rate          =
                        MarketQuoteHelper.NormalisePriceUnits(
                            FixedRate, "DecimalRate").value
                };
                //4. Get the Weightings
                analyticModelParameters.Weightings =
                    CreateWeightings(CDefaultWeightingValue, analyticModelParameters.DiscountFactors.Length - 1);
                //4. Set the anaytic input parameters and Calculate the respective metrics
                //
                if (AnalyticsModel != null)
                {
                    var analyticResults = AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters, new[] { RateMetrics.NPV });
                    var baseNPV         = analyticResults.NPV;
                    //Now loop through the risk curves.
                    foreach (var curve in riskCurves)
                    {
                        analyticResults = RiskCalculationHelper((IRateCurve)curve, analyticModelParameters);
                        result.Add(analyticResults.NPV - baseNPV);
                    }
                }
            }
            return(result.ToArray());
        }
Пример #2
0
        /// <summary>
        /// Calculates the specified metric for the fast bootstrapper.
        /// </summary>
        /// <param name="interpolatedSpace">The intepolated Space.</param>
        /// <returns></returns>
        public override decimal CalculateImpliedQuote(IInterpolatedSpace interpolatedSpace)
        {
            if (AnalyticsModel == null)
            {
                switch (ModelIdentifier)
                {
                case "SwapAsset":
                case "SimpleSwapAsset":
                case "ClearedSwapAsset":
                    AnalyticsModel = new SimpleSwapAssetAnalytic();
                    break;

                case "DiscountSwapAsset":
                case "SimpleDiscountSwapAsset":
                case "DiscountClearedSwapAsset":
                    AnalyticsModel = new SimpleDiscountSwapAssetAnalytic();
                    break;
                }
            }
            ISwapAssetParameters analyticModelParameters = new IRSwapAssetParameters
            {
                NotionalAmount = Notional,
                //2. Get the discount factors
                DiscountFactors =
                    GetDiscountFactors(interpolatedSpace,
                                       AdjustedPeriodDates.ToArray(),
                                       BaseDate),
                //3. Get the respective year fractions
                YearFractions = YearFractions,
                Rate          =
                    MarketQuoteHelper.NormalisePriceUnits(
                        FixedRate, "DecimalRate").value
            };

            //4. Get the Weightings
            analyticModelParameters.Weightings =
                CreateWeightings(CDefaultWeightingValue, analyticModelParameters.DiscountFactors.Length - 1);
            AnalyticResults = new RateAssetResults();
            //4. Set the anaytic input parameters and Calculate the respective metrics
            //
            if (AnalyticsModel != null)
            {
                AnalyticResults = AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters, new[] { RateMetrics.ImpliedQuote });
            }
            return(AnalyticResults.ImpliedQuote);
        }
Пример #3
0
        /// <summary>
        /// Calculates the specified metric for the fast bootstrapper.
        /// </summary>
        /// <param name="interpolatedSpace">The intepolated Space.</param>
        /// <returns></returns>
        public override decimal CalculateDiscountFactorAtMaturity(IInterpolatedSpace interpolatedSpace)
        {
            if (AnalyticsModel == null)
            {
                switch (ModelIdentifier)
                {
                case "SwapAsset":
                case "SimpleSwapAsset":
                case "ClearedSwapAsset":
                    AnalyticsModel = new SimpleSwapAssetAnalytic();
                    break;

                case "DiscountSwapAsset":
                case "SimpleDiscountSwapAsset":
                case "DiscountClearedSwapAsset":
                    AnalyticsModel = new SimpleDiscountSwapAssetAnalytic();
                    break;
                }
            }
            ISwapAssetParameters analyticModelParameters = new IRSwapAssetParameters()
            {
                YearFractions       = YearFractions,
                StartDiscountFactor = GetDiscountFactor(interpolatedSpace, AdjustedStartDate, BaseDate)
            };

            //3. Get the Rate
            //
            if (FixedRate != null)
            {
                analyticModelParameters.Rate = MarketQuoteHelper.NormalisePriceUnits(FixedRate, "DecimalRate").value;
            }
            AnalyticResults = new RateAssetResults();
            //4. Set the anaytic input parameters and Calculate the respective metrics
            //
            if (AnalyticsModel == null)
            {
                return(1.0m);
            }
            AnalyticResults = AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters,
                                                                                             new[] { RateMetrics.DiscountFactorAtMaturity });
            return(AnalyticResults.DiscountFactorAtMaturity);
        }
Пример #4
0
        /// <summary>
        /// Calculates the specified model data.
        /// </summary>
        /// <param name="modelData">The model data.</param>
        /// <returns></returns>
        public override BasicAssetValuation Calculate(IAssetControllerData modelData)
        {
            ModelData = modelData;
            switch (ModelIdentifier)
            {
            case "SimpleSwapAsset":
                AnalyticsModel = new SimpleSwapAssetAnalytic();
                break;

            case "SimpleDiscountSwapAsset":
                AnalyticsModel = new SimpleDiscountSwapAssetAnalytic();
                break;
            }
            var metrics = MetricsHelper.GetMetricsToEvaluate(Metrics, AnalyticsModel.Metrics);
            // Determine if DFAM has been requested - if so thats all we evaluate - every other metric is ignored
            var bEvalDiscountFactorAtMaturity = false;

            if (metrics.Contains(RateMetrics.DiscountFactorAtMaturity))
            {
                bEvalDiscountFactorAtMaturity = true;
                metrics.RemoveAll(
                    metricItem => metricItem != RateMetrics.DiscountFactorAtMaturity);
            }
            var metricsToEvaluate = metrics.ToArray();

            AnalyticResults = new RateAssetResults();
            var        marketEnvironment = modelData.MarketEnvironment;
            IRateCurve curve             = null;

            //1. instantiate curve
            if (marketEnvironment.GetType() == typeof(SimpleMarketEnvironment))
            {
                curve     = (IRateCurve)((ISimpleMarketEnvironment)marketEnvironment).GetPricingStructure();
                CurveName = curve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(SimpleRateMarketEnvironment))
            {
                curve     = ((ISimpleRateMarketEnvironment)marketEnvironment).GetRateCurve();
                CurveName = curve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(SwapLegEnvironment))
            {
                curve     = ((ISwapLegEnvironment)marketEnvironment).GetDiscountRateCurve();
                CurveName = curve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(MarketEnvironment))
            {
                curve = (IRateCurve)modelData.MarketEnvironment.GetPricingStructure(CurveName);
            }
            //2. Set the rate
            var analyticModelParameters =
                new IRSwapAssetParameters
            {
                Rate = MarketQuoteHelper.NormalisePriceUnits(FixedRate, "DecimalRate").value
            };

            if (bEvalDiscountFactorAtMaturity)
            {
                //3. Set the start diccount factor
                analyticModelParameters.StartDiscountFactor =
                    GetDiscountFactor(curve, AdjustedStartDate, modelData.ValuationDate);
                //4. Get the respective year fractions
                analyticModelParameters.YearFractions = YearFractions;
                //5. Set the anaytic input parameters and Calculate the respective metrics
                AnalyticResults =
                    AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters,
                                                                                   metricsToEvaluate);
            }
            else
            {
                analyticModelParameters.NotionalAmount = Notional;
                //2. Get the discount factors
                analyticModelParameters.DiscountFactors =
                    GetDiscountFactors(curve, AdjustedPeriodDates.ToArray(), modelData.ValuationDate);
                //3. Get the respective year fractions
                analyticModelParameters.YearFractions = YearFractions;
                //4. Get the Weightings
                analyticModelParameters.Weightings = Weightings;
                //5. Set the anaytic input parameters and Calculate the respective metrics
                AnalyticResults =
                    AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters,
                                                                                   metricsToEvaluate);
            }
            return(GetValue(AnalyticResults));
        }