コード例 #1
0
        private ScheduleOfRITEs BuildScheduleFromRITChars(string name, HashSet <long> EDSschedule)
        {
            ScheduleOfRITEs newSchedule = new ScheduleOfRITEs(name);

            foreach (long RITCharID in EDSschedule)
            {
                long RITEID = EDSDataExtract.CoverageIdAttrMap[RITCharID].RITExposureId;

                RITCharacteristic characteristicToAdd = _characteristics.Where(ritchar => ritchar.ID == RITCharID).FirstOrDefault();
                RITE ritetoAdd = _rites.Where(rite => rite.ExposureID == RITEID).FirstOrDefault();

                if (characteristicToAdd != null)
                {
                    newSchedule.AddCharacteristic(characteristicToAdd);
                }
                else
                {
                    throw new IndexOutOfRangeException("Error building schedule with RITCharacteristics: Cannot find RITCharacteristic with id = " + RITCharID + " in Exposure Data");
                }

                if (ritetoAdd != null)
                {
                    newSchedule.AddItem(ritetoAdd);
                }
                else
                {
                    throw new IndexOutOfRangeException("Error building schedule with RITEs: Cannot find RITE with id = " + RITEID + " in Exposure Data");
                }
            }

            return(newSchedule);
        }
コード例 #2
0
        public void AddCharacteristic(long _ID, ExposureType _expType, double _tiv)
        {
            RITCharacteristic Char = new RITCharacteristic(_ID, _expType, _tiv);

            RiskCharacteristics.Add(Char);
            Char.ParentRITE = this;
        }
コード例 #3
0
        public List <AtomicLoss> GetAllocatedLossList(float[] AllocatedLossVector, int[] GULossIndicies, uint[] TimeStamps, Declarations contractDeclarations)
        {
            List <AtomicLoss> AllocatedLosses = new List <AtomicLoss>();
            int NumOfArites = AllocatedLossVector.Length;

            for (int i = 0; i < NumOfArites; i++)
            {
                if (AllocatedLossVector[i] > 0)
                {
                    AtomicLoss loss = new AtomicLoss();
                    loss.ExposureID = Mapper.GetRITEIDFromIndex(GULossIndicies[i]);
                    loss.Subperil   = Mapper.GetSubPerilFromIndex(GULossIndicies[i]);
                    loss.Loss       = AllocatedLossVector[i];
                    RITCharacteristic RitChar = Mapper.GetRITCharObject(loss.ExposureID);
                    loss.RITE    = RitChar.ParentRITE;
                    loss.ExpType = RitChar.ExpType;

                    //Get TimeStamp using Mapper:
                    int      ContractYear    = contractDeclarations.Inception.Year;
                    uint     timestamp       = TimeStamps[GULossIndicies[i]];
                    DateTime ActualTimeStamp = new DateTime(ContractYear, 1, 1);
                    ActualTimeStamp = ActualTimeStamp.AddDays((double)timestamp - 1);
                    loss.timestamp  = ActualTimeStamp;
                    AllocatedLosses.Add(loss);
                }
            }

            return(AllocatedLosses);
        }
