示例#1
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;
            if (AnalyticsModel == null)
            {
                AnalyticsModel = new EquityAssetAnalytic();
                //DependencyCreator.Resolve<IModelAnalytic<ISimpleAssetParameters, RateMetrics>>(_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 bEvalIndexAtMaturity = false;

            if (metrics.Contains(EquityMetrics.IndexAtMaturity))
            {
                bEvalIndexAtMaturity = true;
                // Remove all metrics except DFAM
                //
                metrics.RemoveAll(metricItem => metricItem != EquityMetrics.IndexAtMaturity);
            }
            var metricsToEvaluate = metrics.ToArray();
            IEquityAssetParameters analyticModelParameters = new EquityAssetParameters();

            CalculationResults = new EquityAssetResults();
            var          marketEnvironment = modelData.MarketEnvironment;
            IEquityCurve equitycurve       = null;

            //1. instantiate curve
            if (marketEnvironment.GetType() == typeof(SimpleMarketEnvironment))
            {
                equitycurve = (IEquityCurve)((ISimpleMarketEnvironment)marketEnvironment).GetPricingStructure();
            }
            if (marketEnvironment.GetType() == typeof(MarketEnvironment))
            {
                equitycurve = (IEquityCurve)modelData.MarketEnvironment.GetPricingStructure(EquityCurveName);
            }
            if (equitycurve != null)
            {
                //1. Get the current equity value from the curve.
                var equityValue = GetEquityFactor(equitycurve, modelData.ValuationDate, SettlementDate);
                //2. Set the market rate
                analyticModelParameters.Multiplier     = Multiplier;
                analyticModelParameters.Quote          = QuoteValue;
                analyticModelParameters.EquityPrice    = equityValue;
                analyticModelParameters.NotionalAmount = Notional;
                //3. Set the anaytic input parameters and Calculate the respective metrics
                AnalyticModelParameters = analyticModelParameters;
                CalculationResults      = AnalyticsModel.Calculate <IEquityAssetResults, EquityAssetResults>(analyticModelParameters, metricsToEvaluate);
                if (bEvalIndexAtMaturity)
                {
                    //4. Set the anaytic input parameters and Calculate the respective metrics
                    //
                    IndexAtMaturity = CalculationResults.IndexAtMaturity;
                }
                return(GetValue(CalculationResults));
            }
            return(null);
        }
        /// <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 LeaseAssetAnalytic();
            var metrics = MetricsHelper.GetMetricsToEvaluate(Metrics, AnalyticsModel.Metrics);
            // Determine if DFAM has been requested - if so that's all we evaluate - every other metric is ignored
            var metricsToEvaluate       = metrics.ToArray();
            var analyticModelParameters = new LeaseAssetParameters();

            CalculationResults = new LeaseAssetAnalytic();
            var marketEnvironment = modelData.MarketEnvironment;
            //IRateCurve rate forecast curve = null;
            IRateCurve leaseCurve = null;

            //0. Set the valuation date and recalculate the settlement date. This could mean regenerating all the coupon dates as well
            //Alternatively the lease can be recreated with a different base date = valuation date.
            //1. instantiate curve
            if (marketEnvironment.GetType() == typeof(SimpleMarketEnvironment))
            {
                leaseCurve             = (IRateCurve)((ISimpleMarketEnvironment)marketEnvironment).GetPricingStructure();
                LeaseDiscountCurveName = leaseCurve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(SimpleRateMarketEnvironment))
            {
                leaseCurve             = ((ISimpleRateMarketEnvironment)marketEnvironment).GetRateCurve();
                LeaseDiscountCurveName = leaseCurve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(SwapLegEnvironment))
            {
                leaseCurve             = ((ISwapLegEnvironment)marketEnvironment).GetDiscountRateCurve();
                LeaseDiscountCurveName = leaseCurve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(MarketEnvironment))
            {
                leaseCurve = (IRateCurve)modelData.MarketEnvironment.GetPricingStructure(LeaseDiscountCurveName);
            }
            //2. Set the rate and the Multiplier
            analyticModelParameters.Multiplier = Multiplier;
            //analyticModelParameters.Quote = QuoteValue;
            analyticModelParameters.GrossAmount = StartAmount;
            analyticModelParameters.StepUp      = LeaseRate;
            //3. Get the discount factors
            analyticModelParameters.PaymentDiscountFactors =
                GetDiscountFactors(leaseCurve, AdjustedPeriodDates, modelData.ValuationDate);
            //4. Get the Weightings
            analyticModelParameters.Weightings = Weightings;
            //5. Set the analytic input parameters and Calculate the respective metrics
            AnalyticModelParameters = analyticModelParameters;
            CalculationResults      =
                AnalyticsModel.Calculate <ILeaseAssetResults, LeaseAssetResults>(analyticModelParameters,
                                                                                 metricsToEvaluate);
            //ExpectedCashflows =
            //CashflowPVs =
            return(GetValue(CalculationResults));
        }
        /// <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 "CapAsset":
                AnalyticsModel = new RateOptionAssetAnalytic();
                break;

            case "DiscountCapAsset":
                AnalyticsModel = new RateOptionAssetAnalytic();
                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 bEvalLastForewardVolatiltiy = false;

            if (metrics.Contains(RateOptionMetrics.VolatilityAtExpiry))
            {
                bEvalLastForewardVolatiltiy = true;
                metrics.RemoveAll(
                    metricItem => metricItem != RateOptionMetrics.VolatilityAtExpiry);
            }
            var metricsToEvaluate = metrics.ToArray();
            IRateOptionAssetParameters analyticModelParameters = new RateOptionAssetParameters();

            AnalyticResults = new RateOptionAssetResults();
            var marketEnvironment = modelData.MarketEnvironment;

            //1. instantiate curve
            if (marketEnvironment.GetType() == typeof(SimpleMarketEnvironment))
            {
                DiscountCurve     = (IRateCurve)((ISimpleMarketEnvironment)marketEnvironment).GetPricingStructure();
                DiscountCurveName = DiscountCurve.GetPricingStructureId().UniqueIdentifier;
                ForecastCurve     = DiscountCurve;
                ForecastCurveName = DiscountCurveName;
                var volatilities = CreateList((double)Volatility, TimesToExpiry.Count);
                analyticModelParameters.Volatilities = volatilities;
            }
            if (marketEnvironment.GetType() == typeof(SwapLegEnvironment))
            {
                DiscountCurve       = ((ISwapLegEnvironment)marketEnvironment).GetDiscountRateCurve();
                DiscountCurveName   = DiscountCurve.GetPricingStructureId().UniqueIdentifier;
                ForecastCurve       = ((ISwapLegEnvironment)marketEnvironment).GetForecastRateCurve();
                ForecastCurveName   = ForecastCurve.GetPricingStructureId().UniqueIdentifier;
                VolatilityCurve     = ((ISwapLegEnvironment)marketEnvironment).GetVolatilitySurface();
                VolatilityCurveName = VolatilityCurve.GetPricingStructureId().UniqueIdentifier;
                analyticModelParameters.Volatilities = GetVolatilties(VolatilityCurve, TimesToExpiry, Strikes);
            }
            if (marketEnvironment.GetType() == typeof(MarketEnvironment))
            {
                if (DiscountCurveName != null)
                {
                    DiscountCurve = (IRateCurve)modelData.MarketEnvironment.GetPricingStructure(DiscountCurveName);
                }
                if (ForecastCurveName != null)
                {
                    ForecastCurve = (IRateCurve)modelData.MarketEnvironment.GetPricingStructure(ForecastCurveName);
                }
                if (VolatilityCurveName != null)
                {
                    VolatilityCurve = (IVolatilitySurface)modelData.MarketEnvironment.GetPricingStructure(VolatilityCurveName);
                }
                analyticModelParameters.Volatilities = GetVolatilties(VolatilityCurve, TimesToExpiry, Strikes);
            }
            analyticModelParameters.FlatVolatility = Volatility;
            //2. Set the premium
            if (Premium == null)
            {
                Premium = CalculatePremium();
            }
            if (Premium != null)
            {
                analyticModelParameters.Premium = (double)Premium;
            }
            if (bEvalLastForewardVolatiltiy)
            {
                //3. Set the start diccount factor and vol.
                analyticModelParameters.PremiumPaymentDiscountFactor =
                    GetDiscountFactor(DiscountCurve, AdjustedStartDate, modelData.ValuationDate);
                //4. Get the respective year fractions
                analyticModelParameters.YearFractions = GetYearFractions();
                //5. Set the anaytic input parameters and Calculate the respective metrics
                AnalyticResults =
                    AnalyticsModel.Calculate <IRateOptionAssetResults, RateOptionAssetResults>(analyticModelParameters,
                                                                                               metricsToEvaluate);
            }
            else
            {
                analyticModelParameters.IsDiscounted = false;
                analyticModelParameters.IsPut        = !IsCap;
                analyticModelParameters.Notionals    = Notionals;
                analyticModelParameters.ForwardRates = ResetRates;
                //2. Get the discount factors
                analyticModelParameters.PaymentDiscountFactors =
                    GetDiscountFactors(DiscountCurve, AdjustedPeriodDates.ToArray(), modelData.ValuationDate);
                analyticModelParameters.ForecastDiscountFactors =
                    GetDiscountFactors(ForecastCurve, AdjustedPeriodDates.ToArray(), modelData.ValuationDate);
                //3. Get the respective year fractions
                analyticModelParameters.YearFractions = GetYearFractions();
                analyticModelParameters.Strikes       = Strikes;
                analyticModelParameters.Rate          = (double)CalculateImpliedParRate(modelData.ValuationDate);
                analyticModelParameters.TimesToExpiry = TimesToExpiry;
                //5. Set the anaytic input parameters and Calculate the respective metrics
                AnalyticResults =
                    AnalyticsModel.Calculate <IRateOptionAssetResults, RateOptionAssetResults>(analyticModelParameters,
                                                                                               metricsToEvaluate);
            }
            return(GetValue(AnalyticResults));
        }
