/// <summary> /// Calculates the reinsurance company's loss for each event /// </summary> /// <param name="Event"></param> /// <param name="DealList"></param> /// <returns></returns> public static List <DealLossResult> CalculateLossForEvent(int[] Event, List <Deal> DealList) { List <DealLossResult> DealLossResultList = new List <DealLossResult>(); try { bool matchPeril = false; bool matchRegion = false; int dealLoss = 0; //for each event iterate through all the deals and match the deal to event based on the peril and region IDs foreach (Deal deal in DealList) { if (deal.ListOfPerils.Contains(Event[1])) //Attempt to match peril { matchPeril = true; } if (matchPeril) { if (deal.ListOfRegions.Contains(Event[2])) //Attempt to match region { matchRegion = true; } } if (matchPeril && matchRegion) //If periland region both match retrieve the loss value { dealLoss = CalculateEventDealLoss(Event[3], deal.Limit_retention); DealLossResult dlr = new DealLossResult(); dlr.EventId = Event[0]; dlr.DealId = deal.ID; dlr.DealLoss = dealLoss; DealLossResultList.Add(dlr); //Add the details of the loss with the event and deal ID to the list matchPeril = false; matchRegion = false; dealLoss = 0; } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(DealLossResultList); }
static void Main(string[] args) { try { List <Deal> ListofDeals = Deal.CreateDeals(); int[][] EventData = Data.Events; //Iterate through allthe events and retreive the Deal and its associated loss to Reinsurance company for (int i = 0; i < EventData.Length; i++) { List <DealLossResult> reInsureanceLossResultList = ReinsuranceCalculations.CalculateLossForEvent(EventData[i], ListofDeals); if (reInsureanceLossResultList.Count == 0) { Console.WriteLine("No deals are affected by these events"); } if (reInsureanceLossResultList.Count == 1) { DealLossResult dlr = reInsureanceLossResultList.FirstOrDefault(); Console.WriteLine("Event id = {0}, only affects deal {1} and the reinsurance company's loss is {2}", dlr.EventId, dlr.DealId, dlr.DealLoss); } if (reInsureanceLossResultList.Count > 1) { foreach (DealLossResult dlr in reInsureanceLossResultList) { Console.WriteLine("Event id = {0}, affects deal {1} and the reinsurance company's loss is {2}", dlr.EventId, dlr.DealId, dlr.DealLoss); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } }