Exemplo n.º 1
0
        //public List<TimeWindow> Generate(int WindowSize, Dictionary<string, Dictionary<int, Dictionary<long, Tuple<double, uint, List<float>>>>> DictionaryLosses)
        //{
        //    //get the unique list of dates from the rites
        //    List<int> lst_dates = new List<int>();
        //    foreach (KeyValuePair<string, Dictionary<int, Dictionary<long, Tuple<double, uint, List<float>>>>> l1 in DictionaryLosses)
        //    {
        //        foreach (KeyValuePair<int, Dictionary<long, Tuple<double, uint, List<float>>>> l2 in l1.Value)
        //        {
        //            foreach (KeyValuePair<long, Tuple<double, uint, List<float>>> l3 in l2.Value)
        //            {
        //                if (!lst_dates.Contains((int)l3.Value.Item2))
        //                    lst_dates.Add((int)l3.Value.Item2);
        //            }
        //        }
        //    }
        //    ArrayList arr_dates = new ArrayList(lst_dates);
        //    arr_dates.Sort();
        //    return GenerateWindows(arr_dates, WindowSize);
        //}

        ////assuming dateslist is a sorted list of dates in integer format
        //private List<TimeWindow> GenerateWindows(ArrayList DatesList, int WindowSize)
        //{
        //    double interval = WindowSize + 0.5;
        //    int count = DatesList.Count;
        //    List<TimeWindow> lst_timeWindows = new List<TimeWindow>();

        //    for (int i = 0; i < count; i++)
        //    {
        //        double current = Convert.ToDouble(DatesList[i]);
        //        double lowerlim = Convert.ToDouble(DatesList[i]) - interval;
        //        double upperlim = Convert.ToDouble(DatesList[i]) + interval;
        //        double datediff = 0;

        //        if (i < count - 1)
        //        {
        //            datediff = Convert.ToDouble(DatesList[i + 1]) - Convert.ToDouble(DatesList[i]);
        //        }

        //        TimeWindow leftWindow = new TimeWindow();
        //        leftWindow.SetStartandEnd(lowerlim, current);
        //        lst_timeWindows.Add(leftWindow);
        //        Console.WriteLine("Left Window - (" + leftWindow.start + "," + leftWindow.end + "]");

        //        //to eliminate empty windows and exclude the last window
        //        if (datediff <= interval && i < (count - 1))
        //        {
        //            TimeWindow rightWindow = new TimeWindow();
        //            rightWindow.SetStartandEnd(current, upperlim);
        //            lst_timeWindows.Add(rightWindow);
        //            Console.WriteLine("Right Window - (" + rightWindow.start + "," + rightWindow.end + "]");
        //        }
        //    }
        //    return lst_timeWindows;

        //}

        #endregion

        public List <TimeWindow> Generate(LossTimeSeries SubjectLoss)
        {
            if (_contractDeclarations.IsHoursClause == false || _contractDeclarations.HoursClauses.Count() == 0)
            {
                return new List <TimeWindow> {
                           new TimeWindow()
                }
            }
            ;

            List <TimeWindow> resultWindowList = new List <TimeWindow>();
            //List<int> windowsizeList = _contractDeclarations.HoursClauses.Select(x => x.Duration).ToList();
            int             windowsize = _contractDeclarations.HoursClauses[0].Duration;
            List <DateTime> dateList   = GenerateDateList(SubjectLoss);

            TimeWindow oneWindow = new TimeWindow();

            if (_contractDeclarations.HoursClauses[0].OnlyOnce) //if only one LO
            {
                return(GenerateWindowsOnlyOneLO(dateList, windowsize));
            }
            else
            {
                return(GenerateWindows_3(dateList, windowsize));
            }
        }
Exemplo n.º 2
0
        public LossTimeSeries Clone()
        {
            LossTimeSeries series = new LossTimeSeries(this.NumOfBldgs);

            series.timeseries = this.timeseries;

            return(series);
        }
Exemplo n.º 3
0
        public void MergeTimeSeries(LossTimeSeries otherLoss, Aggregation aggType = Aggregation.Summed)
        {
            if (NumOfBldgs != otherLoss.NumOfBldgs && aggType == Aggregation.PerBuilding)
            {
                throw new InvalidOperationException("Cannot merge time series with losses of different number of buildings");
            }

            foreach (KeyValuePair <DateTime, double[]> timeloss in otherLoss.timeseries)
            {
                this.AddLoss(timeloss.Key, timeloss.Value, aggType);
            }
        }
Exemplo n.º 4
0
        public LossTimeSeries ApplyWindow(TimeWindow window)
        {
            LossTimeSeries series = new LossTimeSeries(this.NumOfBldgs);

            foreach (KeyValuePair <DateTime, double[]> timeloss in this.timeseries)
            {
                if ((timeloss.Key >= window.start && timeloss.Key <= window.end) || window.IsUnrestricted)
                {
                    series.AddLoss(timeloss.Key, timeloss.Value, Aggregation.PerBuilding);
                }
            }

            return(series);
        }
Exemplo n.º 5
0
 public override void SetSubjectLoss(LossTimeSeries _subjectLoss)
 {
     if (OriginalLossSet == false)
     {
         originalSubjectLoss = _subjectLoss;
         OriginalLossSet     = true;
     }
     else
     {
         subjectLoss = _subjectLoss;
         CurrentLossStateCollection.SetSubjectLosses(subjectLoss.AllLoss());
         CurrentLossStateCollection.SetRecoverableLosses(subjectLoss.AllLoss());
     }
 }
Exemplo n.º 6
0
        public void InputLossForGraph(long ID, LossTimeSeries series)
        {
            Graph Contract;

            if (GraphCache.GetContract(ID, out Contract))
            {
                //Contract.PayoutTimeSeries = series;
                Contract.IsExecuted = true;
            }
            else
            {
                throw new InvalidOperationException("Graph for contract: " + ID + " must be built before setting Losses");
            }
        }
Exemplo n.º 7
0
        public List <DateTime> GenerateDateList(LossTimeSeries SubjectLoss)
        {
            //get the unique list of dates from the rites
            List <DateTime> lst_dates = new List <DateTime>();

            foreach (TimeLoss dt in SubjectLoss)
            {
                if (!lst_dates.Contains(dt.Time))
                {
                    lst_dates.Add(dt.Time);
                }
            }
            //ArrayList arr_dates = new ArrayList(lst_dates);
            lst_dates.Sort();
            return(lst_dates);
        }
Exemplo n.º 8
0
        public LossTimeSeries GetPayoutTimeSeries()
        {
            var timeGroups =
                from allocLoss in AllocatedLosses
                group allocLoss by allocLoss.timestamp into g
                select new { Time = g.Key, Payouts = g };

            LossTimeSeries series = new LossTimeSeries(1);

            foreach (var g in timeGroups)
            {
                double totalpayout = g.Payouts.Select(payout => payout.Loss).Sum();
                series.AddLoss(g.Time, totalpayout);
            }

            return(series);
        }
Exemplo n.º 9
0
        public LossTimeSeries GetFilteredTimeSeries(string subperil, ExposureType exType)
        {
            var timeGroups =
                from allocLoss in AllocatedLosses
                group allocLoss by allocLoss.timestamp into g
                select new { Time = g.Key, Payouts = g };

            LossTimeSeries series = new LossTimeSeries(1);

            foreach (var g in timeGroups)
            {
                double totalpayout = g.Payouts.Where(payout => payout.Subperil == subperil && payout.ExpType == exType)
                                     .Select(payout => payout.Loss)
                                     .Sum();
                series.AddLoss(g.Time, totalpayout);
            }

            return(series);
        }
