public override AssetValuation Calculate(IInstrumentControllerData modelData)
        {
            ModelData = modelData;
            AnalyticModelParameters = null;
            CalculationResults      = null;
            UpdateBucketingInterval(ModelData.ValuationDate, PeriodHelper.Parse(CDefaultBucketingInterval));
            // 1. First derive the analytics to be evaluated via the stream controller model
            // NOTE: These take precedence of the child model metrics
            if (AnalyticsModel == null)
            {
                AnalyticsModel = new BondStreamAnalytic();
            }
            var            streamControllerMetrics = ResolveModelMetrics(AnalyticsModel.Metrics);
            AssetValuation streamValuation;

            // 2. Now evaluate only the child specific metrics (if any)
            foreach (var coupon in Coupons)
            {
                coupon.PricingStructureEvolutionType = PricingStructureEvolutionType;
                coupon.BucketedDates = BucketedDates;
                coupon.Multiplier    = Multiplier;
            }
            var childControllers = new List <InstrumentControllerBase>(Coupons.ToArray());
            //Now the stream analytics can be completed.
            var childValuations           = EvaluateChildMetrics(childControllers, modelData, Metrics);
            var couponValuation           = AssetValuationHelper.AggregateMetrics(childValuations, new List <string>(Metrics), PaymentCurrencies);
            var childControllerValuations = new List <AssetValuation> {
                couponValuation
            };

            // Child metrics have now been calculated so we can now evaluate the stream model metrics
            if (streamControllerMetrics.Count > 0)
            {
                var reportingCurrency = ModelData.ReportingCurrency == null ? Currency : ModelData.ReportingCurrency.Value;
                var notionals         = GetCouponNotionals();
                var accrualFactors    = GetCouponAccrualFactors();
                var discountFactors   = GetPaymentDiscountFactors();
                var floatingNPV       = AggregateMetric(InstrumentMetrics.FloatingNPV, childControllerValuations);
                var accrualFactor     = AggregateMetric(InstrumentMetrics.AccrualFactor, childControllerValuations);
                //TODO need to  set the notional amount and the weighting. Also amortisation??
                IBondStreamParameters analyticModelParameters = new BondStreamParameters
                {
                    Multiplier        = Multiplier,
                    CouponNotionals   = notionals,
                    Currency          = Currency,
                    ReportingCurrency = reportingCurrency,
                    AccrualFactor     = accrualFactor,
                    FloatingNPV       = floatingNPV,
                    NPV = AggregateMetric(InstrumentMetrics.NPV, childControllerValuations),
                    CouponYearFractions    = accrualFactors,
                    PaymentDiscountFactors = discountFactors,
                    TargetNPV = floatingNPV
                };
                CalculationResults = AnalyticsModel.Calculate <IBondStreamInstrumentResults, BondStreamInstrumentResults>(analyticModelParameters, streamControllerMetrics.ToArray());
                // Now merge back into the overall stream valuation
                var streamControllerValuation = GetValue(CalculationResults, modelData.ValuationDate);
                streamValuation = AssetValuationHelper.UpdateValuation(streamControllerValuation,
                                                                       childControllerValuations, ConvertMetrics(streamControllerMetrics), new List <string>(Metrics), PaymentCurrencies);
                AnalyticModelParameters = analyticModelParameters;
            }
            else
            {
                streamValuation = AssetValuationHelper.AggregateMetrics(childControllerValuations, new List <string>(Metrics), PaymentCurrencies);
            }
            CalculationPerformedIndicator = true;
            streamValuation.id            = Id;
            return(streamValuation);
        }
        /// <summary>
        /// Calculates the specified model data.
        /// </summary>
        /// <param name="modelData">The model data.</param>
        /// <returns></returns>
        public override AssetValuation Calculate(IInstrumentControllerData modelData)
        {
            ModelData = modelData;
            AnalyticModelParameters = null;
            CalculationResults      = null;
            UpdateBucketingInterval(ModelData.ValuationDate, PeriodHelper.Parse(CDefaultBucketingInterval));
            // 1. First derive the analytics to be evaluated via the stream controller model
            // NOTE: These take precendence of the child model metrics
            if (AnalyticsModel == null)
            {
                AnalyticsModel = new SimpleIRSwaptionInstrumentAnalytic();
            }
            var swaptionControllerMetrics = ResolveModelMetrics(AnalyticsModel.Metrics);
            var quotes = ModelData.AssetValuation.quote.ToList();

            if (AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.BreakEvenRate.ToString()) == null)
            {
                var quote = QuotationHelper.Create(0.0m, InstrumentMetrics.BreakEvenRate.ToString(), "DecimalValue");
                quotes.Add(quote);
            }
            if (AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.NPV.ToString()) == null)
            {
                var quote = QuotationHelper.Create(0.0m, InstrumentMetrics.NPV.ToString(), "DecimalValue");
                quotes.Add(quote);
            }
            ModelData.AssetValuation.quote = quotes.ToArray();
            AssetValuation swaptionValuation;

            //Sets the evolution type for calculations.
            Swap.PricingStructureEvolutionType = PricingStructureEvolutionType;
            Swap.BucketedDates = BucketedDates;
            if (PremiumPayments != null)
            {
                foreach (var payment in PremiumPayments)
                {
                    payment.PricingStructureEvolutionType = PricingStructureEvolutionType;
                    payment.BucketedDates = BucketedDates;
                }
            }
            //The assetValuation list.
            var childValuations = new List <AssetValuation>();

            // 2. Now evaluate only the child specific metrics (if any)
            if (PremiumPayments != null)
            {
                var paymentControllers = new List <InstrumentControllerBase>(PremiumPayments);
                childValuations.AddRange(paymentControllers.Select(payment => payment.Calculate(modelData)));
            }
            var swapMetrics = Swap.Calculate(modelData);
            //We assume the fixed leg is always the first leg!
            var fixedLeg      = Swap.GetLegs()[0].Calculate(modelData);
            var breakEvenRate = AssetValuationHelper.GetQuotationByMeasureType(swapMetrics, InstrumentMetrics.BreakEvenRate.ToString()).value;
            var timeToIndex   = (Swap.EffectiveDate - ModelData.ValuationDate).Days / 365.0;
            //This is European only.
            var expiryTime = (ExerciseDates[0] - ModelData.ValuationDate).Days / 365.0;
            IVolatilitySurface indexVolSurface = null;

            if (modelData.MarketEnvironment is ISwapLegEnvironment streamMarket1)
            {
                indexVolSurface = streamMarket1.GetVolatilitySurface();
                indexVolSurface.PricingStructureEvolutionType = PricingStructureEvolutionType;
                VolatilitySurfaceName = indexVolSurface.GetPricingStructureId().UniqueIdentifier;
            }
            else
            {
                if (!string.IsNullOrEmpty(VolatilitySurfaceName))
                {
                    indexVolSurface = (IVolatilitySurface)modelData.MarketEnvironment.GetPricingStructure(VolatilitySurfaceName);
                }
            }
            //Calculate the delta
            var delta = SimpleIRSwaptionInstrumentAnalytic.CalculateOptionDelta(IsCall, breakEvenRate, StrikeRate, expiryTime, timeToIndex, indexVolSurface);

            //Set the multiplier using the delta of the option.
            //Multiplier = delta;?
            Swap.Multiplier = System.Math.Abs(delta);
            //New function that converts the metrics by multiplying be the delta.
            var swapCalculations = Swap.Calculate(modelData);
            //childValuations.Add(swapCalculations);
            var childControllerValuations = AssetValuationHelper.AggregateMetrics(childValuations, new List <string>(Metrics), PaymentCurrencies); // modelData.ValuationDate);
            var streamAccrualFactor       = AssetValuationHelper.GetQuotationByMeasureType(fixedLeg, InstrumentMetrics.AccrualFactor.ToString());  //TODO This is not correct!
            var npv = AssetValuationHelper.GetQuotationByMeasureType(childControllerValuations, InstrumentMetrics.NPV.ToString());

            childValuations.Add(swapCalculations);
            // Child metrics have now been calculated so we can now evaluate the stream model metrics
            if (swaptionControllerMetrics.Count > 0)
            {
                //Get the market data.
                IFxCurve fxCurve = null;
                ISwaptionInstrumentParameters analyticModelParameters = new SwaptionInstrumentParameters
                {
                    IsBought          = IsBasePartyBuyer,
                    IsCall            = IsCall,
                    SwapAccrualFactor = System.Math.Abs(streamAccrualFactor.value),
                    Strike            = StrikeRate,
                    OtherNPV          = npv.value,
                    TimeToExpiry      = (decimal)expiryTime,
                    SwapBreakEvenRate = breakEvenRate,
                    //OtherNPV =
                };
                // Curve Related
                if (modelData.MarketEnvironment is ISwapLegEnvironment streamMarket)
                {
                    analyticModelParameters.VolatilitySurface = indexVolSurface;
                    //Check for currency.
                    if (ModelData.ReportingCurrency != null)
                    {
                        if (ModelData.ReportingCurrency.Value != PaymentCurrencies[0])//This is an interest rate swap and so only has one currency.
                        {
                            fxCurve = streamMarket.GetReportingCurrencyFxCurve();
                            fxCurve.PricingStructureEvolutionType = PricingStructureEvolutionType;
                        }
                    }
                }
                var analyticsModel = new SimpleIRSwaptionInstrumentAnalytic(ModelData.ValuationDate, (decimal)timeToIndex,
                                                                            StrikeRate, fxCurve, indexVolSurface);
                AnalyticsModel          = analyticsModel;
                Volatility              = analyticsModel.Volatility;
                AnalyticModelParameters = analyticModelParameters;
                CalculationResults      = AnalyticsModel.Calculate <ISwaptionInstrumentResults, SwaptionInstrumentResults>(analyticModelParameters, swaptionControllerMetrics.ToArray());
                // Now merge back into the overall stream valuation
                var swapControllerValuation = GetValue(CalculationResults, modelData.ValuationDate);
                //childValuations.Add(swapControllerValuation);
                childControllerValuations = AssetValuationHelper.AggregateMetrics(childValuations, new List <string>(Metrics), PaymentCurrencies);// modelData.ValuationDate);
                swaptionValuation         = AssetValuationHelper.UpdateValuation(swapControllerValuation,
                                                                                 childControllerValuations, ConvertMetrics(swaptionControllerMetrics), new List <string>(Metrics));
                //swaptionValuation = AssetValuationHelper.AggregateMetrics(childValuations, new List<string>(Metrics), modelData.ValuationDate);
            }
            else
            {
                swaptionValuation = childControllerValuations;
            }
            CalculationPerfomedIndicator = true;
            swaptionValuation.id         = Id;
            return(swaptionValuation);
        }
        /// <summary>
        /// Calculates the specified model data.
        /// </summary>
        /// <param name="modelData">The model data.</param>
        /// <returns></returns>
        public override AssetValuation Calculate(IInstrumentControllerData modelData)
        {
            ModelData = modelData;
            AnalyticModelParameters = null;
            CalculationResults      = null;
            UpdateBucketingInterval(ModelData.ValuationDate, PeriodHelper.Parse(CDefaultBucketingInterval));
            // 1. First derive the analytics to be evaluated via the stream controller model
            // NOTE: These take precendence of the child model metrics
            if (AnalyticsModel == null)
            {
                AnalyticsModel = new SimpleXccySwapInstrumentAnalytic();
            }
            var            swapControllerMetrics = ResolveModelMetrics(AnalyticsModel.Metrics);
            AssetValuation swapValuation;
            var            quotes = ModelData.AssetValuation.quote.ToList();

            if (AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.AccrualFactor.ToString()) == null)
            {
                var quote = QuotationHelper.Create(0.0m, InstrumentMetrics.AccrualFactor.ToString(), "DecimalValue");
                quotes.Add(quote);
            }
            if (AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.FloatingNPV.ToString()) == null)
            {
                var quote = QuotationHelper.Create(0.0m, InstrumentMetrics.FloatingNPV.ToString(), "DecimalValue");
                quotes.Add(quote);
            }
            if (AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.NPV.ToString()) == null)
            {
                var quote = QuotationHelper.Create(0.0m, InstrumentMetrics.NPV.ToString(), "DecimalValue");
                quotes.Add(quote);
            }
            ModelData.AssetValuation.quote = quotes.ToArray();
            //Sets the evolution type for calculations.
            foreach (var leg in Legs)
            {
                leg.PricingStructureEvolutionType = PricingStructureEvolutionType;
                leg.BucketedDates = BucketedDates;
                leg.Multiplier    = Multiplier;
            }
            if (AdditionalPayments != null)
            {
                foreach (var payment in AdditionalPayments)
                {
                    payment.PricingStructureEvolutionType = PricingStructureEvolutionType;
                    payment.BucketedDates = BucketedDates;
                    payment.Multiplier    = Multiplier;
                }
            }
            var legControllers = new List <InstrumentControllerBase> {
                PayLeg, ReceiveLeg
            };
            //The assetValuation list.
            var childValuations = new List <AssetValuation>();

            // 2. Now evaluate only the child specific metrics (if any)
            if (modelData.MarketEnvironment is ISwapLegEnvironment)
            {
                var        market        = (SwapLegEnvironment)modelData.MarketEnvironment;
                IRateCurve discountCurve = null;
                IRateCurve forecastCurve = null;
                IFxCurve   currencyCurve = null;
                foreach (var leg in legControllers)
                {
                    var stream = (PriceableInterestRateStream)leg;
                    if (modelData.ReportingCurrency == null)
                    {
                        modelData.ReportingCurrency = stream.Currency;
                    }
                    if (stream.DiscountCurveName != null)
                    {
                        discountCurve = market.GetDiscountRateCurve();
                    }
                    if (stream.ForecastCurveName != null)
                    {
                        forecastCurve = market.GetForecastRateCurve();
                    }
                    if (modelData.ReportingCurrency.Value != stream.Currency.Value)
                    {
                        //stream.ReportingCurrencyFxCurveName =
                        //    MarketEnvironmentHelper.ResolveFxCurveNames(stream.Currency.Value, modelData.ReportingCurrency.Value);
                        currencyCurve = market.GetReportingCurrencyFxCurve();
                    }
                    modelData.MarketEnvironment = MarketEnvironmentHelper.CreateInterestRateStreamEnvironment(modelData.ValuationDate, discountCurve, forecastCurve, currencyCurve);
                    childValuations.Add(leg.Calculate(modelData));
                }
                if (GetAdditionalPayments() != null)
                {
                    var paymentControllers = new List <InstrumentControllerBase>(GetAdditionalPayments());
                    childValuations.AddRange(paymentControllers.Select(payment => payment.Calculate(modelData)));
                }
            }
            else
            {
                childValuations = EvaluateChildMetrics(legControllers, modelData, Metrics);
            }
            var childControllerValuations = AssetValuationHelper.AggregateMetrics(childValuations, new List <string>(Metrics), PaymentCurrencies);// modelData.ValuationDate);

            childControllerValuations.id = Id + ".InterestRateStreams";
            // Child metrics have now been calculated so we can now evaluate the stream model metrics
            if (swapControllerMetrics.Count > 0)
            {
                //TODO need to fix this calculation.
                var payStreamAccrualFactor     = AssetValuationHelper.GetQuotationByMeasureType(childValuations[0], InstrumentMetrics.AccrualFactor.ToString()); //AggregateMetric(InstrumentMetrics.AccrualFactor, childValuations);
                var payStreamNPV               = AssetValuationHelper.GetQuotationByMeasureType(childValuations[0], InstrumentMetrics.NPV.ToString());           //AggregateMetric(InstrumentMetrics.NPV, childValuations);
                var payStreamFloatingNPV       = AssetValuationHelper.GetQuotationByMeasureType(childValuations[0], InstrumentMetrics.FloatingNPV.ToString());   //AggregateMetric(InstrumentMetrics.FloatingNPV, childValuations);
                var receiveStreamAccrualFactor = AssetValuationHelper.GetQuotationByMeasureType(childValuations[1], InstrumentMetrics.AccrualFactor.ToString()); //AggregateMetric(InstrumentMetrics.AccrualFactor, childValuations);
                var receiveStreamNPV           = AssetValuationHelper.GetQuotationByMeasureType(childValuations[1], InstrumentMetrics.NPV.ToString());           //AggregateMetric(InstrumentMetrics.NPV, childValuations);
                var receiveStreamFloatingNPV   = AssetValuationHelper.GetQuotationByMeasureType(childValuations[1], InstrumentMetrics.FloatingNPV.ToString());
                IIRSwapInstrumentParameters analyticModelParameters = new SwapInstrumentParameters
                {
                    IsPayFixedInd              = true,
                    PayStreamAccrualFactor     = payStreamAccrualFactor.value,
                    PayStreamFloatingNPV       = payStreamFloatingNPV.value,
                    PayStreamNPV               = payStreamNPV.value,
                    ReceiveStreamFloatingNPV   = receiveStreamFloatingNPV.value,
                    ReceiveStreamNPV           = receiveStreamNPV.value,
                    ReceiveStreamAccrualFactor = receiveStreamAccrualFactor.value,
                    NPV = payStreamNPV.value + receiveStreamNPV.value
                };
                CalculationResults = AnalyticsModel.Calculate <IIRSwapInstrumentResults, SwapInstrumentResults>(analyticModelParameters, swapControllerMetrics.ToArray());
                // Now merge back into the overall stream valuation
                var swapControllerValuation = GetValue(CalculationResults, modelData.ValuationDate);
                swapValuation = AssetValuationHelper.UpdateValuation(swapControllerValuation,
                                                                     childControllerValuations, ConvertMetrics(swapControllerMetrics), new List <string>(Metrics));
            }
            else
            {
                swapValuation = childControllerValuations;
            }
            CalculationPerfomedIndicator = true;
            swapValuation.id             = Id;
            return(swapValuation);
        }
        /// <summary>
        /// Calculates the specified model data.
        /// </summary>
        /// <param name="modelData">The model data.</param>
        /// <returns></returns>
        public override AssetValuation Calculate(IInstrumentControllerData modelData)
        {
            ModelData = modelData;
            AnalyticModelParameters = null;
            CalculationResults      = null;
            UpdateBucketingInterval(ModelData.ValuationDate, PeriodHelper.Parse(CDefaultBucketingInterval));
            // 1. First derive the analytics to be evaluated via the stream controller model
            // NOTE: These take precedence of the child model metrics
            if (AnalyticsModel == null)
            {
                AnalyticsModel = new TermDepositInstrumentAnalytic();
            }
            var termDepositControllerMetrics = ResolveModelMetrics(AnalyticsModel.Metrics);

            //Allows the evolution type to be modified pre-calculation.
            //Set the children
            foreach (var cashflow in GetChildren())
            {
                if (cashflow is PriceableCashflow priceableCashflow)
                {
                    priceableCashflow.BucketedDates = BucketedDates;
                    priceableCashflow.PricingStructureEvolutionType = PricingStructureEvolutionType;
                    priceableCashflow.Multiplier = Multiplier;
                }
            }
            var childControllers = new List <InstrumentControllerBase>(GetChildren());

            //The assetValuation list.
            ChildValuations = new List <AssetValuation>();
            // 2. Now evaluate only the child specific metrics (if any)
            ChildValuations = EvaluateChildMetrics(childControllers, modelData, Metrics);
            var childControllerValuations = AssetValuationHelper.AggregateMetrics(ChildValuations, new List <string>(Metrics), PaymentCurrencies);// modelData.ValuationDate);

            childControllerValuations.id = Id + ".Cashflows";
            AssetValuation depositValuation;

            // Child metrics have now been calculated so we can now evaluate the stream model metrics
            if (termDepositControllerMetrics.Count > 0)
            {
                var reportingCurrency = ModelData.ReportingCurrency == null
                                            ? Currency.Value
                                            : ModelData.ReportingCurrency.Value;
                var marketQuote = FixedRate;
                ITermDepositInstrumentParameters analyticModelParameters = new TermDepositInstrumentParameters
                {
                    Multiplier        = Multiplier,
                    Currency          = Currency.Value,
                    ReportingCurrency = reportingCurrency,
                    BreakEvenRate     = InterestAmount.CalculationResults.ImpliedQuote,
                    MarketQuote       = marketQuote
                };
                CalculationResults = AnalyticsModel.Calculate <ITermDepositInstrumentResults, TermDepositInstrumentResults>(analyticModelParameters, termDepositControllerMetrics.ToArray());
                // Now merge back into the overall stream valuation
                var streamControllerValuation = GetValue(CalculationResults, modelData.ValuationDate);
                depositValuation = AssetValuationHelper.UpdateValuation(streamControllerValuation,
                                                                        ChildValuations, ConvertMetrics(termDepositControllerMetrics), new List <string>(Metrics), PaymentCurrencies);// modelData.ValuationDate);
            }
            else
            {
                depositValuation = childControllerValuations;
            }
            CalculationPerformedIndicator = true;
            depositValuation.id           = Id;
            return(depositValuation);
        }
        public override AssetValuation Calculate(IInstrumentControllerData modelData)
        {
            ModelData = modelData;
            AnalyticModelParameters = null;
            CalculationResults      = null;
            UpdateBucketingInterval(ModelData.ValuationDate, PeriodHelper.Parse(CDefaultBucketingInterval));
            // 1. First derive the analytics to be evaluated via the stream controller model
            // NOTE: These take precendence of the child model metrics
            if (AnalyticsModel == null)
            {
                AnalyticsModel = new FxLegAnalytic();
            }
            AssetValuation streamValuation;
            //Check if risk calc are required.
            bool delta0PDH = AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.LocalCurrencyDelta0PDH.ToString()) != null ||
                             AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.Delta0PDH.ToString()) != null;
            bool delta1PDH = AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.LocalCurrencyDelta1PDH.ToString()) != null ||
                             AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.Delta1PDH.ToString()) != null;
            var streamControllerMetrics = ResolveModelMetrics(AnalyticsModel.Metrics);
            var childValuations         = new List <AssetValuation>();

            foreach (var payment in Payments)
            {
                payment.PricingStructureEvolutionType = PricingStructureEvolutionType;
                payment.BucketedDates = BucketedDates;
                payment.Multiplier    = Multiplier;
            }

            if (modelData.MarketEnvironment is IFxLegEnvironment marketEnvironment)//TODO need to look at PricingStructureEvolutionType.
            {
                //Modify the second market.
                var curveName1 = marketEnvironment.GetExchangeCurrencyPaymentEnvironment1();
                var modelData1 = new InstrumentControllerData(modelData.AssetValuation, curveName1,
                                                              modelData.ValuationDate, modelData.ReportingCurrency);
                var curveName2 = marketEnvironment.GetExchangeCurrencyPaymentEnvironment2();
                var modelData2 = new InstrumentControllerData(modelData.AssetValuation, curveName2,
                                                              modelData.ValuationDate, modelData.ReportingCurrency);
                childValuations.Add(Currency1Payment.Calculate(modelData1));
                childValuations.Add(Currency2Payment.Calculate(modelData2));
            }
            else if (modelData.MarketEnvironment.GetType() == typeof(MarketEnvironment))
            {
                var market = (MarketEnvironment)modelData.MarketEnvironment;
                if (delta0PDH)
                {
                    //Force building of the risk curves.
                    //market.SearchForPerturbedPricingStructures(FxIndexCurveName, "delta0PDH");//TODO Need to add this perturbation to fxCurve.
                }
                if (delta1PDH)
                {
                    //Force building of the risk curves.
                    market.SearchForPerturbedPricingStructures(Currency1DiscountCurveName, "delta1PDH");
                    market.SearchForPerturbedPricingStructures(Currency2DiscountCurveName, "delta1PDH");
                }
                //This defines the cross cureves from the payment currency to the reporting
                //currency for each leg of the fx trade.
                //
                if (modelData.ReportingCurrency.Value != Currency1.Value)
                {
                    ReportingCurrencyFxCurveName1 =
                        MarketEnvironmentHelper.ResolveFxCurveNames(Currency1.Value,
                                                                    modelData.ReportingCurrency.Value);
                }
                if (modelData.ReportingCurrency.Value != Currency2.Value)
                {
                    ReportingCurrencyFxCurveName2 =
                        MarketEnvironmentHelper.ResolveFxCurveNames(Currency2.Value,
                                                                    modelData.ReportingCurrency.Value);
                }
                childValuations.Add(Currency1Payment.Calculate(modelData));
                childValuations.Add(Currency2Payment.Calculate(modelData));
            }
            var paymentValuation          = AssetValuationHelper.AggregateMetrics(childValuations, new List <string>(Metrics), PaymentCurrencies);
            var childControllerValuations = new List <AssetValuation> {
                paymentValuation
            };

            // Child metrics have now been calculated so we can now evaluate the stream model metrics
            if (streamControllerMetrics.Count > 0)
            {
                var rate = ExchangeRate.rate;
                if (modelData.MarketEnvironment is MarketEnvironment market)
                {
                    var fxCurve = (IFxCurve)market.SearchForPricingStructureType(FxIndexCurveName);
                    if (HybridValuation)
                    {
                        var curve1 = (IRateCurve)market.SearchForPricingStructureType(Currency1DiscountCurveName);
                        var curve2 = (IRateCurve)market.SearchForPricingStructureType(Currency2DiscountCurveName);
                        var flag   = ExchangeRate.quotedCurrencyPair.quoteBasis == QuoteBasisEnum.Currency2PerCurrency1;
                        AnalyticsModel = new FxLegAnalytic(modelData.ValuationDate, RiskMaturityDate, fxCurve, curve1,
                                                           curve2, flag);
                    }
                    else
                    {
                        AnalyticsModel = new FxLegAnalytic(modelData.ValuationDate, RiskMaturityDate, fxCurve);
                    }
                }
                IFxLegParameters analyticModelParameters = new FxLegParameters
                {
                    Multiplier  = Multiplier,
                    MarketQuote = rate,
                };
                CalculationResults =
                    AnalyticsModel.Calculate <IFxLegInstrumentResults, FxLegInstrumentResults>(
                        analyticModelParameters, streamControllerMetrics.ToArray());
                // Now merge back into the overall stream valuation
                var streamControllerValuation = GetValue(CalculationResults, modelData.ValuationDate);
                streamValuation = AssetValuationHelper.UpdateValuation(streamControllerValuation,
                                                                       childControllerValuations,
                                                                       ConvertMetrics(streamControllerMetrics),
                                                                       new List <string>(Metrics), PaymentCurrencies);
            }
            else
            {
                streamValuation = paymentValuation;
            }
            CalculationPerfomedIndicator = true;
            streamValuation.id           = Id;
            return(streamValuation);
        }
        public override AssetValuation Calculate(IInstrumentControllerData modelData)
        {
            ModelData = modelData;
            AnalyticModelParameters = null;
            // 1. First derive the analytics to be evaluated via the stream controller model
            // NOTE: These take precedence of the child model metrics
            if (AnalyticsModel == null)
            {
                AnalyticsModel = new BondTransactionAnalytic();
            }
            var            bondControllerMetrics = ResolveModelMetrics(AnalyticsModel.Metrics);
            AssetValuation bondValuation;
            var            quotes = ModelData.AssetValuation.quote.ToList();

            if (AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.AccrualFactor.ToString()) == null)
            {
                var quote = QuotationHelper.Create(0.0m, InstrumentMetrics.AccrualFactor.ToString(), "DecimalValue");
                quotes.Add(quote);
            }
            if (AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.FloatingNPV.ToString()) == null)
            {
                var quote = QuotationHelper.Create(0.0m, InstrumentMetrics.FloatingNPV.ToString(), "DecimalValue");
                quotes.Add(quote);
            }
            if (AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.NPV.ToString()) == null)
            {
                var quote = QuotationHelper.Create(0.0m, InstrumentMetrics.NPV.ToString(), "DecimalValue");
                quotes.Add(quote);
            }
            ModelData.AssetValuation.quote = quotes.ToArray();
            var        marketEnvironment = modelData.MarketEnvironment;
            IRateCurve rateDiscountCurve = null;

            //2. Sets the evolution type for coupon and payment calculations.
            Coupons.PricingStructureEvolutionType = PricingStructureEvolutionType;
            Coupons.BucketedDates = BucketedDates;
            Coupons.Multiplier    = Multiplier;
            if (AdditionalPayments != null)
            {
                foreach (var payment in AdditionalPayments)
                {
                    payment.PricingStructureEvolutionType = PricingStructureEvolutionType;
                    payment.BucketedDates = BucketedDates;
                    payment.Multiplier    = Multiplier;
                }
            }
            //3. Aggregate the child metrics.
            List <AssetValuation> childValuations = new List <AssetValuation> {
                Coupons?.Calculate(modelData)
            };

            if (GetAdditionalPayments() != null)
            {
                var paymentControllers = new List <InstrumentControllerBase>(GetAdditionalPayments());
                childValuations.AddRange(paymentControllers.Select(payment => payment.Calculate(modelData)));
            }
            var childControllerValuations = AssetValuationHelper.AggregateMetrics(childValuations, new List <string>(Metrics), PaymentCurrencies);

            childControllerValuations.id = Id + ".BondCouponRateStreams";
            //4. Calc the asset as a little extra
            var metrics         = ResolveModelMetrics(AnalyticsModel.Metrics);
            var metricsAsString = metrics.Select(metric => metric.ToString()).ToList();
            var controllerData  = PriceableAssetFactory.CreateAssetControllerData(metricsAsString.ToArray(), modelData.ValuationDate, modelData.MarketEnvironment);

            UnderlyingBond.Multiplier = Multiplier;
            UnderlyingBond.Calculate(controllerData);
            //5. Now do the bond calculations.
            if (bondControllerMetrics.Count > 0)
            {
                CalculationResults = new BondTransactionResults();
                if (marketEnvironment.GetType() == typeof(MarketEnvironment))
                {
                    var bondCurve = (IBondCurve)modelData.MarketEnvironment.GetPricingStructure(BondCurveName);
                    if (bondCurve != null)
                    {
                        var marketDataType =
                            bondCurve.GetPricingStructureId().Properties.GetValue <string>(AssetMeasureEnum.MarketQuote.ToString(), false);
                        if (marketDataType != null && marketDataType == BondPriceEnum.YieldToMaturity.ToString())
                        {
                            IsYTMQuote = true;
                        }
                        //TODO handle the other cases like: AssetSwapSpread; DirtyPrice and ZSpread.
                        var mq = (decimal)bondCurve.GetYieldToMaturity(modelData.ValuationDate, SettlementDate);
                        Quote = BasicQuotationHelper.Create(mq, AssetMeasureEnum.MarketQuote.ToString(),
                                                            PriceQuoteUnitsEnum.DecimalRate.ToString());
                    }
                    rateDiscountCurve = (IRateCurve)modelData.MarketEnvironment.GetPricingStructure(DiscountCurveName);
                }
                //Generate the vectors
                const bool isBuyerInd = true;
                var        analyticModelParameters = new BondTransactionParameters
                {
                    IsBuyerInd           = isBuyerInd,
                    AccrualYearFractions = GetCouponAccrualFactors(),
                    Multiplier           = Multiplier,
                    Quote                  = QuoteValue,
                    CouponRate             = UnderlyingBond.GetCouponRate(),
                    NotionalAmount         = UnderlyingBond.Notional,
                    Frequency              = UnderlyingBond.Frequency,
                    IsYTMQuote             = IsYTMQuote,
                    AccruedFactor          = UnderlyingBond.GetAccruedFactor(),
                    RemainingAccruedFactor = UnderlyingBond.GetRemainingAccruedFactor(),
                    PaymentDiscountFactors =
                        GetDiscountFactors(rateDiscountCurve, Coupons.StreamPaymentDates.ToArray(), modelData.ValuationDate),
                };
                //5. Get the Weightings
                analyticModelParameters.Weightings =
                    CreateWeightings(CDefaultWeightingValue, analyticModelParameters.PaymentDiscountFactors.Length);
                //6. Set the analytic input parameters and Calculate the respective metrics
                AnalyticModelParameters = analyticModelParameters;
                CalculationResults      = AnalyticsModel.Calculate <IBondTransactionResults, BondTransactionResults>(analyticModelParameters, metrics.ToArray());
                // Now merge back into the overall stream valuation
                var bondControllerValuation = GetValue(CalculationResults, modelData.ValuationDate);
                bondValuation = AssetValuationHelper.UpdateValuation(bondControllerValuation,
                                                                     childControllerValuations, ConvertMetrics(bondControllerMetrics), new List <string>(Metrics));
            }
            else
            {
                bondValuation = childControllerValuations;
            }
            // store inputs and results from this run
            CalculationPerformedIndicator = true;
            bondValuation.id = Id;
            return(bondValuation);
        }
