Пример #1
0
        /// <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);
        }
Пример #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="forecastcurve"></param>
 /// <param name="parameters"></param>
 /// <returns></returns>
 protected IRateOptionAssetResults ForecastRiskCalculationHelper(IRateCurve forecastcurve, IRateOptionAssetParameters parameters)
 {
     parameters.ForecastDiscountFactors = GetDiscountFactors(forecastcurve,
                                                             AdjustedPeriodDates.ToArray(),
                                                             BaseDate);
     //Set the analytic input parameters and Calculate the respective metrics
     //
     return(AnalyticsModel.Calculate <IRateOptionAssetResults, RateOptionAssetResults>(parameters, new[] { RateOptionMetrics.NPV }));
 }
Пример #3
0
        /// <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());
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ratecurve"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        protected virtual IRateAssetResults RiskCalculationHelper(IRateCurve ratecurve, ISwapAssetParameters parameters)
        {
            parameters.DiscountFactors =
                GetDiscountFactors(ratecurve,
                                   AdjustedPeriodDates.ToArray(),
                                   BaseDate);

            //Set the anaytic input parameters and Calculate the respective metrics
            //
            return(AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(parameters, new[] { RateMetrics.NPV }));
        }
Пример #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="discountCurve"></param>
 /// <param name="parameters"></param>
 /// <returns></returns>
 protected override IRateAssetResults RiskCalculationHelper(IRateCurve discountCurve, ISwapAssetParameters parameters)
 {
     parameters.FloatingLegDiscountFactors =
         GetDiscountFactors(discountCurve,
                            AdjustedPeriodDates.ToArray(),
                            BaseDate);
     parameters.DiscountFactors =
         GetDiscountFactors(discountCurve,
                            FloatingLegAdjustedPeriodDates.ToArray(),
                            BaseDate);
     //Set the analytic input parameters and Calculate the respective metrics
     //
     return(AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(parameters, new[] { RateMetrics.NPVChange }));
 }
Пример #6
0
        /// <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>
        ///
        /// </summary>
        /// <returns>Calculates the premium using previously set curves</returns>
        public Decimal?CalculatePremium()
        {
            //Check the curves. If they are null use the market quote.
            if (DiscountCurve == null || ForecastCurve == null)
            {
                return(null);
            }
            //1. Copy the vols.
            var volatilities = CreateList((double)Volatility, TimesToExpiry.Count);
            //Currently onlt non-discounted caps are avialable.
            var notionals = CreateList(InitialNotional, TimesToExpiry.Count);

            //2.The strikes
            if (Strike != null)
            {
                var strikes = CreateList((decimal)Strike, TimesToExpiry.Count);
                //3.The premium of the flat volatility must be calculated.
                var analyticsModel          = new RateOptionAssetAnalytic();
                var analyticModelParameters = new RateOptionAssetParameters
                {
                    PaymentDiscountFactors  = GetDiscountFactors(DiscountCurve, AdjustedPeriodDates.ToArray(), BaseDate),
                    ForecastDiscountFactors =
                        GetDiscountFactors(ForecastCurve, AdjustedPeriodDates.ToArray(), BaseDate),
                    Volatilities  = volatilities,
                    YearFractions = GetYearFractions(),
                    Strikes       = strikes,
                    TimesToExpiry = TimesToExpiry,
                    IsDiscounted  = false,
                    IsPut         = !IsCap,
                    Notionals     = notionals
                };
                //4. Solve for the forward volatility that has the same premium.
                var metrics         = new[] { RateOptionMetrics.NPV };
                var analyticResults =
                    analyticsModel.Calculate <IRateOptionAssetResults, RateOptionAssetResults>(analyticModelParameters,
                                                                                               metrics);
                if (IncludeFirstPeriod)
                {
                    Premium = (decimal)SumDoubleList(analyticResults.NPV, 0);
                }
                else
                {
                    Premium = (decimal)SumDoubleList(analyticResults.NPV, 1);
                }
                return(Premium);
            }
            return(null);
        }
