Esempio n. 1
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)
        {
            ISimpleOptionAssetParameters analyticModelParameters = new SimpleRateOptionAssetParameters();

            //{
            //    YearFraction = YearFraction,
            //    TimeToExpiry = TimeToExpiry,
            //    StartDiscountFactor =
            //        GetDiscountFactor(interpolatedSpace,
            //            AdjustedStartDate, BaseDate),
            //    EndDiscountFactor =
            //        GetDiscountFactor(interpolatedSpace,
            //            GetRiskMaturityDate(), BaseDate),
            //    Volatility = Volatility
            //};
            //3. Get the Rate
            //
            //if (Volatility != null)
            //{
            //    analyticModelParameters.Rate = MarketQuoteHelper.NormalisePriceUnits(FixedRate, "DecimalRate").value;
            //}
            AnalyticResults = new SimpleRateOptionAssetResults();
            //4. Set the anaytic input parameters and Calculate the respective metrics
            //
            AnalyticResults = AnalyticsModel.Calculate <ISimpleRateOptionAssetResults, SimpleRateOptionAssetResults>(analyticModelParameters, new[] { RateOptionMetrics.ImpliedQuote });
            return(AnalyticResults.ImpliedQuote);
        }
Esempio n. 2
0
        /// <summary>
        /// Calculates the specified model data.
        /// </summary>
        /// <param name="modelData">The model data.</param>
        /// <returns></returns>
        public override BasicAssetValuation Calculate(IAssetControllerData modelData)
        {
            ModelData = modelData;
            if (AnalyticsModel == null)
            {
                //AnalyticsModel =
                //    DependencyCreator.Resolve<IModelAnalytic<ISimpleOptionAssetParameters, RateOptionMetrics>>(
                //        ModelIdentifier);
                AnalyticsModel = new SimpleRateOptionAssetAnalytic();
            }
            var metrics = MetricsHelper.GetMetricsToEvaluate(Metrics, AnalyticsModel.Metrics);
            // Determine if DFAM has been requested - if so that all we evaluate - every other metric is ignored
            //
            var bEvalVolatilityAtRiskMaturity = false;

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

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

            if (IsVolatilityQuote)
            {
                analyticModelParameters.IsVolatilityQuote = true;
                analyticModelParameters.Volatility        = Volatility;
            }
            if (bEvalVolatilityAtRiskMaturity && IsVolatilityQuote)
            {
                analyticModelParameters.IsVolatilityQuote = true;
                AnalyticResults = AnalyticsModel.Calculate <ISimpleRateOptionAssetResults, SimpleRateOptionAssetResults>(analyticModelParameters, metricsToEvaluate);
                return(GetValue(AnalyticResults));
            }
            var        marketEnvironment = modelData.MarketEnvironment;
            IRateCurve curve             = null;

            //1. instantiate curve
            if (marketEnvironment.GetType() == typeof(SimpleMarketEnvironment))
            {
                curve     = (IRateCurve)((ISimpleMarketEnvironment)marketEnvironment).GetPricingStructure();
                CurveName = curve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(SimpleRateMarketEnvironment))
            {
                curve     = ((ISimpleRateMarketEnvironment)marketEnvironment).GetRateCurve();
                CurveName = curve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(SwapLegEnvironment))
            {
                curve     = ((ISwapLegEnvironment)marketEnvironment).GetDiscountRateCurve();
                CurveName = curve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(MarketEnvironment))
            {
                curve = (IRateCurve)modelData.MarketEnvironment.GetPricingStructure(CurveName);
            }
            analyticModelParameters.IsPut = !IsCap;
            //A cap is a call option on the rate. This rate should reflect the underlying Xibor
            analyticModelParameters.Rate = GetRate(curve, modelData.ValuationDate, AdjustedEffectiveDate,
                                                   MaturityDate, YearFraction);
            analyticModelParameters.Premium = Premium;
            //2. get start df = curve.getvalue(this._adjustedStartDate);
            //
            analyticModelParameters.StartDiscountFactor = GetDiscountFactor(curve, AdjustedEffectiveDate,
                                                                            modelData.ValuationDate);
            analyticModelParameters.PremiumPaymentDiscountFactor = GetDiscountFactor(curve, PaymentDate,
                                                                                     modelData.ValuationDate);
            analyticModelParameters.NotionalAmount = Notional;
            analyticModelParameters.IsDiscounted   = IsDiscounted;
            //3. Get the end discount factor
            //
            analyticModelParameters.EndDiscountFactor = GetDiscountFactor(curve, MaturityDate,
                                                                          modelData.ValuationDate);
            analyticModelParameters.Strike       = Strike;
            analyticModelParameters.TimeToExpiry = TimeToExpiry;
            if (bEvalVolatilityAtRiskMaturity && !IsVolatilityQuote)
            {
                AnalyticResults =
                    AnalyticsModel.Calculate <ISimpleRateOptionAssetResults, SimpleRateOptionAssetResults>(
                        analyticModelParameters, metricsToEvaluate);
                return(GetValue(AnalyticResults));
            }
            if (!IsVolatilityQuote)
            {
                IVolatilitySurface volCurve;
                if (marketEnvironment.GetType() == typeof(SwapLegEnvironment))
                {
                    var me = (ISwapLegEnvironment)marketEnvironment;
                    volCurve     = me.GetVolatilitySurface();
                    VolCurveName = volCurve.GetPricingStructureId().UniqueIdentifier;
                }
                else
                {
                    volCurve = (IVolatilitySurface)modelData.MarketEnvironment.GetPricingStructure(VolCurveName);
                }
                analyticModelParameters.Volatility =
                    Convert.ToDecimal(volCurve.GetValue((double)TimeToExpiry, (double)Strike));
            }
            //4. Set the analytic input parameters and Calculate the respective metrics
            //
            AnalyticResults =
                AnalyticsModel.Calculate <ISimpleRateOptionAssetResults, SimpleRateOptionAssetResults>(analyticModelParameters,
                                                                                                       metricsToEvaluate);
            return(GetValue(AnalyticResults));
        }