示例#7
0
        public override AssetValuation Calculate(IInstrumentControllerData modelData)
        {
            ModelData = modelData;
            AnalyticModelParameters = null;
            CalculationResults      = null;
            UpdateBucketingInterval(ModelData.ValuationDate, PeriodHelper.Parse(CDefaultBucketingInterval));
            // 1. First derive the analytics to be evaluated via the stream controller model
            // NOTE: These take precendence of the child model metrics
            if (AnalyticsModel == null)
            {
                AnalyticsModel = new FxOptionLegAnalytic();
            }
            var            marketEnvironment = modelData.MarketEnvironment as IFxLegEnvironment;
            AssetValuation streamValuation;
            //Check if risk calc are required.
            bool delta0PDH = AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.LocalCurrencyDelta0PDH.ToString()) != null ||
                             AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.Delta0PDH.ToString()) != null;
            bool delta1PDH = AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.LocalCurrencyDelta1PDH.ToString()) != null ||
                             AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.Delta1PDH.ToString()) != null;
            var streamControllerMetrics = ResolveModelMetrics(AnalyticsModel.Metrics);
            var childValuations         = new List <AssetValuation>();

            // 2. Now evaluate only the child specific metrics (if any)
            foreach (var payment in FxLeg.Payments)
            {
                payment.Multiplier = Multiplier;
                payment.PricingStructureEvolutionType = PricingStructureEvolutionType;
                payment.BucketedDates = BucketedDates;
            }
            foreach (var premium in Premia)
            {
                premium.Multiplier = 1.0m;
                premium.PricingStructureEvolutionType = PricingStructureEvolutionType;
                premium.BucketedDates = BucketedDates;
            }
            if (marketEnvironment != null)
            {
                //Modify the second market.
                var modelData1 = new InstrumentControllerData(modelData.AssetValuation,
                                                              marketEnvironment.GetExchangeCurrencyPaymentEnvironment1(),
                                                              modelData.ValuationDate, modelData.ReportingCurrency);
                var modelData2 = new InstrumentControllerData(modelData.AssetValuation,
                                                              marketEnvironment.GetExchangeCurrencyPaymentEnvironment2(),
                                                              modelData.ValuationDate, modelData.ReportingCurrency);
                childValuations.Add(Currency1Payment.Calculate(modelData1));
                childValuations.Add(Currency2Payment.Calculate(modelData2));
                childValuations.AddRange(Premia.Select(premium => premium.Calculate(modelData2)));
            }
            else if (modelData.MarketEnvironment.GetType() == typeof(MarketEnvironment))
            {
                var market = (MarketEnvironment)modelData.MarketEnvironment;
                if (delta0PDH)
                {
                    //    //Force building of the risk curves.
                    //    market.SearchForPerturbedPricingStructures(FxIndexCurveName, "delta0PDH");//TODO Need to add this perturbation to fxCurve.
                }
                if (delta1PDH)
                {
                    //Force building of the risk curves.
                    market.SearchForPerturbedPricingStructures(FxLeg.Currency1DiscountCurveName, "delta1PDH");
                    market.SearchForPerturbedPricingStructures(FxLeg.Currency2DiscountCurveName, "delta1PDH");
                }
                childValuations = EvaluateChildMetrics(GetChildren().ToList(), modelData, Metrics);
                //childValuations.Add(Currency1Payment.Calculate(modelData));
            }
            var paymentValuation          = AssetValuationHelper.AggregateMetrics(childValuations, new List <string>(Metrics), PaymentCurrencies);// modelData.ValuationDate);
            var childControllerValuations = new List <AssetValuation> {
                paymentValuation
            };

            TimeToExpiry = GetPaymentYearFraction(ModelData.ValuationDate, ExpiryDate);
            var volatilityCurveNodeTime = GetPaymentYearFraction(ModelData.ValuationDate, ValueDate);

            // Child metrics have now been calculated so we can now evaluate the stream model metrics
            if (streamControllerMetrics.Count > 0)
            {
                if (modelData.MarketEnvironment is MarketEnvironment market)
                {
                    var fxCurve      = (IFxCurve)market.SearchForPricingStructureType(FxLeg.FxIndexCurveName);
                    var indexSurface = (IVolatilitySurface)market.SearchForPricingStructureType(VolatilitySurfaceName);
                    if (HybridValuation)
                    {
                        var curve1 = (IRateCurve)market.SearchForPricingStructureType(FxLeg.Currency1DiscountCurveName);
                        var curve2 = (IRateCurve)market.SearchForPricingStructureType(FxLeg.Currency2DiscountCurveName);
                        var flag   = FxLeg.ExchangeRate.quotedCurrencyPair.quoteBasis == QuoteBasisEnum.Currency2PerCurrency1;
                        AnalyticsModel = new FxOptionLegAnalytic(modelData.ValuationDate, RiskMaturityDate, fxCurve, curve1,
                                                                 curve2, flag, FxStrike, TimeToExpiry, volatilityCurveNodeTime, indexSurface, FxOptionType);
                    }
                    else
                    {
                        AnalyticsModel = new FxOptionLegAnalytic(modelData.ValuationDate, RiskMaturityDate, fxCurve, FxStrike, TimeToExpiry, volatilityCurveNodeTime, indexSurface, FxOptionType);
                    }
                }
                decimal?premium = null;
                if (Premia.Count > 1)
                {
                    premium = Premia[0].PaymentAmount.amount; // We assume only a single premium in the basic case.
                }
                IFxOptionLegParameters analyticModelParameters = new FxOptionLegParameters
                {
                    Premium = premium,
                };
                CalculationResults =
                    AnalyticsModel.Calculate <IFxOptionLegInstrumentResults, FxOptionLegInstrumentResults>(
                        analyticModelParameters, streamControllerMetrics.ToArray());

                // Now merge back into the overall stream valuation
                var streamControllerValuation = GetValue(CalculationResults, modelData.ValuationDate);
                streamValuation = AssetValuationHelper.UpdateValuation(streamControllerValuation,
                                                                       childControllerValuations,
                                                                       ConvertMetrics(streamControllerMetrics),
                                                                       new List <string>(Metrics), PaymentCurrencies);// modelData.ValuationDate);
            }
            else
            {
                streamValuation = paymentValuation;
            }
            CalculationPerformedIndicator = true;
            streamValuation.id            = Id;
            return(streamValuation);
        }
