/// <summary> /// Calculates the specified model data. /// </summary> /// <param name="interpolatedSpace">The interpolatedSpace.</param> /// <returns></returns> public override decimal CalculateImpliedQuote(IInterpolatedSpace interpolatedSpace) { AnalyticsModel = new SimpleSwapAssetAnalytic(); //DependencyCreator.Resolve<IModelAnalytic<ISwapAssetParameters, RateMetrics>>("InflationSwapAsset"); ISwapAssetParameters analyticModelParameters = new IRSwapAssetParameters(); AnalyticResults = new RateAssetResults(); //1. instantiate curve //var curve = (IRateCurve)modelData.MarketEnvironment.GetPricingStructure(_discountCurveName); //2. Set the rate analyticModelParameters.Rate = MarketQuoteHelper.NormalisePriceUnits(FixedRate, "DecimalRate").value; //2. Get the discount factors analyticModelParameters.DiscountFactors = GetDiscountFactors(interpolatedSpace, AdjustedPeriodDates.ToArray(), BaseDate); //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, new[] { RateMetrics.ImpliedQuote }); return(AnalyticResults.ImpliedQuote); }
/// <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) { AnalyticsModel = new ZeroCouponRateAssetAnalytic(); // DependencyCreator.Resolve<IModelAnalytic<ISimpleAssetParameters, RateMetrics>>(_modelIdentifier); } IZeroRateAssetParameters analyticModelParameters = new ZeroRateAssetParameters { YearFraction = YearFraction, PeriodAsTimesPerYear = CompoundingHelper. PeriodFractionFromCompoundingFrequency( BaseDate, CompoundingFrequency, DayCountFraction), StartDiscountFactor = GetDiscountFactor(interpolatedSpace, BaseDate, BaseDate) }; //2. get start df = curve.getvalue(this._adjustedStartDate); // //3. Get the Rate // if (FixedRate != null) { analyticModelParameters.Rate = MarketQuoteHelper.NormalisePriceUnits(FixedRate, "DecimalRate").value; } CalculationResults = new RateAssetResults(); //4. Set the anaytic input parameters and Calculate the respective metrics // CalculationResults = AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters, new[] { RateMetrics.DiscountFactorAtMaturity }); return(CalculationResults.DiscountFactorAtMaturity); }
/// <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 InflationAssetAnalytic(); // DependencyCreator.Resolve<IModelAnalytic<ISimpleAssetParameters, RateMetrics>>(_modelIdentifier); } ISimpleDualAssetParameters analyticModelParameters = new DualRateAssetParameters { YearFraction = YearFraction, StartDiscountFactor = GetDiscountFactor(interpolatedSpace, AdjustedStartDate, BaseDate), EndDiscountFactor = GetDiscountFactor(interpolatedSpace, GetRiskMaturityDate(), 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 // AnalyticResults = AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters, new[] { RateMetrics.ImpliedQuote }); return(AnalyticResults.ImpliedQuote); }
/// <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 (UseSimpleModel) { return(IndexAtMaturity); } if (AnalyticsModel == null) { AnalyticsModel = new CommodityAverageAssetAnalytic(); } ICommodityAverageAssetParameters analyticModelParameters = new CommodityAverageAssetParameters { StartIndex = GetIndexAtMaturity(interpolatedSpace, AdjustedStartDate, BaseDate), }; //3. Get the Index // if (MarketQuote != null) { analyticModelParameters.AverageIndex = MarketQuoteHelper.NormalisePriceUnits(MarketQuote, "DecimalRate").value; } //4. Set the anaytic input parameters and Calculate the respective metrics // AnalyticResults = AnalyticsModel.Calculate <ICommodityAssetResults, CommodityAssetResults>(analyticModelParameters, new[] { CommodityMetrics.IndexAtMaturity }); return(CalculationResults.IndexAtMaturity); }
/// <summary> /// An inital test to see if the guess was good.. /// </summary> /// <returns></returns> public Boolean InitialValue() { var curve = new SimpleFxCurve(_baseDate, _interpolationMethod, _extrapolation, _dates, _dfs); var impliedQuote = _priceableAsset.CalculateImpliedQuote(curve); var marketQuote = MarketQuoteHelper.NormalisePriceUnits(_priceableAsset.MarketQuote, "DecimalRate").value; var quoteError = (double)(marketQuote - impliedQuote); return(Math.Abs(quoteError) < _cTolerance); }
/// <summary> /// An inital test to see if the guess was good.. /// </summary> /// <returns></returns> public Boolean InitialValue() { var curve = new SimpleCommodityCurve(BaseDate, InterpolationMethod, Extrapolation, Dfs); var impliedQuote = PriceableAsset.CalculateImpliedQuote(curve); var marketQuote = MarketQuoteHelper.NormalisePriceUnits(PriceableAsset.MarketQuote, "DecimalRate").value; var quoteError = (double)(marketQuote - impliedQuote); return(Math.Abs(quoteError) < Tolerance); }
/// <summary> /// Values the specified discount factor. /// </summary> /// <param name="discountFactor">The discount factor.</param> /// <returns>Quote error - difference between market quote and implied (from the bootstrapped term structure) quote</returns> public double Value(double discountFactor) { Dfs[Dfs.Keys.Last()] = discountFactor; var curve = new SimpleCommodityCurve(BaseDate, InterpolationMethod, Extrapolation, Dfs); var impliedQuote = PriceableAsset.CalculateImpliedQuote(curve); var marketQuote = MarketQuoteHelper.NormalisePriceUnits(PriceableAsset.MarketQuote, "DecimalRate").value; var quoteError = (double)(marketQuote - impliedQuote); return(quoteError); }
/// <summary> /// Values the specified discount factor. /// </summary> /// <param name="discountFactor">The discount factor.</param> /// <returns>Quote error - difference between market quote and implied (from the bootstrapped term structure) quote</returns> public double Value(double discountFactor) { _dfs[_dfs.Count - 1] = discountFactor; var curve = new SimpleFxCurve(_baseDate, _interpolationMethod, _extrapolation, _dates, _dfs); var impliedQuote = _priceableAsset.CalculateImpliedQuote(curve); var marketQuote = MarketQuoteHelper.NormalisePriceUnits(_priceableAsset.MarketQuote, "DecimalRate").value; var quoteError = (double)(marketQuote - impliedQuote); return(quoteError); }
/// <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()); }
/// <summary> /// Initializes a new instance of the <see cref="RateAssetQuote"/> class. /// </summary> /// <param name="priceableAsset">The priceable asset.</param> /// <param name="baseDate">The base date.</param> /// <param name="interpolation">The interpolation.</param> /// <param name="extrapolation">if set to <c>true</c> [extrapolation].</param> /// <param name="dfs">The discount factors.</param> /// <param name="tolerance">The tolerance.</param> public RateAssetQuote(IPriceableRateAssetController priceableAsset, DateTime baseDate, InterpolationMethod interpolation, bool extrapolation, IDictionary <DateTime, double> dfs, double tolerance) { PriceableAsset = priceableAsset; BaseDate = baseDate; Dfs = dfs; InterpolationMethod = interpolation; Extrapolation = extrapolation; Tolerance = tolerance; Quote = MarketQuoteHelper.NormalisePriceUnits(PriceableAsset.MarketQuote, "DecimalRate").value; }
/// <summary> /// Initializes a new instance of the <see cref="RateAssetQuote"/> class. /// </summary> /// <param name="priceableAsset">The priceable asset.</param> /// <param name="referenceCurve">The reference curve.</param> /// <param name="baseDate">The base date.</param> /// <param name="extrapolation">if set to <c>true</c> [extrapolation].</param> /// <param name="dfs">The DFS.</param> /// <param name="tolerance">The tolerance.</param> public RateSpreadAssetQuote(IPriceableRateSpreadAssetController priceableAsset, IRateCurve referenceCurve, DateTime baseDate, bool extrapolation, IDictionary <DateTime, double> dfs, double tolerance) { PriceableAsset = priceableAsset; BaseDate = baseDate; Dfs = dfs; Extrapolation = extrapolation; Tolerance = tolerance; BaseCurve = referenceCurve; SpreadQuote = MarketQuoteHelper.NormalisePriceUnits(PriceableAsset.MarketQuote, "DecimalRate").value; BaseQuote = PriceableAsset.CalculateImpliedQuote(BaseCurve); }
/// <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 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); }
/// <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); }
/// <summary> /// Calculates the specified model data. /// </summary> /// <param name="interpolatedSpace">The interpolatedSpace.</param> /// <returns></returns> public override decimal CalculateDiscountFactorAtMaturity(IInterpolatedSpace interpolatedSpace) { AnalyticsModel = new SwapAssetAnalytic(); //DependencyCreator.Resolve<IModelAnalytic<ISwapAssetParameters, RateMetrics>>("InflationSwapAsset"); ISwapAssetParameters analyticModelParameters = new IRSwapAssetParameters(); AnalyticResults = new RateAssetResults(); //1. instantiate curve //var curve = (IRateCurve)modelData.MarketEnvironment.GetPricingStructure(_discountCurveName); //2. Set the rate analyticModelParameters.Rate = MarketQuoteHelper.NormalisePriceUnits(FixedRate, "DecimalRate").value; //3. Set the start diccount factor analyticModelParameters.StartDiscountFactor = GetDiscountFactor(interpolatedSpace, AdjustedStartDate, BaseDate); //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, new[] { RateMetrics.DiscountFactorAtMaturity }); return(AnalyticResults.DiscountFactorAtMaturity); }
/// <summary> /// Calculates the specified metric for the fast bootstrapper. /// </summary> /// <param name="discountCurve">The discount curve.</param> /// <param name="forecastCurve">The forecast curve</param> /// <param name="curveToPerturb">The curve to perturb: the discount curve, the forecast curve or both.</param> /// <returns></returns> public IDictionary <string, Decimal> CalculatePDH(CurveBase discountCurve, CurveBase forecastCurve, CurvePerturbation curveToPerturb) { if (AnalyticsModel == null) { switch (ModelIdentifier) { case "SwapAsset": AnalyticsModel = new SwapAssetAnalytic(); break; case "DiscountSwapAsset": AnalyticsModel = new DiscountSwapAssetAnalytic(); break; } } var result = new Dictionary <string, Decimal>(); if (discountCurve != null && forecastCurve != null) { ISwapAssetParameters analyticModelParameters = new IRSwapAssetParameters { NotionalAmount = Notional, //2. Get the discount factors DiscountFactors = GetDiscountFactors(discountCurve, AdjustedPeriodDates.ToArray(), BaseDate), //3. Get the respective year fractions YearFractions = YearFractions, Weightings = Weightings, Rate = MarketQuoteHelper.NormalisePriceUnits( FixedRate, "DecimalRate").value, FloatingLegDiscountFactors = GetDiscountFactors(discountCurve, FloatingLegAdjustedPeriodDates.ToArray(), BaseDate), FloatingLegForecastDiscountFactors = GetDiscountFactors(forecastCurve, FloatingLegAdjustedPeriodDates.ToArray(), BaseDate), FloatingLegYearFractions = FloatingLegYearFractions, FloatingLegWeightings = FloatingLegWeightings, FloatingLegSpread = MarketQuoteHelper.NormalisePriceUnits( FloatingLegSpread, "DecimalRate").value }; if (ForwardRates != null) { analyticModelParameters.FloatingLegForwardRates = ForwardRates; } //4. Set the analytic input parameters and Calculate the respective metrics // if (AnalyticsModel != null) { var analyticResults = AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters, new[] { RateMetrics.NPV }); AnalyticResults = analyticResults; analyticModelParameters.BaseNPV = analyticResults.NPV; //Now loop through the risk curves. if (curveToPerturb == CurvePerturbation.DiscountCurve) { var riskCurves = discountCurve.CreateCurveRiskSet(1); foreach (var curve in riskCurves) { var perturbedAsset = curve.GetPricingStructureId().Properties.GetValue <string>("PerturbedAsset"); analyticResults = RiskCalculationHelper((IRateCurve)curve, analyticModelParameters); result.Add("DiscountCurve:" + perturbedAsset, analyticResults.NPVChange); } } if (curveToPerturb == CurvePerturbation.ForecastCurve) { var riskCurves = forecastCurve.CreateCurveRiskSet(1); foreach (var curve in riskCurves) { var perturbedAsset = curve.GetPricingStructureId().Properties.GetValue <string>("PerturbedAsset"); analyticResults = ForecastRiskCalculationHelper((IRateCurve)curve, analyticModelParameters); result.Add("ForecastCurve:" + perturbedAsset, analyticResults.NPVChange); } } if (curveToPerturb == CurvePerturbation.Both) { var riskCurves1 = discountCurve.CreateCurveRiskSet(1); foreach (var curve in riskCurves1) { var perturbedAsset = curve.GetPricingStructureId().Properties.GetValue <string>("PerturbedAsset"); analyticResults = RiskCalculationHelper((IRateCurve)curve, analyticModelParameters); result.Add("DiscountCurve:" + perturbedAsset, analyticResults.NPVChange); } var riskCurves2 = forecastCurve.CreateCurveRiskSet(1); foreach (var curve in riskCurves2) { var perturbedAsset = curve.GetPricingStructureId().Properties.GetValue <string>("PerturbedAsset"); analyticResults = ForecastRiskCalculationHelper((IRateCurve)curve, analyticModelParameters); result.Add("ForecastCurve:" + perturbedAsset, analyticResults.NPVChange); } } } } return(result); }
/// <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)); }
/// <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 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; 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)); }