示例#1
0
            private static Amount CalculateCorrelatedSumBuckets(Currency calculationCurrency, SensitivityRisk risk, Dictionary <IBucket, Decimal> thresholdFactors, List <MarginBucket> bucketMargins)
            {
                Dictionary <IBucket, Amount> weightingMarginSums = new Dictionary <IBucket, Amount>();

                foreach (MarginBucket bucketMargin in bucketMargins)
                {
                    Amount weightingMarginsSum = Amount.Sum(bucketMargin.Children.Select(x => x.Value), calculationCurrency);
                    Amount bucketMarginValue   = Amount.Max(Amount.Min(weightingMarginsSum, bucketMargin.Value), -bucketMargin.Value);
                    weightingMarginSums[bucketMargin.Bucket] = bucketMarginValue;
                }

                Amount sum = Amount.OfZero(calculationCurrency);

                foreach (IBucket bucket1 in weightingMarginSums.Keys)
                {
                    foreach (IBucket bucket2 in weightingMarginSums.Keys)
                    {
                        if (bucket1 != bucket2)
                        {
                            Decimal thresholdFactor1 = thresholdFactors[bucket1];
                            Decimal thresholdFactor2 = thresholdFactors[bucket2];
                            Decimal concentration    = Math.Min(thresholdFactor1, thresholdFactor2) / Math.Max(thresholdFactor1, thresholdFactor2);

                            Decimal correlationBucket = ModelParameters.GetCorrelationBucket(risk, bucket1, bucket2);
                            Decimal correlation       = correlationBucket * concentration;

                            sum += weightingMarginSums[bucket1] * weightingMarginSums[bucket2] * correlation;
                        }
                    }
                }

                return(sum);
            }
示例#2
0
            private static Amount CalculateCorrelatedSumBuckets(Currency calculationCurrency, SensitivityRisk risk, List <MarginBucket> bucketMargins)
            {
                Dictionary <IBucket, Amount> weightingMarginSums = new Dictionary <IBucket, Amount>();

                foreach (MarginBucket bucketMargin in bucketMargins)
                {
                    Amount weightingMarginsSum = Amount.Sum(bucketMargin.Children.Select(x => x.Value), calculationCurrency);
                    Amount bucketMarginAmount  = Amount.Max(Amount.Min(weightingMarginsSum, bucketMargin.Value), -bucketMargin.Value);
                    weightingMarginSums[bucketMargin.Bucket] = bucketMarginAmount;
                }

                Amount sum = Amount.OfZero(calculationCurrency);

                foreach (IBucket bucket1 in weightingMarginSums.Keys)
                {
                    foreach (IBucket bucket2 in weightingMarginSums.Keys)
                    {
                        if (bucket1 != bucket2)
                        {
                            Decimal correlation = MathUtilities.Square(ModelParameters.GetCorrelationBucket(risk, bucket1, bucket2));
                            sum += weightingMarginSums[bucket1] * weightingMarginSums[bucket2] * correlation;
                        }
                    }
                }

                return(sum);
            }