示例#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 "CapAsset":
                AnalyticsModel = new RateOptionAssetAnalytic();
                break;

            case "DiscountCapAsset":
                AnalyticsModel = new RateOptionAssetAnalytic();
                break;
            }
            var metrics                 = MetricsHelper.GetMetricsToEvaluate(Metrics, AnalyticsModel.Metrics);
            var metricsToEvaluate       = metrics.ToArray();
            var analyticModelParameters = new RateOptionAssetParameters();

            AnalyticResults = new RateOptionAssetResults();
            var                marketEnvironment = modelData.MarketEnvironment;
            IRateCurve         rateCurve         = null;
            IRateCurve         discountCurve     = null;
            IVolatilitySurface volCurve          = null;

            //1. instantiate curve
            if (marketEnvironment.GetType() == typeof(SwapLegEnvironment))
            {
                rateCurve           = ((ISwapLegEnvironment)marketEnvironment).GetForecastRateCurve();
                ForecastCurveName   = rateCurve.GetPricingStructureId().UniqueIdentifier;
                discountCurve       = ((ISwapLegEnvironment)marketEnvironment).GetDiscountRateCurve();
                DiscountCurveName   = discountCurve.GetPricingStructureId().UniqueIdentifier;
                volCurve            = ((ISwapLegEnvironment)marketEnvironment).GetVolatilitySurface();
                VolatilityCurveName = volCurve.GetPricingStructureId().UniqueIdentifier;
            }
            //Cap logic.
            analyticModelParameters.IsPut = !IsCap;
            //1. Notionals
            analyticModelParameters.Notionals = Notionals;
            //and the rest rates
            if (ResetRates != null)
            {
                analyticModelParameters.ForwardRates = ResetRates;
            }
            //2. Get the discount factors
            analyticModelParameters.ForecastDiscountFactors =
                GetDiscountFactors(rateCurve, AdjustedPeriodDates.ToArray(), modelData.ValuationDate);
            analyticModelParameters.PaymentDiscountFactors =
                GetDiscountFactors(discountCurve, AdjustedPeriodDates.ToArray(), modelData.ValuationDate);
            //3. Get the respective year fractions
            analyticModelParameters.YearFractions = YearFractions;
            //4. set the expiry times.
            TimesToExpiry =
                GetTimesToExpiry(ExpiryDates, modelData.ValuationDate);
            analyticModelParameters.TimesToExpiry = TimesToExpiry;
            //5. Get the vols
            analyticModelParameters.Volatilities =
                GetVolatilties(volCurve, TimesToExpiry, Strikes);
            //8. Get the Strikes
            analyticModelParameters.Strikes = Strikes;
            ParRate = CalculateImpliedParRate(modelData.ValuationDate);
            analyticModelParameters.Rate = (double)ParRate;
            //9. Set the analytic input parameters and Calculate the respective metrics
            AnalyticResults =
                AnalyticsModel.Calculate <IRateOptionAssetResults, RateOptionAssetResults>(analyticModelParameters,
                                                                                           metricsToEvaluate);
            //TODO change this method and return a table report of all greeks.
            return(GetValue(AnalyticResults));
        }
        /// <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));
        }
        /// <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 CommodityAssetAnalytic();
            //DependencyCreator.Resolve<IModelAnalytic<ICommodityAssetParameters, CommodityMetrics>>(_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 bEvalForwardAtMaturity = false;

            if (metrics.Contains(CommodityMetrics.IndexAtMaturity))
            {
                bEvalForwardAtMaturity = true;
                metrics.RemoveAll(
                    metricItem => metricItem != CommodityMetrics.IndexAtMaturity);
            }
            ICommodityAssetParameters analyticModelParameters = new CommodityAssetParameters();

            AnalyticResults = new CommodityAssetResults();
            var metricsToEvaluate = metrics.ToArray();
            var marketEnvironment = modelData.MarketEnvironment;
            //1. instantiate curve
            ICommodityCurve commodityCurve = null;

            //1. instantiate curve
            if (marketEnvironment.GetType() == typeof(SimpleMarketEnvironment))
            {
                commodityCurve     = (ICommodityCurve)((ISimpleMarketEnvironment)marketEnvironment).GetPricingStructure();
                CommodityCurveName = commodityCurve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(SimpleCommodityMarketEnvironment))
            {
                commodityCurve     = ((ISimpleCommodityMarketEnvironment)marketEnvironment).GetCommodityCurve();
                CommodityCurveName = commodityCurve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(SwapLegEnvironment))
            {
                commodityCurve     = ((ISwapLegEnvironment)marketEnvironment).GetCommodityCurve();
                CommodityCurveName = commodityCurve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(MarketEnvironment))
            {
                commodityCurve = (ICommodityCurve)modelData.MarketEnvironment.GetPricingStructure(CommodityCurveName);
            }
            //3. Get the Rate
            if (CommodityValue != null)
            {
                analyticModelParameters.CommodityForward = CommodityValue.value;
            }
            if (bEvalForwardAtMaturity)
            {
                //4. Set the anaytic input parameters and Calculate the respective metrics
                AnalyticResults =
                    AnalyticsModel.Calculate <ICommodityAssetResults, CommodityAssetResults>(analyticModelParameters,
                                                                                             metricsToEvaluate);
                //_forwardAtMaturity = ForwardAtMaturity;
            }
            else
            {
                analyticModelParameters.NotionalAmount = NotionalAmount;
                IDayCounter dc = Actual365.Instance;
                analyticModelParameters.YearFraction = (decimal)dc.YearFraction(modelData.ValuationDate, RiskMaturityDate);
                //3. Get the end discount factor - Need to fix this.
                analyticModelParameters.CommodityCurveForward =
                    GetIndexAtMaturity(commodityCurve, GetRiskMaturityDate(), modelData.ValuationDate);

                //4. Set the anaytic input parameters and Calculate the respective metrics
                AnalyticResults =
                    AnalyticsModel.Calculate <ICommodityAssetResults, CommodityAssetResults>(analyticModelParameters,
                                                                                             metricsToEvaluate);
            }
            return(GetValue(AnalyticResults));
        }
        /// <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 InflationAssetAnalytic();
            //DependencyCreator.Resolve<IModelAnalytic<ISimpleDualAssetParameters, RateMetrics>>("InflationAsset");
            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);
            }

            ISimpleDualAssetParameters analyticModelParameters = new DualRateAssetParameters
            {
                YearFraction = YearFraction
            };

            AnalyticResults = new RateAssetResults();
            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);
            }
            //2. get start df = curve.getvalue(this._adjustedStartDate);
            analyticModelParameters.StartDiscountFactor =
                GetDiscountFactor(curve, AdjustedStartDate, modelData.ValuationDate);
            //3. Get the Rate
            analyticModelParameters.Rate = MarketQuoteHelper.NormalisePriceUnits(FixedRate, "DecimalRate").value;
            if (bEvalDiscountFactorAtMaturity)
            {
                //4. Set the anaytic input parameters and Calculate the respective metrics
                AnalyticResults =
                    AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters,
                                                                                   metricsToEvaluate);
                EndDiscountFactor = DiscountFactorAtMaturity;
            }
            else
            {
                analyticModelParameters.NotionalAmount = Notional;
                //3. Get the end index discount factor
                analyticModelParameters.EndDiscountFactor =
                    GetDiscountFactor(curve, GetRiskMaturityDate(), modelData.ValuationDate);
                //4. Get the payment discount factor
                analyticModelParameters.PaymentDiscountFactor =
                    GetDiscountFactor(curve, GetRiskMaturityDate(), modelData.ValuationDate);
                //5. Set the anaytic input parameters and Calculate the respective metrics
                AnalyticResults =
                    AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters,
                                                                                   metricsToEvaluate);
            }
            return(GetValue(AnalyticResults));
        }