示例#8
0
        /// <summary>
        /// Calculates the specified model data.
        /// </summary>
        /// <param name="modelData">The model data.</param>
        /// <returns></returns>
        public override AssetValuation Calculate(IInstrumentControllerData modelData)
        {
            ModelData = modelData;
            AnalyticModelParameters = null;
            CalculationResults      = null;
            UpdateBucketingInterval(ModelData.ValuationDate, PeriodHelper.Parse(CDefaultBucketingInterval));
            // 1. First derive the analytics to be evaluated via the stream controller model
            // NOTE: These take precedence of the child model metrics
            if (AnalyticsModel == null)
            {
                AnalyticsModel = new FxSwapAnalytic();
            }
            var            swapControllerMetrics = ResolveModelMetrics(AnalyticsModel.Metrics);
            AssetValuation swapValuation;

            //Sets the evolution type for calculations.
            foreach (var leg in Legs)
            {
                leg.PricingStructureEvolutionType = PricingStructureEvolutionType;
                leg.BucketedDates = BucketedDates;
                leg.Multiplier    = Multiplier;
            }
            var legControllers = new List <InstrumentControllerBase>(GetLegs());
            //The assetValuation list.
            var childValuations = new List <AssetValuation>();

            // 2. Now evaluate only the child specific metrics (if any)
            if (modelData.MarketEnvironment.GetType() == typeof(MarketEnvironment))
            {
                childValuations.AddRange(legControllers.Select(leg => leg.Calculate(modelData)));
            }
            else
            {
                childValuations = EvaluateChildMetrics(legControllers, modelData, Metrics);
            }
            var childControllerValuations = AssetValuationHelper.AggregateMetrics(childValuations, new List <string>(Metrics), PaymentCurrencies);// modelData.ValuationDate);

            childControllerValuations.id = Id + ".FxLeg";
            // Child metrics have now been calculated so we can now evaluate the stream model metrics
            if (swapControllerMetrics.Count > 0)
            {
                IFxSwapParameters analyticModelParameters = new FxSwapParameters
                {
                    Multiplier = Multiplier,
                    //AccrualFactor = AggregateCouponMetric(InstrumentMetrics.AccrualFactor),
                    //FloatingNPV = AggregateCouponMetric(InstrumentMetrics.FloatingNPV),
                    //NPV = AggregateCouponMetric(InstrumentMetrics.NPV)
                };
                CalculationResults = AnalyticsModel.Calculate <IFxSwapInstrumentResults, FxSwapInstrumentResults>(analyticModelParameters, swapControllerMetrics.ToArray());
                // Now merge back into the overall stream valuation
                var swapControllerValuation = GetValue(CalculationResults, modelData.ValuationDate);
                swapValuation = AssetValuationHelper.UpdateValuation(swapControllerValuation,
                                                                     childControllerValuations, ConvertMetrics(swapControllerMetrics), new List <string>(Metrics));
            }
            else
            {
                swapValuation = childControllerValuations;
            }
            CalculationPerformedIndicator = true;
            swapValuation.id = Id;
            return(swapValuation);
        }