Пример #8
0
        /// <summary>
        /// Calculates the specified metric for the fast bootstrapper.
        /// </summary>
        /// <param name="interpolatedSpace">The intepolated Space.</param>
        /// <returns></returns>
        public override decimal CalculateImpliedQuote(IInterpolatedSpace interpolatedSpace)
        {
            if (AnalyticsModel == null)
            {
                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 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));
        }
Пример #10
0
        /// <summary>
        /// Calculates the specified model data.
        /// </summary>
        /// <param name="valuationDate">The valuation date.</param>
        /// <param name="discountCurve">The discount curve.</param>
        /// <param name="forecastCurve">The forward curve.</param>
        /// <param name="volCurve">The volatility surface.
        /// and discount curves when called with ForecastRateCurve.</param>
        /// <param name="curveToPerturb">The curve to perturb: the discount curve, the forecast curve or both.</param>
        /// <returns></returns>
        public IDictionary <string, double> CalculateRatePDH(DateTime valuationDate,
                                                             IRateCurve discountCurve, IRateCurve forecastCurve, IVolatilitySurface volCurve, CurvePerturbation curveToPerturb)
        {
            var result = new Dictionary <string, double>();

            AnalyticResults = new RateOptionAssetResults();
            switch (ModelIdentifier)
            {
            case "CapAsset":
                AnalyticsModel = new RateOptionAssetAnalytic();
                break;

            case "DiscountCapAsset":
                AnalyticsModel = new RateOptionAssetAnalytic();
                break;
            }
            ForecastCurveName   = forecastCurve.GetPricingStructureId().UniqueIdentifier;
            DiscountCurveName   = discountCurve.GetPricingStructureId().UniqueIdentifier;
            VolatilityCurveName = volCurve.GetPricingStructureId().UniqueIdentifier;
            var analyticModelParameters = new RateOptionAssetParameters {
                IsPut = !IsCap, Notionals = Notionals
            };

            //and the rest rates
            if (ResetRates != null)
            {
                analyticModelParameters.ForwardRates = ResetRates;
            }
            //2. Get the discount factors
            analyticModelParameters.ForecastDiscountFactors =
                GetDiscountFactors(forecastCurve, AdjustedPeriodDates.ToArray(), valuationDate);
            analyticModelParameters.PaymentDiscountFactors =
                GetDiscountFactors(discountCurve, AdjustedPeriodDates.ToArray(), valuationDate);
            //3. Get the respective year fractions
            analyticModelParameters.YearFractions = YearFractions;
            //4. set the expiry times.
            TimesToExpiry =
                GetTimesToExpiry(ExpiryDates, valuationDate);
            analyticModelParameters.TimesToExpiry = TimesToExpiry;
            //5. Get the vols
            analyticModelParameters.Volatilities =
                GetVolatilties(volCurve, TimesToExpiry, Strikes);
            //8. Get the Strikes
            analyticModelParameters.Strikes = Strikes;
            //9. Set the analytic input parameters and Calculate the respective metrics
            var analyticResults =
                AnalyticsModel.Calculate <IRateOptionAssetResults, RateOptionAssetResults>(analyticModelParameters,
                                                                                           new[] { RateOptionMetrics.NPV });

            AnalyticResults = analyticResults;
            var baseNPV = SumDoubleList(AnalyticResults.NPV, 0);

            //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, baseNPV - SumDoubleList(analyticResults.NPV, 0));
                }
            }
            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, baseNPV - SumDoubleList(analyticResults.NPV, 0));
                }
            }
            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, baseNPV - SumDoubleList(analyticResults.NPV, 0));
                }
                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, baseNPV - SumDoubleList(analyticResults.NPV, 0));
                }
            }
            return(result);
        }
Пример #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 "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));
        }
Пример #12
0
        /// <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);
        }
Пример #13
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));
        }
Пример #14
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));
        }