示例#8
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 ZeroCouponRateAssetAnalytic();
            //DependencyCreator.Resolve<IModelAnalytic<IZeroRateAssetParameters, RateMetrics>>(_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(RateMetrics.DiscountFactorAtMaturity))
            {
                bEvalDiscountFactorAtMaturity = true;
                // Remove all metrics except DFAM
                //
                metrics.RemoveAll(metricItem => metricItem != RateMetrics.DiscountFactorAtMaturity);
            }
            IZeroRateAssetParameters analyticModelParameters = new ZeroRateAssetParameters {
                YearFraction = YearFraction
            };

            CalculationResults = new RateAssetResults();
            var metricsToEvaluate = metrics.ToArray();

            analyticModelParameters.PeriodAsTimesPerYear =
                CompoundingHelper.PeriodFractionFromCompoundingFrequency(BaseDate, CompoundingFrequency, DayCountFraction);
            var        marketEnvironment = modelData.MarketEnvironment;
            IRateCurve curve             = null;

            //1. instantiate curve
            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);
            }
            //
            analyticModelParameters.StartDiscountFactor = GetDiscountFactor(curve, BaseDate, modelData.ValuationDate);
            //3. Get the Rate
            //
            if (FixedRate != null)
            {
                analyticModelParameters.Rate = MarketQuoteHelper.NormalisePriceUnits(FixedRate, "DecimalRate").value;
            }
            if (bEvalDiscountFactorAtMaturity)
            {
                //4. Set the anaytic input parameters and Calculate the respective metrics
                //
                CalculationResults = AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters, metricsToEvaluate);
                EndDiscountFactor  = CalculationResults.DiscountFactorAtMaturity;
            }
            else
            {
                analyticModelParameters.NotionalAmount = Notional;
                //3. Get the end discount factor
                //
                analyticModelParameters.EndDiscountFactor = GetDiscountFactor(curve, GetRiskMaturityDate(), modelData.ValuationDate);
                //4. Set the anaytic input parameters and Calculate the respective metrics
                //
                CalculationResults = AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters, metricsToEvaluate);
            }

            return(GetValue(CalculationResults));
        }
        /// <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 BondAssetAnalytic();
            var metrics = MetricsHelper.GetMetricsToEvaluate(Metrics, AnalyticsModel.Metrics);
            // Determine if DFAM has been requested - if so that's all we evaluate - every other metric is ignored
            var metricsToEvaluate       = metrics.ToArray();
            var analyticModelParameters = new BondAssetParameters();

            CalculationResults = new BondAssetResults();
            var marketEnvironment = modelData.MarketEnvironment;
            //IRateCurve rate forecast curve = null;
            IRateCurve rateDiscountCurve = null;

            //0. Set the valuation date and recalculate the settlement date. This could mean regenerating all the coupon dates as well
            //Alternatively the bond can be recreated with a different base date = valuation date.
            //TODO Check that the dates are correct and that the last coupon date is used.
            //Set the purchase price.
            analyticModelParameters.PurchasePrice = PurchasePrice;
            //1. instantiate curve
            if (marketEnvironment.GetType() == typeof(SimpleMarketEnvironment))
            {
                rateDiscountCurve     = (IRateCurve)((ISimpleMarketEnvironment)marketEnvironment).GetPricingStructure();
                SwapDiscountCurveName = rateDiscountCurve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(SimpleRateMarketEnvironment))
            {
                rateDiscountCurve     = ((ISimpleRateMarketEnvironment)marketEnvironment).GetRateCurve();
                SwapDiscountCurveName = rateDiscountCurve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(SwapLegEnvironment))
            {
                rateDiscountCurve     = ((ISwapLegEnvironment)marketEnvironment).GetDiscountRateCurve();
                SwapDiscountCurveName = rateDiscountCurve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(MarketEnvironment))
            {
                var bondCurve = (IBondCurve)modelData.MarketEnvironment.GetPricingStructure(BondCurveName);
                if (bondCurve != null)
                {
                    var marketDataType =
                        bondCurve.GetPricingStructureId().Properties.GetValue <string>(AssetMeasureEnum.MarketQuote.ToString(), false);
                    if (marketDataType != null && marketDataType == BondPriceEnum.YieldToMaturity.ToString())
                    {
                        IsYTMQuote = true;
                    }
                    //TODO handle the other cases like: AssetSwapSpread; DirtyPrice and ZSpread.
                    var mq = (decimal)bondCurve.GetYieldToMaturity(modelData.ValuationDate, SettlementDate);
                    Quote = BasicQuotationHelper.Create(mq, AssetMeasureEnum.MarketQuote.ToString(),
                                                        PriceQuoteUnitsEnum.DecimalRate.ToString());
                }
                //The forecast rate curve will need to be set if it is a floating rate note.
                rateDiscountCurve = (IRateCurve)modelData.MarketEnvironment.GetPricingStructure(SwapDiscountCurveName);
            }
            //2. Set the rate and the Multiplier
            analyticModelParameters.Multiplier             = Multiplier;
            analyticModelParameters.Quote                  = QuoteValue;
            analyticModelParameters.CouponRate             = GetCouponRate();
            analyticModelParameters.NotionalAmount         = Notional;
            analyticModelParameters.Frequency              = Frequency;
            analyticModelParameters.IsYTMQuote             = IsYTMQuote;
            analyticModelParameters.AccruedFactor          = GetAccruedFactor();
            analyticModelParameters.RemainingAccruedFactor = GetRemainingAccruedFactor();
            //3. Get the discount factors
            analyticModelParameters.PaymentDiscountFactors =
                GetDiscountFactors(rateDiscountCurve, AdjustedPeriodDates, modelData.ValuationDate);
            //4. Get the respective year fractions
            analyticModelParameters.AccrualYearFractions = GetYearFractions();
            //5. Get the Weightings
            Weightings =
                CreateWeightings(CDefaultWeightingValue, analyticModelParameters.PaymentDiscountFactors.Length);
            analyticModelParameters.Weightings = Weightings;
            //6. Set the analytic input parameters and Calculate the respective metrics
            AnalyticModelParameters = analyticModelParameters;
            CalculationResults      =
                AnalyticsModel.Calculate <IBondAssetResults, BondAssetResults>(analyticModelParameters,
                                                                               metricsToEvaluate);
            return(GetValue(CalculationResults));
        }
