private void AggregateMixSubject(int ParentPosition, ICoverState TotalCoverState, ICoverLevelNodeAggInfo LevelAggInfo, IDerivedCoverLevelNodeAggInfo DerivedInfo, float[] coverRatio, float[] FactorVector)
        {
            //TODO: for agg is fine, but for allocation we cannot use this method
            throw new NotSupportedException("Mix Derived cover subject is not supported");
            int[]   ChildrenMap       = LevelAggInfo.GetChildrenMap();
            int[]   MapPartitions     = LevelAggInfo.GetCoverAggregationPartitions();
            float[] TotalPayoutState  = TotalCoverState.GetPayout();
            float[] TotalSubjectState = TotalCoverState.GetSubjectLoss();
            int     MapPosition       = 1;
            float   TempSubject       = 0;
            float   ChildR            = 0;
            float   x = 0;

            float[] multiplier = DerivedInfo.GetMixFunctionMultiplier();
            //float[] factors = LevelAggInfo.GetFactor();
            int[] factorsIndex = LevelAggInfo.GetFactorIndex();
            int   counter      = factorsIndex.Count();

            float[] factors = new float[counter];
            for (int i = 0; i < counter; i++)
            {
                int uniqueIndex = factorsIndex[i];
                if (uniqueIndex == -1)
                {
                    factors[i] = 1;
                }
                else
                {
                    factors[i] = FactorVector[uniqueIndex];
                }
            }
            FactorPattern factorPattern = LevelAggInfo.GetLevelFactorPattern();

            if (factorPattern == FactorPattern.AllOnes || factorPattern == FactorPattern.Constant)
            {
                for (int i = 0; i < MapPartitions.Length; i++)
                {
                    TempSubject = TotalPayoutState[ChildrenMap[0]];
                    x           = multiplier[i];

                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        ChildR      = TotalPayoutState[ChildrenMap[j]];
                        TempSubject = (TempSubject + ChildR) - x * Math.Abs(TempSubject - ChildR) - Math.Abs(x) * (TempSubject + ChildR);
                    }
                    TotalSubjectState[ParentPosition] = TempSubject * factors[MapPosition];
                    MapPosition += MapPartitions[i];
                    ParentPosition++;
                }
            }
            else
            {
                for (int i = 0; i < MapPartitions.Length; i++)
                {
                    TempSubject = TotalPayoutState[ChildrenMap[0]] * factors[0];
                    x           = multiplier[i];

                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        ChildR      = TotalPayoutState[ChildrenMap[j]] * factors[j];
                        TempSubject = (TempSubject + ChildR) - x * Math.Abs(TempSubject - ChildR) - Math.Abs(x) * (TempSubject + ChildR);
                    }
                    TotalSubjectState[ParentPosition] = TempSubject;
                    MapPosition += MapPartitions[i];
                    ParentPosition++;
                }
            }
        }
        private void AggregateMaxSubject(int ParentPosition, ICoverState TotalCoverState, ICoverLevelNodeAggInfo LevelAggInfo, float[] coverRatio, float[] FactorVector)
        {
            int[]   ChildrenMap       = LevelAggInfo.GetChildrenMap();
            int[]   MapPartitions     = LevelAggInfo.GetCoverAggregationPartitions();
            float[] TotalPayoutState  = TotalCoverState.GetPayout();
            float[] TotalSubjectState = TotalCoverState.GetSubjectLoss();
            //float[] factors = LevelAggInfo.GetFactor();
            int[] factorsIndex = LevelAggInfo.GetFactorIndex();
            int   counter      = factorsIndex.Count();

            float[] factors = new float[counter];
            for (int i = 0; i < counter; i++)
            {
                int uniqueIndex = factorsIndex[i];
                if (uniqueIndex == -1)
                {
                    factors[i] = 1;
                }
                else
                {
                    factors[i] = FactorVector[uniqueIndex];
                }
            }
            FactorPattern factorPattern = LevelAggInfo.GetLevelFactorPattern();

            int   MapPosition = 1;
            float MaxSubject  = 0;
            int   numOfMax    = 0;

            if (factorPattern == FactorPattern.AllOnes || factorPattern == FactorPattern.Constant)
            {
                for (int i = 0; i < MapPartitions.Length; i++) //for each parent
                {
                    //MaxSubject = TotalPayoutState[ChildrenMap[0]];
                    //MaxSubject = 0;
                    MaxSubject = TotalPayoutState[ChildrenMap[MapPosition - 1]] * factors[MapPosition - 1];
                    numOfMax   = 0;

                    for (int j = MapPosition + 1; j <= MapPartitions[i]; j++)
                    {
                        float temp = TotalPayoutState[ChildrenMap[j - 1]] * factors[j - 1];
                        MaxSubject = Math.Max(MaxSubject, temp);
                    }

                    //ratio
                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        if (MaxSubject == TotalPayoutState[ChildrenMap[j]] * factors[j])
                        {
                            coverRatio[j - 1] = 1;
                            numOfMax++;
                        }
                    }

                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        coverRatio[j - 1] /= numOfMax;
                    }

                    TotalSubjectState[ParentPosition] = MaxSubject * factors[MapPosition];
                    //MapPosition += MapPartitions[i];
                    MapPosition = MapPartitions[i] + 1;
                    ParentPosition++;
                }
            }
            else
            {
                for (int i = 0; i < MapPartitions.Length; i++) //for each parent
                {
                    MaxSubject = TotalPayoutState[ChildrenMap[MapPosition - 1]] * factors[MapPosition - 1];
                    numOfMax   = 0;

                    for (int j = MapPosition + 1; j <= MapPartitions[i]; j++)
                    {
                        float temp = TotalPayoutState[ChildrenMap[j - 1]] * factors[j - 1];
                        MaxSubject = Math.Max(MaxSubject, temp);
                    }

                    //ratio
                    for (int j = MapPosition; j <= MapPartitions[i]; j++)
                    {
                        if (MaxSubject == TotalPayoutState[ChildrenMap[j - 1]] * factors[j - 1])
                        {
                            coverRatio[j - 1] = 1;
                            numOfMax++;
                        }
                    }

                    for (int j = MapPosition; j <= MapPartitions[i]; j++)
                    {
                        coverRatio[j - 1] /= numOfMax;
                    }

                    TotalSubjectState[ParentPosition] = MaxSubject;
                    //MapPosition += MapPartitions[i];
                    MapPosition = MapPartitions[i] + 1;
                    ParentPosition++;
                }
            }
        }