コード例 #4
0
        //public double[] GetGUForNode(GraphNode node)
        //{
        //    PrimarySubject sub = (PrimarySubject)node.Subject;
        //    int numBldgs = sub.Schedule.ActNumOfBldgs;
        //    double[] subjectloss = new double[numBldgs];
        //    List<RITCharacteristic> LeftoverRiteChars = sub.Schedule.RITChars.ToList();

        //    foreach (GraphNode childnode in graph.GetChildrenForNode(node))
        //    {
        //        double[] nodeLosses = GetGUForNode(childnode);

        //        if (childnode is TermNode)
        //        {
        //            TermNode termNode = childnode as TermNode;
        //            if (numBldgs == 1)
        //            {
        //                subjectloss[0] += nodeLosses.Sum();
        //            }
        //            else if (numBldgs == nodeLosses.Count())
        //            {
        //                subjectloss.Zip(nodeLosses, (a, b) => a + b);
        //            }
        //        }
        //        else
        //        {
        //            CoverNode covNode = childnode as CoverNode;
        //            subjectloss[0] += covNode.Payout;
        //        }

        //        LeftoverRiteChars = LeftoverRiteChars.Except(childnode.Subject.Schedule.RITChars).ToList();
        //    }

        //    foreach (RITCharacteristic RITChar in LeftoverRiteChars)
        //    {
        //        foreach (string subperil in sub.CauseOfLossSet.GetSubperils())
        //        {
        //            if (sub.ExposureTypes.Contains(RITChar.ExpType))
        //            {
        //                double[] RITELoss;
        //                uint timestamp;
        //                string error;
        //                if (GetRITCharacteristicLoss(RITChar, subperil, out RITELoss, out timestamp, out error, numBldgs))
        //                    subjectloss = subjectloss.Zip(RITELoss, (x, y) => x + y).ToArray();
        //                else
        //                    throw new GUInputEngineException(error);
        //            }
        //        }
        //    }

        //    return subjectloss;
        //}

        private bool GetRITCharacteristicLoss(RITCharacteristic RITChar, string subperil, out double[] loss, out uint timestamp, out string error, int numBldgs)
        {
            bool success = true;

            error = "";
            long   CharId      = RITChar.ID;
            double BuildingTIV = RITChar.TIV / RITChar.ParentRITE.NumOfTrueBldgs;

            loss      = new double[1];
            loss[0]   = 0;
            timestamp = 0;

            Dictionary <int, Dictionary <long, Tuple <double, uint, List <float> > > > AfterCOL;

            if (GULosses.TryGetValue(subperil, out AfterCOL))
            {
                Dictionary <long, Tuple <double, uint, List <float> > > AfterSample;
                if (AfterCOL.TryGetValue(0, out AfterSample))
                {
                    Tuple <double, uint, List <float> > DamageRatio;
                    if (AfterSample.TryGetValue(CharId, out DamageRatio))
                    {
                        timestamp = DamageRatio.Item2;

                        if (DamageRatio.Item3.Count == numBldgs)
                        {
                            double[] multiplyArr = RITE.GenerateMultiplierArr(RITChar.ParentRITE.NumOfSampleBldgs);
                            loss = DamageRatio.Item3.Zip(multiplyArr, (d1, d2) => (double)d1 * d2).ToArray();
                            //loss = Array.ConvertAll(DamageRatio.Item2.ToArray(), x => (double)x);
                            success = true;
                        }
                        else if (numBldgs == 1)
                        {
                            double[] multiplyArr = RITE.GenerateMultiplierArr(RITChar.ParentRITE.NumOfSampleBldgs);
                            loss[0] = DamageRatio.Item3.Zip(multiplyArr, (d1, d2) => d1 * d2).Sum();
                            //loss[0] = DamageRatio.Item2.ToArray().Sum();
                            success = true;
                        }
                        else
                        {
                            success = false;
                            error   = "Error getting GU for RITE ID: " + RITChar.ID + ". GU losses specified not matching for NumBldgs...";
                        }
                    }
                    else
                    {
                        success = false;
                        error   = "Error getting GU for RITE ID: " + RITChar.ID + ". Cannot find RITE ID in GU Input Loss dictionary";
                    }
                }
                else
                {
                    success = false;
                    error   = "Error getting GU for RITE ID: " + RITChar.ID + ". Cannot find Sample 0 in GU Input Loss dictionary, currenlty hard-coded to take sample id = 0";
                }
            }

            return(success);
        }
コード例 #5
0
        public Dictionary <long, int> BuildNumOfSampleDictionary(RITCharacteristic AggRITChar, HashSet <long> DisAggRITCharIDs, int eventID, int TotalNumSamples)
        {
            Dictionary <long, int> NumSamples = new Dictionary <long, int>();

            //Order RITCharIds
            List <long> OrderedDisAggRITCharIDs = DisAggRITCharIDs.OrderBy(id => expData.DisaggRitCharToDisAggRIT[id]).ToList();
            //List<long> OrderedDisAggRITIDs = DisAggRITCharIDs.Select(id => expData.DisaggRitCharToDisAggRIT[id]).OrderBy(id => id).ToList();
            int NumPartitions = DisAggRITCharIDs.Count - 1;

            Dictionary <long, int> SamplePartitions = new Dictionary <long, int>();

            int[] samples = new int[NumPartitions];

            long AggLocID = AggRITChar.ParentRITE.ExposureID;
            int  currSeed = ((int)AggLocID * eventID) % Int32.MaxValue;
            var  RandGen  = new Random(currSeed);

            for (int i = 0; i < NumPartitions; i++)
            {
                samples[i] = RandGen.Next(TotalNumSamples + 1);
            }

            samples = samples.OrderBy(sample => sample).ToArray();

            for (int i = 0; i < NumPartitions; i++)
            {
                long DisAggRITCharID = OrderedDisAggRITCharIDs[i];

                SamplePartitions.Add(DisAggRITCharID, samples[i]);
            }

            long LastDisAggRITCharID = OrderedDisAggRITCharIDs[NumPartitions];

            SamplePartitions.Add(LastDisAggRITCharID, TotalNumSamples);

            int lastPartition = 0;

            foreach (long DisAggRITCharID in OrderedDisAggRITCharIDs)
            {
                int CurrentPartition    = SamplePartitions[DisAggRITCharID];
                int CurrentNumOfSamples = CurrentPartition - lastPartition;

                NumSamples.Add(DisAggRITCharID, CurrentNumOfSamples);
                lastPartition = CurrentPartition;
            }

            int DebugToatlNumSamples = NumSamples.Select(pair => pair.Value).Sum();


            return(NumSamples);
        }