示例#10
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;
            if (AnalyticsModel == null)
            {
                //AnalyticsModel =
                //    DependencyCreator.Resolve<IModelAnalytic<ISimpleOptionAssetParameters, RateOptionMetrics>>(
                //        ModelIdentifier);
                AnalyticsModel = new SimpleRateOptionAssetAnalytic();
            }
            var metrics = MetricsHelper.GetMetricsToEvaluate(Metrics, AnalyticsModel.Metrics);
            // Determine if DFAM has been requested - if so that all we evaluate - every other metric is ignored
            //
            var bEvalVolatilityAtRiskMaturity = false;

            if (metrics.Contains(RateOptionMetrics.VolatilityAtExpiry))
            {
                bEvalVolatilityAtRiskMaturity = true;
                // Remove all metrics except DFAM
                //
                metrics.RemoveAll(metricItem => metricItem != RateOptionMetrics.VolatilityAtExpiry);
            }
            ISimpleOptionAssetParameters analyticModelParameters = new SimpleRateOptionAssetParameters {
                YearFraction = YearFraction
            };

            AnalyticResults = new SimpleRateOptionAssetResults();
            var metricsToEvaluate = metrics.ToArray();

            if (IsVolatilityQuote)
            {
                analyticModelParameters.IsVolatilityQuote = true;
                analyticModelParameters.Volatility        = Volatility;
            }
            if (bEvalVolatilityAtRiskMaturity && IsVolatilityQuote)
            {
                analyticModelParameters.IsVolatilityQuote = true;
                AnalyticResults = AnalyticsModel.Calculate <ISimpleRateOptionAssetResults, SimpleRateOptionAssetResults>(analyticModelParameters, metricsToEvaluate);
                return(GetValue(AnalyticResults));
            }
            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);
            }
            analyticModelParameters.IsPut = !IsCap;
            //A cap is a call option on the rate. This rate should reflect the underlying Xibor
            analyticModelParameters.Rate = GetRate(curve, modelData.ValuationDate, AdjustedEffectiveDate,
                                                   MaturityDate, YearFraction);
            analyticModelParameters.Premium = Premium;
            //2. get start df = curve.getvalue(this._adjustedStartDate);
            //
            analyticModelParameters.StartDiscountFactor = GetDiscountFactor(curve, AdjustedEffectiveDate,
                                                                            modelData.ValuationDate);
            analyticModelParameters.PremiumPaymentDiscountFactor = GetDiscountFactor(curve, PaymentDate,
                                                                                     modelData.ValuationDate);
            analyticModelParameters.NotionalAmount = Notional;
            analyticModelParameters.IsDiscounted   = IsDiscounted;
            //3. Get the end discount factor
            //
            analyticModelParameters.EndDiscountFactor = GetDiscountFactor(curve, MaturityDate,
                                                                          modelData.ValuationDate);
            analyticModelParameters.Strike       = Strike;
            analyticModelParameters.TimeToExpiry = TimeToExpiry;
            if (bEvalVolatilityAtRiskMaturity && !IsVolatilityQuote)
            {
                AnalyticResults =
                    AnalyticsModel.Calculate <ISimpleRateOptionAssetResults, SimpleRateOptionAssetResults>(
                        analyticModelParameters, metricsToEvaluate);
                return(GetValue(AnalyticResults));
            }
            if (!IsVolatilityQuote)
            {
                IVolatilitySurface volCurve;
                if (marketEnvironment.GetType() == typeof(SwapLegEnvironment))
                {
                    var me = (ISwapLegEnvironment)marketEnvironment;
                    volCurve     = me.GetVolatilitySurface();
                    VolCurveName = volCurve.GetPricingStructureId().UniqueIdentifier;
                }
                else
                {
                    volCurve = (IVolatilitySurface)modelData.MarketEnvironment.GetPricingStructure(VolCurveName);
                }
                analyticModelParameters.Volatility =
                    Convert.ToDecimal(volCurve.GetValue((double)TimeToExpiry, (double)Strike));
            }
            //4. Set the analytic input parameters and Calculate the respective metrics
            //
            AnalyticResults =
                AnalyticsModel.Calculate <ISimpleRateOptionAssetResults, SimpleRateOptionAssetResults>(analyticModelParameters,
                                                                                                       metricsToEvaluate);
            return(GetValue(AnalyticResults));
        }