Ejemplo n.º 3
0
        public float ApplyTopCoverLayer(ICoverLevelFinancialInfo FinancialInfo, int TotalStatePosition, ICoverState TotalCoverState, int[] LeafTopCoverList, float[] FactorVector)
        {
            float[]      Attachment   = FinancialInfo.GetCodedAttachment();
            float[]      Limit        = FinancialInfo.GetCodedLimit();
            float[]      Share        = FinancialInfo.GetCodedShare();
            float[]      SubjectLoss  = TotalCoverState.GetSubjectLoss();
            float[]      Payout       = TotalCoverState.GetPayout();
            float        TotalPayout  = 0;
            FunctionType functionType = FinancialInfo.PayoutFunctionType;

            //float[] Factors = FinancialInfo.GetFactor();
            int[] factorsIndex = FinancialInfo.GetFactorIndex();
            int   counter      = factorsIndex.Count();

            float[] factors = new float[counter];
            for (int i = 0; i < counter; i++)
            {
                int uniqueIndex = factorsIndex[i];
                if (uniqueIndex == -1)
                {
                    factors[i] = 1;
                }
                else
                {
                    factors[i] = FactorVector[uniqueIndex];
                }
            }

            int EndPosition = Share.Count();

            if (functionType == FunctionType.Constant)
            {
                float[] Multiplier = FinancialInfo.GetPayoutMultiplier();
                float   E          = 0;
                for (int i = 0; i < EndPosition; i++)
                {
                    E = SubjectLoss[TotalStatePosition] - Attachment[i];
                    Payout[TotalStatePosition] = Limit[i] / 2 * (E / Math.Abs(E) + 1);
                    TotalPayout += Payout[TotalStatePosition] * factors[i];
                    TotalStatePosition++;
                }
            }
            else if (functionType == FunctionType.Regular)
            {
                for (int i = 0; i < EndPosition; i++)
                {
                    Payout[TotalStatePosition] = Share[i] * Math.Min(Limit[i], Math.Max(0, SubjectLoss[TotalStatePosition] - Attachment[i]));
                    TotalPayout += Payout[TotalStatePosition] * factors[i];
                    TotalStatePosition++;
                }
            }
            else if (functionType == FunctionType.Min)
            {
                for (int i = 0; i < EndPosition; i++)
                {
                    Payout[TotalStatePosition] = Share[i] * Math.Min(Limit[i], Math.Max(0, SubjectLoss[TotalStatePosition]));
                    TotalPayout += Payout[TotalStatePosition] * factors[i];
                    TotalStatePosition++;
                }
            }
            else
            {
                float[] F = FinancialInfo.GetPayoutMultiplier();
                float   E = 0;
                for (int i = 0; i < EndPosition; i++)
                {
                    E = SubjectLoss[TotalStatePosition] - Attachment[i];

                    if (E <= 0)
                    {
                        Payout[TotalStatePosition] = 0;
                    }
                    else
                    {
                        Payout[TotalStatePosition] = (16 * F[i] * F[i] - 14 * F[i] - 1) * ((F[i] - 1) * F[i] * Limit[i] + (2 * F[i] - 1) * Math.Min((SubjectLoss[TotalStatePosition] - Attachment[i] * F[i]), Limit[i])) * (Math.Max(0, E) / Math.Abs(E));
                    }
                    TotalPayout += Payout[TotalStatePosition] * factors[i];
                    //Payout[TotalStatePosition] = Multiplier[i] * Share[i] * Math.Min(Limit[i], Math.Max(0, E)) + (1 - Multiplier[i]) * Limit[i] / 2 * (E / Math.Abs(E) + 1);

                    //if (E <= 0)
                    //{
                    //    Payout[i] = Multiplier[i] * Share[i] * Math.Min(Limit[i], Math.Max(0, E));
                    //    TotalPayout += Payout[TotalStatePosition];
                    //}
                    //else
                    //{
                    //    Payout[i] = Multiplier[i] * Share[i] * Math.Min(Limit[i], E) + (1 - Multiplier[i]) * Limit[i];
                    //    TotalPayout += Payout[TotalStatePosition];
                    //}

                    TotalStatePosition++;
                }
            }

            int NumOfLeafTop = LeafTopCoverList.Count();

            if (NumOfLeafTop > 0)
            {
                for (int i = 0; i < NumOfLeafTop; i++)
                {
                    TotalPayout += Payout[i] * factors[i];
                }
            }
            return(TotalPayout);
        }
        private void AggregateSumSubject(int ParentPosition, ICoverState TotalCoverState, ICoverLevelNodeAggInfo LevelAggInfo, float[] coverRatio, float[] FactorVector)
        {
            int[]   ChildrenMap       = LevelAggInfo.GetChildrenMap();
            int[]   MapPartitions     = LevelAggInfo.GetCoverAggregationPartitions();
            float[] TotalPayoutState  = TotalCoverState.GetPayout();
            float[] TotalSubjectState = TotalCoverState.GetSubjectLoss();
            int     MapPosition       = 0;

            int[] factorsIndex = LevelAggInfo.GetFactorIndex();
            int   counter      = factorsIndex.Count();

            float[] factors = new float[counter];
            for (int i = 0; i < counter; i++)
            {
                int uniqueIndex = factorsIndex[i];
                if (uniqueIndex == -1)
                {
                    factors[i] = 1;
                }
                else
                {
                    factors[i] = FactorVector[uniqueIndex];
                }
            }

            FactorPattern factorPattern = LevelAggInfo.GetLevelFactorPattern();

            if (factorPattern == FactorPattern.AllOnes || factorPattern == FactorPattern.Constant)
            {
                for (int i = 0; i < MapPartitions.Length; i++)
                {
                    float ParentSubject = 0;
                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        ParentSubject += TotalPayoutState[ChildrenMap[j]] * factors[j];  //denominator
                    }

                    //ratio
                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        coverRatio[j] = (ParentSubject == 0) ? 0 : TotalPayoutState[ChildrenMap[j]] * factors[j] / ParentSubject;
                    }

                    TotalSubjectState[ParentPosition] = ParentSubject;
                    MapPosition = MapPartitions[i] + 1;
                    ParentPosition++;
                }
            }
            else
            {
                for (int i = 0; i < MapPartitions.Length; i++)
                {
                    float ParentSubject = 0;
                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        ParentSubject += TotalPayoutState[ChildrenMap[j]] * factors[j];  //denominator
                    }

                    //ratio
                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        coverRatio[j] = (ParentSubject == 0) ? 0 : TotalPayoutState[ChildrenMap[j]] * factors[j] / ParentSubject;
                    }

                    TotalSubjectState[ParentPosition] = ParentSubject;
                    MapPosition = MapPartitions[i] + 1;
                    ParentPosition++;
                }
            }
        }