コード例 #6
0
        public void GetGUForCoverageRITE(CoverageAtomicRITE aRITE)
        {
            double[]          GULossArray;
            uint              timestamp;
            string            error;
            RITCharacteristic RIT = aRITE.RITE.RiskCharacteristics.Where(RITChar => RITChar.ID == aRITE.RITCharacterisiticID).FirstOrDefault();

            if (GetRITCharacteristicLoss(RIT, aRITE.SubPeril, out GULossArray, out timestamp, out error, aRITE.RITE.ActNumOfBldgs))
            {
                aRITE.SetSubjectLoss(new LossTimeSeries(timestamp, GULossArray));
            }
            else
            {
                throw new GUInputEngineException(error);
            }
        }
コード例 #7
0
        public void GetGUForCoverageRITE(CoverageAtomicRITE aRITE)
        {
            double[] GULossArray;
            uint     timestamp;
            string   error;

            RITCharacteristic RIT = aRITE.RITE.RiskCharacteristics.Where(RITChar => RITChar.ID == aRITE.RITCharacterisiticID).FirstOrDefault();

            if (GetRITCharacteristicLoss(RIT, aRITE.SubPeril, out GULossArray, out timestamp, out error, aRITE.RITE.ActNumOfSampleBldgs))
            {
                DateTime ActualTimeStamp = new DateTime(ContractYear, 1, 1);
                ActualTimeStamp = ActualTimeStamp.AddDays((double)timestamp - 1);
                aRITE.SetSubjectLoss(new LossTimeSeries(ActualTimeStamp, GULossArray));
            }
            else
            {
                throw new GUInputEngineException(error);
            }
        }
コード例 #8
0
 public void AddCharacteristic(RITCharacteristic Char)
 {
     RiskCharacteristics.Add(Char);
     Char.ParentRITE = this;
 }