示例#11
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 "SwapAsset":
                AnalyticsModel = new SwapAssetAnalytic();
                break;

            case "DiscountSwapAsset":
                AnalyticsModel = new DiscountSwapAssetAnalytic();
                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();
            ISwapAssetParameters analyticModelParameters = new IRSwapAssetParameters();

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

            //1. instantiate curve
            if (marketEnvironment.GetType() == typeof(SimpleMarketEnvironment))
            {
                curve             = (IRateCurve)((ISimpleMarketEnvironment)marketEnvironment).GetPricingStructure();
                CurveName         = curve.GetPricingStructureId().UniqueIdentifier;
                ForecastCurveName = CurveName;
            }
            if (marketEnvironment.GetType() == typeof(SimpleRateMarketEnvironment))
            {
                curve             = ((ISimpleRateMarketEnvironment)marketEnvironment).GetRateCurve();
                CurveName         = curve.GetPricingStructureId().UniqueIdentifier;
                ForecastCurveName = CurveName;
            }
            if (marketEnvironment.GetType() == typeof(SwapLegEnvironment))
            {
                curve             = ((ISwapLegEnvironment)marketEnvironment).GetDiscountRateCurve();
                CurveName         = curve.GetPricingStructureId().UniqueIdentifier;
                forecastCurve     = ((ISwapLegEnvironment)marketEnvironment).GetForecastRateCurve();
                ForecastCurveName = forecastCurve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(MarketEnvironment))
            {
                curve = (IRateCurve)modelData.MarketEnvironment.GetPricingStructure(CurveName);
                if (ForecastCurveName != null)
                {
                    forecastCurve = (IRateCurve)modelData.MarketEnvironment.GetPricingStructure(ForecastCurveName);
                }
            }
            if (forecastCurve == null)
            {
                forecastCurve = curve;
            }
            //2. Set the rate
            analyticModelParameters.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;
                //1. Get any rates that have reset.
                if (ForwardRates != null)
                {
                    analyticModelParameters.FloatingLegForwardRates = ForwardRates;
                }
                //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. Get the respective year fractions
                analyticModelParameters.FloatingLegYearFractions = FloatingLegYearFractions;
                //6. Get the Weightings
                analyticModelParameters.FloatingLegWeightings = FloatingLegWeightings;
                //7. Get the floating discount factors
                analyticModelParameters.FloatingLegDiscountFactors =
                    GetDiscountFactors(curve, FloatingLegAdjustedPeriodDates.ToArray(), modelData.ValuationDate);
                //8. Get the forecast curve discount factors.
                analyticModelParameters.FloatingLegForecastDiscountFactors =
                    GetDiscountFactors(forecastCurve, FloatingLegAdjustedPeriodDates.ToArray(), modelData.ValuationDate);
                //9. Get the Spread
                analyticModelParameters.FloatingLegSpread = FloatingLegSpread?.value ?? 0.0m;
                //10. Set the anaytic input parameters and Calculate the respective metrics
                AnalyticResults =
                    AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters,
                                                                                   metricsToEvaluate);
            }
            return(GetValue(AnalyticResults));
        }
