/// <summary> /// Calculates the specified metric for the fast bootstrapper. /// </summary> /// <param name="interpolatedSpace">The intepolated Space.</param> /// <param name="discountedSpace">The OIS Space.</param> /// <returns></returns> public Decimal CalculateImpliedQuote(IInterpolatedSpace interpolatedSpace, IInterpolatedSpace discountedSpace) { switch (ModelIdentifier) { case "SwapAsset": AnalyticsModel = new SwapAssetAnalytic(); break; case "DiscountSwapAsset": AnalyticsModel = new DiscountSwapAssetAnalytic(); break; } //1. Set the basic parameters. ISwapAssetParameters analyticModelParameters = new IRSwapAssetParameters { NotionalAmount = Notional, //2. Get the discount factors DiscountFactors = GetDiscountFactors(discountedSpace, AdjustedPeriodDates.ToArray(), BaseDate), //3. Get the respective year fractions YearFractions = YearFractions, Rate = MarketQuoteHelper.NormalisePriceUnits(FixedRate, "DecimalRate").value }; //2. Get any rates that have reset. if (ForwardRates != null) { analyticModelParameters.FloatingLegForwardRates = ForwardRates; } //4. Get the Weightings analyticModelParameters.Weightings = CreateWeightings(CDefaultWeightingValue, analyticModelParameters.DiscountFactors.Length - 1); analyticModelParameters.FloatingLegDiscountFactors = GetDiscountFactors(discountedSpace, FloatingLegAdjustedPeriodDates.ToArray(), BaseDate); //6. Get the respective fixed leg year fractions analyticModelParameters.FloatingLegYearFractions = FloatingLegYearFractions; //7. Get the Fixed Leg Weightings analyticModelParameters.FloatingLegWeightings = FloatingLegWeightings; //8. Get the forecast curve discount factors. analyticModelParameters.FloatingLegForecastDiscountFactors = GetDiscountFactors(interpolatedSpace, FloatingLegAdjustedPeriodDates.ToArray(), BaseDate); AnalyticResults = new RateAssetResults(); //4. Set the analytic input parameters and Calculate the respective metrics // if (AnalyticsModel != null) { AnalyticResults = AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters, new[] { RateMetrics.ImpliedQuote }); } return(AnalyticResults.ImpliedQuote); }
/// <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)); }