/// <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> /// /// </summary> /// <returns>The swap par rate</returns> public decimal CalculateImpliedParRate(DateTime baseDate) { //Check the curves. If they are null use the market quote. if (ForecastCurve == null) { return(0.0m); } var analyticsModel = new SimpleSwapAssetAnalytic(); var analyticModelParameters = new IRSwapAssetParameters { NotionalAmount = InitialNotional, DiscountFactors = GetDiscountFactors(ForecastCurve, AdjustedPeriodDates, baseDate), YearFractions = Convert(GetYearFractions()), Weightings = CreateList(AdjustedPeriodDates.Count - 1, 1.0m) }; //2. Get the discount factors //3. Get the respective year fractions //4. Get the Weightings //3. Solve for the forward volatility that has the same premium. var metrics = new[] { RateMetrics.ImpliedQuote }; var analyticResults = analyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters, metrics); return(analyticResults.ImpliedQuote); }
/// <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> /// 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 metric for the fast bootstrapper. /// </summary> /// <param name="interpolatedSpace">The interpolated Space.</param> /// <returns></returns> public override decimal CalculateDiscountFactorAtMaturity(IInterpolatedSpace interpolatedSpace) { if (AnalyticsModel == null) { switch (ModelIdentifier) { case "SwapAsset": case "ClearedSwapAsset": AnalyticsModel = new SimpleSwapAssetAnalytic(); // break; } } ISwapAssetParameters analyticModelParameters = new IRSwapAssetParameters { YearFractions = YearFractions, StartDiscountFactor = GetDiscountFactor(interpolatedSpace, AdjustedStartDate, BaseDate), Rate = CalculateImpliedQuote(interpolatedSpace) + MarketQuoteHelper .NormaliseGeneralPriceUnits(QuotationType, Spread, "DecimalRate").value }; //3. Set the implied Rate with a spread // AnalyticResults = new RateAssetResults(); //4. Set the anaytic input parameters and Calculate the respective metrics // if (AnalyticsModel != null) { AnalyticResults = AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters, new[] { RateMetrics.DiscountFactorAtMaturity }); } return(AnalyticResults.DiscountFactorAtMaturity); }
/// <summary> /// Calculates the specified model data. /// </summary> /// <param name="modelData">The model data.</param> /// <returns></returns> public override BasicAssetValuation Calculate(IAssetControllerData modelData) { ModelData = modelData; switch (ModelIdentifier) { case "SimpleSwapAsset": AnalyticsModel = new SimpleSwapAssetAnalytic(); break; case "SimpleDiscountSwapAsset": AnalyticsModel = new SimpleDiscountSwapAssetAnalytic(); break; } var metrics = MetricsHelper.GetMetricsToEvaluate(Metrics, AnalyticsModel.Metrics); // Determine if DFAM has been requested - if so thats all we evaluate - every other metric is ignored var bEvalDiscountFactorAtMaturity = false; if (metrics.Contains(RateMetrics.DiscountFactorAtMaturity)) { bEvalDiscountFactorAtMaturity = true; metrics.RemoveAll( metricItem => metricItem != RateMetrics.DiscountFactorAtMaturity); } var metricsToEvaluate = metrics.ToArray(); AnalyticResults = new RateAssetResults(); var marketEnvironment = modelData.MarketEnvironment; IRateCurve curve = null; //1. instantiate curve if (marketEnvironment.GetType() == typeof(SimpleMarketEnvironment)) { curve = (IRateCurve)((ISimpleMarketEnvironment)marketEnvironment).GetPricingStructure(); CurveName = curve.GetPricingStructureId().UniqueIdentifier; } if (marketEnvironment.GetType() == typeof(SimpleRateMarketEnvironment)) { curve = ((ISimpleRateMarketEnvironment)marketEnvironment).GetRateCurve(); CurveName = curve.GetPricingStructureId().UniqueIdentifier; } if (marketEnvironment.GetType() == typeof(SwapLegEnvironment)) { curve = ((ISwapLegEnvironment)marketEnvironment).GetDiscountRateCurve(); CurveName = curve.GetPricingStructureId().UniqueIdentifier; } if (marketEnvironment.GetType() == typeof(MarketEnvironment)) { curve = (IRateCurve)modelData.MarketEnvironment.GetPricingStructure(CurveName); } //2. Set the rate var analyticModelParameters = new IRSwapAssetParameters { Rate = MarketQuoteHelper.NormalisePriceUnits(FixedRate, "DecimalRate").value }; if (bEvalDiscountFactorAtMaturity) { //3. Set the start diccount factor analyticModelParameters.StartDiscountFactor = GetDiscountFactor(curve, AdjustedStartDate, modelData.ValuationDate); //4. Get the respective year fractions analyticModelParameters.YearFractions = YearFractions; //5. Set the anaytic input parameters and Calculate the respective metrics AnalyticResults = AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters, metricsToEvaluate); } else { analyticModelParameters.NotionalAmount = Notional; //2. Get the discount factors analyticModelParameters.DiscountFactors = GetDiscountFactors(curve, AdjustedPeriodDates.ToArray(), modelData.ValuationDate); //3. Get the respective year fractions analyticModelParameters.YearFractions = YearFractions; //4. Get the Weightings analyticModelParameters.Weightings = Weightings; //5. Set the anaytic input parameters and Calculate the respective metrics AnalyticResults = AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters, metricsToEvaluate); } return(GetValue(AnalyticResults)); }