Esempio n. 1
0
        /// <summary>
        /// Builds this instance and retruns the underlying instrument associated with the controller
        /// </summary>
        /// <returns></returns>
        public new CapFloor Build()
        {
            var capFloor = new CapFloor
            {
                Items = new object[] { new ProductType {
                                           Value = ProductType.ToString()
                                       } },
                ItemsElementName  = new[] { ItemsChoiceType2.productType },
                additionalPayment = MapToPayments(AdditionalPayments),
                capFloorStream    = CapFloorLeg.Build()
            };

            return(capFloor);
        }
Esempio n. 2
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);
        }