Ejemplo n.º 5
0
        public void ApplyCoverLayer(ICoverLevelFinancialInfo FinancialInfo, int TotalStatePosition, ICoverState TotalCoverState)
        {
            float[]      Attachment   = FinancialInfo.GetCodedAttachment();
            float[]      Limit        = FinancialInfo.GetCodedLimit();
            float[]      Share        = FinancialInfo.GetCodedShare();
            float[]      SubjectLoss  = TotalCoverState.GetSubjectLoss();
            float[]      Payout       = TotalCoverState.GetPayout();
            FunctionType functionType = FinancialInfo.PayoutFunctionType;

            int EndPosition = Share.Count();

            if (functionType == FunctionType.Constant)
            {
                float E = 0;

                for (int i = 0; i < EndPosition; i++)
                {
                    E = SubjectLoss[TotalStatePosition] - Attachment[i];
                    Payout[TotalStatePosition] = Share[i] * Limit[i] / 2 * (E / Math.Abs(E) + 1);
                    TotalStatePosition++;
                }
            }
            else if (functionType == FunctionType.Regular)
            {
                for (int i = 0; i < EndPosition; i++)
                {
                    Payout[TotalStatePosition] = Share[i] * Math.Min(Limit[i], Math.Max(0, SubjectLoss[TotalStatePosition] - Attachment[i]));
                    TotalStatePosition++;
                }
            }
            else if (functionType == FunctionType.Min)
            {
                for (int i = 0; i < EndPosition; i++)
                {
                    Payout[TotalStatePosition] = Share[i] * Math.Min(Limit[i], Math.Max(0, SubjectLoss[TotalStatePosition]));
                    TotalStatePosition++;
                }
            }
            else
            {
                float[] F = FinancialInfo.GetPayoutMultiplier();
                float   E = 0;
                for (int i = 0; i < EndPosition; i++)
                {
                    E = SubjectLoss[TotalStatePosition] - Attachment[i];
                    if (E <= 0)
                    {
                        Payout[TotalStatePosition] = 0;
                    }
                    else
                    {
                        Payout[TotalStatePosition] = Share[i] * (16 * F[i] * F[i] - 14 * F[i] - 1) * ((F[i] - 1) * F[i] * Limit[i] + (2 * F[i] - 1) * Math.Min((SubjectLoss[TotalStatePosition] - Attachment[i] * F[i]), Limit[i])) * (Math.Max(0, E) / Math.Abs(E));
                    }
                    TotalStatePosition++;
                }
                //float E = 0;
                //for (int i = 0; i < EndPosition; i++)
                //{
                //    E = SubjectLoss[TotalStatePosition] - Attachment[i];
                //    //Payout[TotalStatePosition] = Multiplier[i] * Share[i] * Math.Min(Limit[i], Math.Max(0, E)) + (1 - Multiplier[i]) * Limit[i] / 2 * (E / Math.Abs(E) + 1);
                //    if (E <= 0)
                //    {
                //        Payout[TotalStatePosition] = Multiplier[i] * Share[i] * Math.Min(Limit[i], Math.Max(0, E));
                //    }
                //    else
                //        Payout[TotalStatePosition] = Multiplier[i] * Share[i] * Math.Min(Limit[i], E) + (1 - Multiplier[i]) * Limit[i] / 2 * (E / Math.Abs(E) + 1);
                //    TotalStatePosition++;
                //}
            }
        }