コード例 #1
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)
            {
                AnalyticsModel = new CommoditySpreadAssetAnalytic();
                // DependencyCreator.Resolve<IModelAnalytic<ISimpleAssetParameters, RateMetrics>>(_modelIdentifier);
            }
            //3. Get the Rate
            var endDF = GetIndex(interpolatedSpace, RiskMaturityDate, BaseDate);
            var analyticModelParameters = new CommodityAssetParameters
            {
                CommodityForward =
                    endDF
            };

            Values = new[] { endDF };
            if (Spread != null)
            {
                analyticModelParameters.Spread = MarketQuoteHelper.NormaliseGeneralPriceUnits(SpreadQuotationType, Spread, "MarketQuote").value;
            }
            AnalyticResults = new CommoditySpreadAssetResults();
            //4. Set the anaytic input parameters and Calculate the respective metrics
            //
            AnalyticResults = AnalyticsModel.Calculate <ICommoditySpreadAssetResults, CommoditySpreadAssetResults>(analyticModelParameters, new[] { CommoditySpreadMetrics.ImpliedQuote });
            return(AnalyticResults.ImpliedQuote);
        }
コード例 #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)
            {
                AnalyticsModel = new RateSpreadAssetAnalytic();
                // DependencyCreator.Resolve<IModelAnalytic<ISimpleAssetParameters, RateMetrics>>(_modelIdentifier);
            }
            //3. Get the Rate
            StartDiscountFactor = GetDiscountFactor(interpolatedSpace, AdjustedStartDate, BaseDate);
            EndDiscountFactor   = GetDiscountFactor(interpolatedSpace, RiskMaturityDate, BaseDate);
            ISimpleRateAssetParameters analyticModelParameters = new RateAssetParameters
            {
                YearFraction        = YearFraction,
                StartDiscountFactor =
                    StartDiscountFactor,
                EndDiscountFactor =
                    EndDiscountFactor
            };
            var fixedRate = GetRate(StartDiscountFactor, EndDiscountFactor, YearFraction);

            if (Spread != null)
            {
                analyticModelParameters.Rate = fixedRate + MarketQuoteHelper
                                               .NormaliseGeneralPriceUnits(SpreadQuotationType, Spread,
                                                                           "DecimalRate").value;
            }
            AnalyticResults = new RateSpreadAssetResults();
            //4. Set the anaytic input parameters and Calculate the respective metrics
            //
            AnalyticResults =
                AnalyticsModel.Calculate <IRateSpreadAssetResults, RateSpreadAssetResults>(analyticModelParameters,
                                                                                           new[] { RateSpreadMetrics.ImpliedQuote });
            return(AnalyticResults.ImpliedQuote);
        }
コード例 #3
0
        /// <summary>
        /// Calculates the specified metric for the fast bootstrapper.
        /// </summary>
        /// <param name="interpolatedSpace">The interpolated Space.</param>
        /// <returns></returns>
        public override decimal CalculateDiscountFactorAtMaturity(IInterpolatedSpace interpolatedSpace)
        {
            if (AnalyticsModel == null)
            {
                switch (ModelIdentifier)
                {
                case "SwapAsset":
                case "ClearedSwapAsset":
                    AnalyticsModel = new SimpleSwapAssetAnalytic();    //
                    break;
                }
            }
            ISwapAssetParameters analyticModelParameters = new IRSwapAssetParameters
            {
                YearFractions       = YearFractions,
                StartDiscountFactor =
                    GetDiscountFactor(interpolatedSpace,
                                      AdjustedStartDate, BaseDate),
                Rate =
                    CalculateImpliedQuote(interpolatedSpace) +
                    MarketQuoteHelper
                    .NormaliseGeneralPriceUnits(QuotationType, Spread,
                                                "DecimalRate").value
            };

            //3. Set the implied Rate with a spread
            //
            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.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;
            AnalyticsModel = new CommoditySpreadAssetAnalytic();
            //DependencyCreator.Resolve<IModelAnalytic<ISimpleAssetParameters, SpreadMetrics>>(_modelIdentifier);
            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(CommoditySpreadMetrics.IndexAtMaturity))
            {
                bEvalDiscountFactorAtMaturity = true;
                metrics.RemoveAll(
                    metricItem => metricItem != CommoditySpreadMetrics.IndexAtMaturity);
            }
            var analyticModelParameters = new CommodityAssetParameters();

            AnalyticResults = new CommoditySpreadAssetResults();
            var             metricsToEvaluate = metrics.ToArray();
            var             marketEnvironment = modelData.MarketEnvironment;
            ICommodityCurve curve             = null;

            //1. instantiate curve
            if (marketEnvironment.GetType() == typeof(SimpleMarketEnvironment))
            {
                curve     = (ICommodityCurve)((ISimpleMarketEnvironment)marketEnvironment).GetPricingStructure();
                CurveName = curve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(SimpleCommodityMarketEnvironment))
            {
                curve     = ((ISimpleCommodityMarketEnvironment)marketEnvironment).GetCommodityCurve();
                CurveName = curve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(MarketEnvironment))
            {
                curve = (ICommodityCurve)modelData.MarketEnvironment.GetPricingStructure(CurveName);
            }
            var endDF = GetIndex(curve, RiskMaturityDate, modelData.ValuationDate);

            Values = new[] { endDF };
            //3. Get the end discount factor
            analyticModelParameters.CommodityForward = endDF;
            if (Spread != null)
            {
                analyticModelParameters.Spread = MarketQuoteHelper.NormaliseGeneralPriceUnits(SpreadQuotationType, Spread, "Price").value;
            }
            if (bEvalDiscountFactorAtMaturity)
            {
                //4. Set the anaytic input parameters and Calculate the respective metrics
                AnalyticResults =
                    AnalyticsModel.Calculate <ICommoditySpreadAssetResults, CommoditySpreadAssetResults>(analyticModelParameters,
                                                                                                         metricsToEvaluate);
                ValueAtMaturity = AnalyticResults.IndexAtMaturity;
            }
            else
            {
                //4. Set the anaytic input parameters and Calculate the respective metrics
                AnalyticResults =
                    AnalyticsModel.Calculate <ICommoditySpreadAssetResults, CommoditySpreadAssetResults>(analyticModelParameters,
                                                                                                         metricsToEvaluate);
            }
            return(GetValue(AnalyticResults));
        }