示例#9
0
        /// <summary>
        /// Calculates the specified model data.
        /// </summary>
        /// <param name="modelData">The model data.</param>
        /// <returns></returns>
        public override AssetValuation Calculate(IInstrumentControllerData modelData)
        {
            ModelData = modelData;
            AnalyticModelParameters = null;
            CalculationResults      = null;
            UpdateBucketingInterval(ModelData.ValuationDate, PeriodHelper.Parse(CDefaultBucketingInterval));
            // 1. First derive the analytics to be evaluated via the stream controller model
            // NOTE: These take precendence of the child model metrics
            if (AnalyticsModel == null)
            {
                AnalyticsModel = new CapFloorInstrumentAnalytic();
            }
            var            swapControllerMetrics = ResolveModelMetrics(AnalyticsModel.Metrics);
            AssetValuation swapValuation;

            //Sets the evolution type for calculations.
            CapFloorLeg.PricingStructureEvolutionType = PricingStructureEvolutionType;
            CapFloorLeg.BucketedDates = BucketedDates;
            CapFloorLeg.Multiplier    = Multiplier;
            if (AdditionalPayments != null)
            {
                foreach (var payment in AdditionalPayments)
                {
                    payment.PricingStructureEvolutionType = PricingStructureEvolutionType;
                    payment.BucketedDates = BucketedDates;
                    payment.Multiplier    = Multiplier;
                }
            }
            //The assetValuation list.
            var childValuations = new List <AssetValuation> {
                CapFloorLeg.Calculate(modelData)
            };

            // 2. Now evaluate only the child specific metrics (if any)
            if (GetAdditionalPayments() != null)
            {
                var paymentControllers = new List <InstrumentControllerBase>(GetAdditionalPayments());
                childValuations.AddRange(paymentControllers.Select(payment => payment.Calculate(modelData)));
            }
            var childControllerValuations = AssetValuationHelper.AggregateMetrics(childValuations, new List <string>(Metrics), PaymentCurrencies);// modelData.ValuationDate);

            childControllerValuations.id = Id + ".CapFloorStreams";
            // Child metrics have now been calculated so we can now evaluate the stream model metrics
            if (swapControllerMetrics.Count > 0)
            {
                //Generate the vectors
                var streamAccrualFactor = AssetValuationHelper.GetQuotationByMeasureType(childValuations[0], InstrumentMetrics.AccrualFactor.ToString());
                var streamFloatingNPV   = AssetValuationHelper.GetQuotationByMeasureType(childValuations[0], InstrumentMetrics.FloatingNPV.ToString());
                var streamNPV           = AssetValuationHelper.GetQuotationByMeasureType(childValuations[0], InstrumentMetrics.NPV.ToString());
                IIRSwapInstrumentParameters analyticModelParameters = new SwapInstrumentParameters
                {
                    AccrualFactor = streamAccrualFactor.value,
                    FloatingNPV   = streamFloatingNPV.value,
                    NPV           = streamNPV.value
                                    //, MarketQuote = MarketQuote.
                };
                AnalyticModelParameters = analyticModelParameters;
                CalculationResults      = AnalyticsModel.Calculate <IIRSwapInstrumentResults, SwapInstrumentResults>(analyticModelParameters, swapControllerMetrics.ToArray());
                // Now merge back into the overall stream valuation
                var swapControllerValuation = GetValue(CalculationResults, modelData.ValuationDate);
                swapValuation = AssetValuationHelper.UpdateValuation(swapControllerValuation,
                                                                     childControllerValuations, ConvertMetrics(swapControllerMetrics), new List <string>(Metrics));
            }
            else
            {
                swapValuation = childControllerValuations;
            }
            CalculationPerfomedIndicator = true;
            swapValuation.id             = Id;
            return(swapValuation);
        }
        public override AssetValuation Calculate(IInstrumentControllerData modelData)
        {
            ModelData = modelData;
            AnalyticModelParameters = null;
            CalculationResults      = null;
            UpdateBucketingInterval(ModelData.ValuationDate, PeriodHelper.Parse(CDefaultBucketingInterval));
            // 1. First derive the analytics to be evaluated via the stream controller model
            // NOTE: These take precendence of the child model metrics
            if (AnalyticsModel == null)
            {
                AnalyticsModel = new CapFloorStreamAnalytic();
            }
            var            streamControllerMetrics = ResolveModelMetrics(AnalyticsModel.Metrics);
            AssetValuation streamValuation;

            // 2. Now evaluate only the child specific metrics (if any)
            foreach (var coupon in Coupons)
            {
                coupon.PricingStructureEvolutionType = PricingStructureEvolutionType;
                coupon.BucketedDates = BucketedDates;
                coupon.Multiplier    = 1.0m;//TODO this will have to be fixed eventually.
            }
            var childControllers = new List <InstrumentControllerBase>(Coupons.ToArray());
            //Add the extra metrics required
            var quotes = ModelData.AssetValuation.quote.ToList();

            if (AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.AccrualFactor.ToString()) == null)
            {
                var quote = QuotationHelper.Create(0.0m, InstrumentMetrics.AccrualFactor.ToString(), "DecimalValue");
                quotes.Add(quote);
            }
            if (AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.FloatingNPV.ToString()) == null)
            {
                var quote = QuotationHelper.Create(0.0m, InstrumentMetrics.FloatingNPV.ToString(), "DecimalValue");
                quotes.Add(quote);
            }
            if (AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.NPV.ToString()) == null)
            {
                var quote = QuotationHelper.Create(0.0m, InstrumentMetrics.NPV.ToString(), "DecimalValue");
                quotes.Add(quote);
            }
            if (AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.LocalCurrencyNPV.ToString()) == null)
            {
                var quote = QuotationHelper.Create(0.0m, InstrumentMetrics.LocalCurrencyNPV.ToString(), "DecimalValue");
                quotes.Add(quote);
            }
            if (AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.LocalCurrencyExpectedValue.ToString()) == null)
            {
                var quote = QuotationHelper.Create(0.0m, InstrumentMetrics.LocalCurrencyExpectedValue.ToString(), "DecimalValue");
                quotes.Add(quote);
            }
            ModelData.AssetValuation.quote = quotes.ToArray();
            var childValuations           = EvaluateChildMetrics(childControllers, modelData, Metrics);
            var couponValuation           = AssetValuationHelper.AggregateMetrics(childValuations, new List <string>(Metrics), PaymentCurrencies);// modelData.ValuationDate);
            var childControllerValuations = new List <AssetValuation> {
                couponValuation
            };

            if (Exchanges != null && Exchanges.Count > 0)
            {
                foreach (var exchange in Exchanges)
                {
                    exchange.PricingStructureEvolutionType = PricingStructureEvolutionType;
                    exchange.BucketedDates = BucketedDates;
                    exchange.Multiplier    = 1.0m;//TODO this will have to be fixed eventually.
                }
                // Roll-Up and merge child valuations into parent Valuation
                var childPrincipalControllers = new List <InstrumentControllerBase>(Exchanges.ToArray());
                var childPrincipalValuations  = EvaluateChildMetrics(childPrincipalControllers, modelData, Metrics);
                var principalValuation        = AssetValuationHelper.AggregateMetrics(childPrincipalValuations, new List <string>(Metrics), PaymentCurrencies);// modelData.ValuationDate);
                childControllerValuations.Add(principalValuation);
            }
            // Child metrics have now been calculated so we can now evaluate the stream model metrics
            if (streamControllerMetrics.Count > 0)
            {
                var reportingCurrency = ModelData.ReportingCurrency == null
                                            ? Currency.Value
                                            : ModelData.ReportingCurrency.Value;
                ICapFloorStreamParameters analyticModelParameters = new CapFloorStreamParameters
                {
                    Multiplier        = 1.0m,
                    Currency          = Currency.Value,
                    ReportingCurrency = reportingCurrency,
                    AccrualFactor     = AggregateMetric(InstrumentMetrics.AccrualFactor, childControllerValuations),
                    FloatingNPV       = AggregateMetric(InstrumentMetrics.FloatingNPV, childControllerValuations),
                    NPV = AggregateMetric(InstrumentMetrics.NPV, childControllerValuations)                                                          //,
                };
                CalculationResults = AnalyticsModel.Calculate <ICapFloorStreamInstrumentResults, CapFloorStreamInstrumentResults>(analyticModelParameters, streamControllerMetrics.ToArray());
                // Now merge back into the overall stream valuation
                var streamControllerValuation = GetValue(CalculationResults, modelData.ValuationDate);
                streamValuation = AssetValuationHelper.UpdateValuation(streamControllerValuation,
                                                                       childControllerValuations, ConvertMetrics(streamControllerMetrics), new List <string>(Metrics), PaymentCurrencies);// modelData.ValuationDate);
            }
            else
            {
                streamValuation = AssetValuationHelper.AggregateMetrics(childControllerValuations, new List <string>(Metrics), PaymentCurrencies);// modelData.ValuationDate);
            }
            CalculationPerfomedIndicator = true;
            streamValuation.id           = Id;
            return(streamValuation);
        }