示例#12
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 SwapAssetAnalytic();
            //DependencyCreator.Resolve<IModelAnalytic<ISwapAssetParameters, RateMetrics>>("InflationSwapAsset");
            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();
            ISwapAssetParameters analyticModelParameters = new IRSwapAssetParameters();

            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
            analyticModelParameters.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 = GetYearFractions();
                //5. Set the anaytic input parameters and Calculate the respective metrics
                AnalyticResults =
                    AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters,
                                                                                   metricsToEvaluate);
            }
            else
            {
                //2. Get the discount factors
                analyticModelParameters.DiscountFactors =
                    GetDiscountFactors(curve, AdjustedPeriodDates.ToArray(), modelData.ValuationDate);
                //3. Get the respective year fractions
                analyticModelParameters.YearFractions = GetYearFractions();
                //4. Get the Weightings
                analyticModelParameters.Weightings =
                    CreateWeightings(CDefaultWeightingValue, analyticModelParameters.DiscountFactors.Length);
                //5. Set the anaytic input parameters and Calculate the respective metrics
                AnalyticResults =
                    AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters,
                                                                                   metricsToEvaluate);
            }
            return(GetValue(AnalyticResults));
        }
        /// <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 CommodityFuturesAssetAnalytic();
            //DependencyCreator.Resolve<IModelAnalytic<ICommodityFuturesAssetParameters, CommodityMetrics>>(_modelIdentifier);
            var metrics = MetricsHelper.GetMetricsToEvaluate(Metrics, AnalyticsModel.Metrics);
            // Determine if DFAM has been requested - if so that is all we evaluate - every other metric is ignored
            var bEvalIndexAtMaturity = false;

            if (metrics.Contains(CommodityMetrics.IndexAtMaturity))
            {
                bEvalIndexAtMaturity = true;
                //  remove all except DiscountFactorAtMaturity metric
                //
                metrics.RemoveAll(metricItem => metricItem != CommodityMetrics.IndexAtMaturity);
            }
            var metricsToEvaluate = metrics.ToArray();
            ICommodityFuturesAssetParameters analyticModelParameters = new CommodityFuturesAssetParameters
            {
                UnitAmount   = Amount,
                TimeToExpiry = TimeToExpiry
            };
            var marketEnvironment = modelData.MarketEnvironment;
            //1. instantiate curve
            ICommodityCurve commodityCurve = null;

            //1. instantiate curve
            if (marketEnvironment.GetType() == typeof(SimpleMarketEnvironment))
            {
                commodityCurve = (ICommodityCurve)((ISimpleMarketEnvironment)marketEnvironment).GetPricingStructure();
                CurveName      = commodityCurve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(SimpleCommodityMarketEnvironment))
            {
                commodityCurve = ((ISimpleCommodityMarketEnvironment)marketEnvironment).GetCommodityCurve();
                CurveName      = commodityCurve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(SwapLegEnvironment))
            {
                commodityCurve = ((ISwapLegEnvironment)marketEnvironment).GetCommodityCurve();
                CurveName      = commodityCurve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(MarketEnvironment))
            {
                commodityCurve = (ICommodityCurve)modelData.MarketEnvironment.GetPricingStructure(CurveName);
            }
            //4. Get the Index
            analyticModelParameters.Index = CommodityValue.value;
            if (bEvalIndexAtMaturity)
            {
                //5. Set the analytic input parameters and Calculate the respective metrics
                AnalyticResults =
                    AnalyticsModel.Calculate <ICommodityAssetResults, CommodityAssetResults>(analyticModelParameters,
                                                                                             metricsToEvaluate);
                ForwardIndex = IndexAtMaturity;
            }
            else
            {
                //4. Get the end discount factor
                ForwardIndex = GetCommodityForward(commodityCurve, GetRiskMaturityDate(), modelData.ValuationDate);
                analyticModelParameters.Index = IndexAtMaturity;
                //5. Get the TimeToExpiry
                analyticModelParameters.TimeToExpiry = GetTimeToExpiry();
                //6. Get the position
                analyticModelParameters.Position = Position;
                //7. Set the analytic input parameters and Calculate the respective metrics
                AnalyticResults =
                    AnalyticsModel.Calculate <ICommodityAssetResults, CommodityAssetResults>(analyticModelParameters,
                                                                                             metricsToEvaluate);
            }
            return(GetValue(AnalyticResults));
        }