コード例 #9
0
        public void GetPrimaryData()
        {
            if (TreatyExposure)
            {
                throw new InvalidOperationException("Cannot use this method to get exposure data for reinsurance contract");
            }

            EDSDataExtract.ExtractRiteMap();

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            var LocationGroups = EDSDataExtract.CoverageIdAttrMap.GroupBy(pair => pair.Value.RITExposureId);

            foreach (var LocGroup in LocationGroups)
            {
                RITE newRITE = BuildRITE(LocGroup.First());
                _rites.Add(newRITE);
                _ritesDict.Add(LocGroup.Key, newRITE);

                foreach (KeyValuePair <long, RiskItemCharacteristicIDAttributes> pair in LocGroup)
                {
                    RITCharacteristic newRITChar = BuildRITCharacteristic(pair);
                    _characteristics.Add(newRITChar);
                    _characteristicsDict.Add(pair.Key, newRITChar);
                    newRITE.AddCharacteristic(newRITChar);
                }
            }


            foreach (KeyValuePair <string, Subschedule> EDSschedule in EDSDataExtract.SubSchedule)
            {
                ScheduleOfRITEs newSchedule;
                HashSet <long>  Ids = (EDSschedule.Value.Ids != null) ? EDSschedule.Value.Ids : new HashSet <long>(EDSschedule.Value.CompressedIds.Enumerable());
                if (EDSschedule.Value.Type == SubscheduleType.RITCHARACTERISTICS)
                {
                    newSchedule = BuildScheduleFromRITChars2(EDSschedule.Key, Ids);
                }
                else if (EDSschedule.Value.Type == SubscheduleType.RITEXPOSURES)
                {
                    newSchedule = BuildScheduleFromRITs2(EDSschedule.Key, Ids);
                }
                else
                {
                    throw new InvalidOperationException("Cannot support building schedules of type: " + EDSschedule.Value.Type.ToString());
                }

                _schedules.Add(newSchedule);
                _schedulesDict.Add(newSchedule.Name, newSchedule);
            }

            stopwatch.Stop();

            ////////////////////////OLD OLD OLD Version//////////////////////////////////
            //_schedules.Clear();
            //_rites.Clear();
            //_characteristics.Clear();

            //stopwatch.Reset();
            //stopwatch.Start();

            //foreach (KeyValuePair<long, RiskItemCharacteristicIDAttributes> RiteAttribute in EDSDataExtract.RiskItemCharacteristicIDAttributeMap)
            //{
            //    RITCharacteristic newRITChar = BuildRITCharacteristic(RiteAttribute);
            //    _characteristics.Add(newRITChar);
            //    RITE parentRITE = _rites.Where(rite => rite.ExposureID == RiteAttribute.Value.RITExposureId).FirstOrDefault();

            //    if (parentRITE != null)
            //    {
            //        parentRITE.AddCharacteristic(newRITChar);
            //    }
            //    else
            //    {
            //        RITE newRITE = BuildRITE(RiteAttribute);
            //        _rites.Add(newRITE);
            //        newRITE.AddCharacteristic(newRITChar);
            //    }

            //}

            //foreach (KeyValuePair<string, Subschedule> EDSschedule in EDSDataExtract.SubSchedule)
            //{
            //    ScheduleOfRITEs newSchedule;
            //    HashSet<long> Ids = (EDSschedule.Value.Ids != null) ? EDSschedule.Value.Ids : new HashSet<long>(EDSschedule.Value.CompressedIds.Enumerable());
            //    if (EDSschedule.Value.Type == SubscheduleType.RITCHARACTERISTICS)
            //        newSchedule = BuildScheduleFromRITChars(EDSschedule.Key, Ids);
            //    else if (EDSschedule.Value.Type == SubscheduleType.RITEXPOSURES)
            //        newSchedule = BuildScheduleFromRITs(EDSschedule.Key, Ids);
            //    else
            //        throw new InvalidOperationException("Cannot support building schedules of type: " + EDSschedule.Value.Type.ToString());

            //    _schedules.Add(newSchedule);
            //}

            //stopwatch.Stop();
        }
コード例 #10
0
 public void AddCharacteristic(RITCharacteristic Item)
 {
     RITChars.Add(Item);
 }
