Beispiel #1
0
        public static Quotation Add(Quotation quotation1, Quotation quotation2)
        {
            var result = QuotationHelper.Copy(quotation1);

            //new Quotation
            //             {
            //                 businessCenter = quotation1.businessCenter,
            //                 cashFlowType = quotation1.cashFlowType,
            //                 currency = quotation1.currency,
            //                 exchangeId = quotation1.exchangeId
            //             };
            //BinarySerializerHelper.Clone(quotation1);//TODO problem with the binary serializer
            if (null != quotation2)
            {
                result.value += quotation2.value;
                if (quotation2.sensitivitySet == null)
                {
                    return(result);
                }
                if (quotation1.sensitivitySet == null)
                {
                    result.sensitivitySet = quotation2.sensitivitySet;
                    return(result);
                }
                //Add the sensitivity set values.
                result.sensitivitySet = new[] { Add(quotation1.sensitivitySet[0], quotation2.sensitivitySet[0]) };
            }
            return(result);
        }
Beispiel #2
0
        public static AssetValuation Copy(AssetValuation baseValuation)
        {
            AssetValuation result = null;

            if (baseValuation != null)
            {
                result = new AssetValuation();
                if (baseValuation.quote != null)
                {
                    result.quote = QuotationHelper.Copy(baseValuation.quote).ToArray();
                }
                if (baseValuation.fxRate != null)
                {
                    result.fxRate = new FxRate();
                    if (baseValuation.fxRate.quotedCurrencyPair != null)
                    {
                        result.fxRate.quotedCurrencyPair = new QuotedCurrencyPair
                        {
                            currency1 =
                                CurrencyHelper.Copy(
                                    baseValuation.fxRate.quotedCurrencyPair.
                                    currency1),
                            currency2 =
                                CurrencyHelper.Copy(
                                    baseValuation.fxRate.quotedCurrencyPair.
                                    currency2),
                            quoteBasis =
                                baseValuation.fxRate.quotedCurrencyPair.
                                quoteBasis
                        };
                    }
                    result.fxRate.rate = baseValuation.fxRate.rate;
                }
                if (baseValuation.valuationScenarioReference != null)
                {
                    result.valuationScenarioReference = new ValuationScenarioReference
                    {
                        href = baseValuation.valuationScenarioReference.href
                    };
                }
                if (baseValuation.id != null)
                {
                    result.id = baseValuation.id;
                }
                if (baseValuation.objectReference != null)
                {
                    result.objectReference = new AnyAssetReference {
                        href = baseValuation.objectReference.href
                    };
                }
            }
            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Sums all quotations. They are assumed to be the same metric.
        /// </summary>
        /// <param name="quotationList">The quotation list contains all quotations of the same metric.</param>
        /// <param name="currency">THe currency of the quotation. This may be null.</param>
        /// <returns></returns>
        public static Quotation Sum(List <Quotation> quotationList, Currency currency)
        {
            var result = new List <Quotation>();//quotationList.FindAll(quotation => currency == quotation.currency);

            foreach (var quote in quotationList)
            {
                if (currency == null && quote.currency == null)
                {
                    result.Add(quote);
                }
                if (currency != null && quote.currency != null)
                {
                    if (currency.Value == quote.currency.Value)
                    {
                        result.Add(quote);
                    }
                }
            }
            if (0 == result.Count)
            {
                return(null);
            }
            if (1 == result.Count)
            {
                return(QuotationHelper.Copy(result[0]));//BinarySerializerHelper.Clone(result[0]);//TODO problem with the binary serializer
            }
            // clone collection internally - just to keep invariant of the method.
            //
            List <Quotation> clonedCollection = QuotationHelper.Copy(quotationList);//BinarySerializerHelper.Clone(quotationList);//TODO problem with the binary serializer
            Quotation        firstElement     = clonedCollection[0];

            clonedCollection.RemoveAt(0);
            Quotation sumOfTheTail = Sum(clonedCollection, currency);

            return(Add(firstElement, sumOfTheTail));
        }