コード例 #5
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;
            AnalyticsModel = new RateSpreadAssetAnalytic();
            //DependencyCreator.Resolve<IModelAnalytic<ISimpleAssetParameters, SpreadMetrics>>(_modelIdentifier);
            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;
            var bEvalDiscountFactorAtStart    = false;

            if (metrics.Contains(RateSpreadMetrics.DiscountFactorAtMaturity))
            {
                bEvalDiscountFactorAtMaturity = true;
                metrics.RemoveAll(
                    metricItem => metricItem != RateSpreadMetrics.DiscountFactorAtMaturity);
            }
            if (metrics.Contains(RateSpreadMetrics.DiscountFactorAtStart))
            {
                bEvalDiscountFactorAtStart = true;
                metrics.RemoveAll(
                    metricItem => metricItem != RateSpreadMetrics.DiscountFactorAtStart);
            }
            ISimpleRateAssetParameters analyticModelParameters = new RateAssetParameters {
                YearFraction = YearFraction
            };

            AnalyticResults = new RateSpreadAssetResults();
            var        metricsToEvaluate = metrics.ToArray();
            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);
            }
            //3. Get the Rate
            StartDiscountFactor = GetDiscountFactor(curve, AdjustedStartDate, modelData.ValuationDate);
            //2. get start df = curve.getvalue(this._adjustedStartDate);
            analyticModelParameters.StartDiscountFactor = StartDiscountFactor;
            EndDiscountFactor = GetDiscountFactor(curve, RiskMaturityDate, modelData.ValuationDate);
            var fixedRate = GetRate(StartDiscountFactor, EndDiscountFactor, YearFraction);

            if (Spread != null)
            {
                analyticModelParameters.Rate = fixedRate + MarketQuoteHelper
                                               .NormaliseGeneralPriceUnits(SpreadQuotationType, Spread,
                                                                           "DecimalRate").value;
            }
            if (bEvalDiscountFactorAtMaturity)
            {
                //4. Set the anaytic input parameters and Calculate the respective metrics
                AnalyticResults =
                    AnalyticsModel.Calculate <IRateSpreadAssetResults, RateSpreadAssetResults>(analyticModelParameters,
                                                                                               metricsToEvaluate);
            }
            if (bEvalDiscountFactorAtStart)
            {
                //4. Set the anaytic input parameters and Calculate the respective metrics
                AnalyticResults =
                    AnalyticsModel.Calculate <IRateSpreadAssetResults, RateSpreadAssetResults>(analyticModelParameters,
                                                                                               metricsToEvaluate);
            }
            else
            {
                //3. Get the end discount factor
                EndDiscountFactor = GetDiscountFactor(curve, GetRiskMaturityDate(), modelData.ValuationDate);
                analyticModelParameters.EndDiscountFactor = EndDiscountFactor;
                //4. Set the anaytic input parameters and Calculate the respective metrics
                AnalyticResults =
                    AnalyticsModel.Calculate <IRateSpreadAssetResults, RateSpreadAssetResults>(analyticModelParameters,
                                                                                               metricsToEvaluate);
            }
            return(GetValue(AnalyticResults));
        }