コード例 #11
0
        //public ExposureDataAdaptor(ContractExposure contractExposure, NGFMPrototype _ParsingAPI)
        //{
        //    //ParsingAPI = _ParsingAPI;
        //    UseJSContext = false;
        //    _contractExposure = contractExposure;

        //    _contractJSON = GetJSONForContract();
        //    EDSDataExtract = new ExposureDataExtractor(_contractExposure);

        //    _characteristics = new HashSet<RITCharacteristic>();
        //    _rites = new HashSet<RITE>();
        //    _schedules = new HashSet<ScheduleOfRITEs>();
        //    _characteristicsDict = new Dictionary<long, RITCharacteristic>();
        //    _ritesDict = new Dictionary<long, RITE>();
        //    _schedulesDict = new Dictionary<string, ScheduleOfRITEs>();

        //    if (_contractExposure.ContractType.IsReinsuranceContract())
        //        TreatyExposure = true;
        //    else
        //        TreatyExposure = false;
        //}

        public void GetPrimaryData()
        {
            if (TreatyExposure)
            {
                throw new InvalidOperationException("Cannot use this method to get exposure data for reinsurance contract");
            }

            EDSDataExtract.ExtractRiteMap();

            Dictionary <long, ExtractRITCharInfo> CoverageIdAttrMap = EDSDataExtract.CoverageIdAttrMap;

            if (UseAggregatedRITEs)
            {
                CoverageIdAttrMap = AggregateRITChars(CoverageIdAttrMap);
            }
            else
            {
                foreach (KeyValuePair <long, ExtractRITCharInfo> pair in CoverageIdAttrMap)
                {
                    RiskCharIDtoAggregateID.Add(pair.Key, pair.Key);
                    AggregateIDtoDisaggIDs.Add(pair.Key, new HashSet <long> {
                        pair.Key
                    });
                }
            }

            #region old RITE aggreagation code


            //foreach (var LocGroup in LocationGroups)
            //{
            //    if (UseAggregatedRITEs)
            //    {
            //        long RiteID = LocGroup.First().Value.RITExposureId;
            //        long OriginalRiteID = (long)LocGroup.First().Value.OriginalRITExposureId;

            //        if (RiteID == OriginalRiteID)
            //        {
            //            RITE newRITE = BuildRITE(LocGroup.First());
            //            _rites.Add(newRITE);
            //            _ritesDict.Add(LocGroup.Key, newRITE);

            //            foreach (KeyValuePair<long, ExtractRITCharInfo> pair in LocGroup)
            //            {
            //                RITCharacteristic newRITChar = BuildRITCharacteristic(pair);
            //                _characteristics.Add(newRITChar);
            //                _characteristicsDict.Add(pair.Key, newRITChar);
            //                newRITE.AddCharacteristic(newRITChar);
            //            }
            //        }
            //        else
            //        {
            //            foreach (KeyValuePair<long, ExtractRITCharInfo> pair in LocGroup)
            //            {
            //                RiskCharIDtoAggregateID.Add(pair.Key, (long)pair.Value.OriginalRITECharacteristicId);
            //            }
            //        }
            //    }
            //    else
            //    {
            //        RITE newRITE = BuildRITE(LocGroup.First());
            //        _rites.Add(newRITE);
            //        _ritesDict.Add(LocGroup.Key, newRITE);

            //        foreach (KeyValuePair<long, ExtractRITCharInfo> pair in LocGroup)
            //        {
            //            RITCharacteristic newRITChar = BuildRITCharacteristic(pair);
            //            _characteristics.Add(newRITChar);
            //            _characteristicsDict.Add(pair.Key, newRITChar);
            //            newRITE.AddCharacteristic(newRITChar);
            //        }
            //    }
            //}

            #endregion

            var LocationGroups = CoverageIdAttrMap.GroupBy(pair => pair.Value.RITExposureId);

            foreach (var LocGroup in LocationGroups)
            {
                RITE newRITE = BuildRITE(LocGroup.First());
                _rites.Add(newRITE);
                _ritesDict.Add(LocGroup.Key, newRITE);

                foreach (KeyValuePair <long, ExtractRITCharInfo> pair in LocGroup)
                {
                    RITCharacteristic newRITChar = BuildRITCharacteristic(pair);
                    _characteristics.Add(newRITChar);
                    _characteristicsDict.Add(pair.Key, newRITChar);
                    newRITE.AddCharacteristic(newRITChar);
                }
            }


            foreach (KeyValuePair <string, Subschedule> EDSschedule in EDSDataExtract.SubSchedule)
            {
                ScheduleOfRITEs newSchedule;
                HashSet <long>  Ids = (EDSschedule.Value.Ids != null) ? EDSschedule.Value.Ids : new HashSet <long>(EDSschedule.Value.CompressedIds.Enumerable());

                if (EDSschedule.Value.Type == SubscheduleType.RITCHARACTERISTICS) //|| EDSschedule.Value.Name == "Blanket_FL" || EDSschedule.Value.Name == "Blanket_EQ" || EDSschedule.Value.Name == "Blanket_WS")    //Sunny Hack
                {
                    newSchedule = BuildScheduleFromRITChars2(EDSschedule.Key, Ids);
                }
                else if (EDSschedule.Value.Type == SubscheduleType.RITEXPOSURES)
                {
                    try { newSchedule = BuildScheduleFromRITs2(EDSschedule.Key, Ids); }
                    catch (IndexOutOfRangeException exp)
                    {
                        newSchedule = BuildScheduleFromRITChars2(EDSschedule.Key, Ids);
                    }
                }
                else
                {
                    throw new InvalidOperationException("Cannot support building schedules of type: " + EDSschedule.Value.Type.ToString());
                }

                _schedules.Add(newSchedule);
                _schedulesDict.Add(newSchedule.Name, newSchedule);
            }
        }