Exemplo n.º 10
0
        //public override void BuildAtomicRITEs()
        //{
        //    _atomicCoverageRITEs = RecursiveGetAtomicRITEs(TopNode);
        //}

        //private HashSet<CoverageAtomicRITE> RecursiveGetAtomicRITEs(GraphNode node)
        //{
        //    if (node.AtomicRITEsAdded == true)
        //        return new HashSet<CoverageAtomicRITE>(node.AllAtomicRITEs.Cast<CoverageAtomicRITE>());

        //    //Get AtomicRites from Children
        //    HashSet<CoverageAtomicRITE> ARITEsFromChildren = new HashSet<CoverageAtomicRITE>();

        //    if (node.Subject.IsDerived)
        //    {
        //        foreach (GraphNode childNode in GetChildrenForNode(node))
        //        {
        //            ARITEsFromChildren.UnionWith(RecursiveGetAtomicRITEs(childNode));
        //        }

        //        node.ResidualAtomicRITEs = new HashSet<AtomicRITE>();
        //        node.AllAtomicRITEs = new HashSet<AtomicRITE>(ARITEsFromChildren.Cast<AtomicRITE>().ToList());
        //        node.AtomicRITEsAdded = true;

        //        return ARITEsFromChildren;
        //    }
        //    else
        //    {
        //        foreach (GraphNode childNode in GetChildrenForNode(node))
        //        {
        //            ARITEsFromChildren.UnionWith(RecursiveGetAtomicRITEs(childNode));
        //        }

        //        //Get Atomic Rites for subject of Node
        //        HashSet<CoverageAtomicRITE> SubjectARITEs = node.Subject.GetAtomicRites();
        //        //var ResidualARITEs = SubjectARITEs.Except(ARITEsFromChildren);
        //        HashSet<CoverageAtomicRITE> ResidualARITEs =  new HashSet<CoverageAtomicRITE>(SubjectARITEs.Except(ARITEsFromChildren));
        //        HashSet<CoverageAtomicRITE> AllARITEs = new HashSet<CoverageAtomicRITE>(ResidualARITEs.Union(ARITEsFromChildren));

        //        node.ResidualAtomicRITEs = new HashSet<AtomicRITE>(ResidualARITEs.Cast<AtomicRITE>());
        //        node.AllAtomicRITEs = new HashSet<AtomicRITE>(AllARITEs.Cast<AtomicRITE>());
        //        node.AtomicRITEsAdded = true;

        //        return AllARITEs;
        //    }
        //}

        public override LossTimeSeries GetNodeSubjectLoss(GraphNode node)
        {
            if (node.SubjectLoss != null)
            {
                return(node.SubjectLoss);
            }

            PrimarySubject priSub      = (PrimarySubject)node.Subject;
            Aggregation    aggType     = priSub.Schedule.IsLocation ? Aggregation.PerBuilding : Aggregation.Summed;
            LossTimeSeries subjectLoss = new LossTimeSeries(priSub.Schedule.ActNumOfBldgs);

            //Recursively gets subject loss for a Node

            foreach (AtomicRITE rite in node.AllAtomicRITEs)
            {
                subjectLoss.MergeTimeSeries(rite.SubjectLoss, aggType);
            }

            return(subjectLoss);
        }
Exemplo n.º 11
0
        } //end of Initialize

        public override LossTimeSeries GetNodeSubjectLoss(GraphNode node)
        {
            if (node.SubjectLoss != null)
            {
                return(node.SubjectLoss);
            }

            LossTimeSeries subjectLoss = new LossTimeSeries(1);

            //Recursively gets subject loss for a Node
            foreach (GraphNode childnode in GetChildrenForNode(node))
            {
                subjectLoss.MergeTimeSeries(GetNodeSubjectLoss(childnode), Aggregation.Summed);
            }

            foreach (AtomicRITE rite in node.ResidualAtomicRITEs)
            {
                subjectLoss.MergeTimeSeries(rite.OriginalSubjectLoss, Aggregation.Summed);
            }

            return(subjectLoss);
        }
Exemplo n.º 12
0
 public abstract void SetSubjectLoss(LossTimeSeries _subjectLoss);
Exemplo n.º 13
0
 public override void SetSubjectLoss(LossTimeSeries _subjectLoss)
 {
     subjectLoss = _subjectLoss;
 }