private static void TestRITEMap(PartitionData pd, long conID) { //Default SubSampling Settings SubSamplingAnalysisSetting subSamplingSettings = new SubSamplingAnalysisSetting(false, 1, 0, 250, "", ""); PartitionDataAdpator PDataAdap = new PartitionDataAdpator(pd, subSamplingSettings); ExposureDataAdaptor expData = PDataAdap.GetExposureAdaptor(conID); ISubPerilConfig subperilInfo = new RMSSubPerilConfig(); RITEmapper1 mapper = new RITEmapper1(expData, new RAPSettings(new HashSet <string> { "EQ" }), subperilInfo); }
private void Initialize(PartitionData partitionData, bool append = false) { Initialize(append); #region VECTORIZED REFERENCE PROTOTYPE INTEGRATION _ReferencePrototype = null; UseReference = Convert.ToBoolean(ConfigurationManager.AppSettings["UseReference"]); if (UseReference) { //Sunny hack... need to change to read from Model Setings Provider from the DLM.. RAPSettings RapSettings = new RAPSettings(new HashSet <string> { "WS", "WI", "WA" }); SubSamplingAnalysisSetting subSamplingSetiings = new SubSamplingAnalysisSetting(false, 1, 0, 250, "", ""); if (RapSettings != null || subSamplingSetiings != null) { _ReferencePrototype = new ReferencePrototype(partitionData, RapSettings, subSamplingSetiings); } else { throw new InvalidOperationException("Cannot run in Array Mode and have null RapSettings or null SubSampling Settings!"); } } #endregion if (null != partitionData && null != partitionData.Exposures) { foreach (ContractExposure ce in partitionData.Exposures) { if ((ce.ContractType != null) && ce.ContractType.IsReinsuranceContract()) { //Treaty Contract ContractExposureDataIndex.TryAdd(ce.ExposureID, new TreatyContractExposureData(JavaScriptHarness, false, ce)); } else if (null != ce.ContractSubjectExposures && null != ce.Subschedules) { // Primary Contract ContractExposureDataIndex.TryAdd(ce.ExposureID, new PrimaryContractExposureData(JavaScriptHarness, false, ce, "", _ReferencePrototype)); } } } }
private static void TestGULossVector(PartitionData pd, long conID) { //Default SubSampling Settings SubSamplingAnalysisSetting subSamplingSettings = new SubSamplingAnalysisSetting(false, 1, 0, 250, "", ""); PartitionDataAdpator PDataAdap = new PartitionDataAdpator(pd, subSamplingSettings); ExposureDataAdaptor expData = PDataAdap.GetExposureAdaptor(conID); ISubPerilConfig subperilInfo = new RMSSubPerilConfig(); IRITEindexMapper mapper = new RITEmapper1(expData, new RAPSettings(new HashSet <string> { "EQ" }), subperilInfo); HashSet <String> subperils = new HashSet <string> { "EQ", "WS" }; VectorGUInputGeneratorFactory vectorgeneratorFactory = new VectorGUInputGeneratorFactory(pd, new HashSet <string> { "EQ" }, TimeStyle.ConstantTimeStamps, LossStyle.GroundUp, true, subSamplingSettings); VectorGUInputGenerator ReferenceEventGen = vectorgeneratorFactory.GetGeneratorForContract(conID); IVectorEvent Event = ReferenceEventGen.GenerateRITELoss(1); }
public static void TestReferenceWithPeriods(GraphType type, PartitionData PD, int conID, COLCollection COLSet) { RAPSettings settings = new RAPSettings(COLSet.GetSubperils()); //Default SubSampling Settings SubSamplingAnalysisSetting subSamplingSettings = new SubSamplingAnalysisSetting(false, 1, 0, 250, "", ""); //NGFMPrototype NGFM = new NGFMPrototype(PD); ReferencePrototype Reference = new ReferencePrototype(PD, settings, subSamplingSettings); //Reference.ReferencePrepare(GraphType.Auto); NGFMPrototype NGFM = new NGFMPrototype(1); NGFM.Prepare(PD); //NGFM result is cached, so create another object for each event DateTime start = DateTime.Now; PLTGenertorFactory generatorFactory = new PLTGenertorFactory(PD, COLSet, subSamplingSettings, start, TimeStyle.ConstantTimeStamps, LossStyle.DamagaeRatio); PLTGenerator NGFMEventGen = generatorFactory.GetGeneratorForContract(conID); //GUInputGenerator ReferenceEventGen = generatorFactory.GetGeneratorForContract(conID); //VectorGUInputGeneratorFactory vectorgeneratorFactory = new VectorGUInputGeneratorFactory(PD, COLSet.GetSubperils(), TimeStyle.ConstantTimeStamps, LossStyle.DamagaeRatio, true, subSamplingSettings); //VectorGUInputGenerator ReferenceEventGen = vectorgeneratorFactory.GetGeneratorForContract(conID); int counter = 0; int total = 0; Console.WriteLine("State at: " + DateTime.Now.ToString("h:mm:ss tt")); //NGFMPrototype NGFM = new NGFMPrototype(PD); for (int i = 1; i < 200; i += 1) { Period NGFMPeriod; List <Dictionary <string, Dictionary <int, Dictionary <long, Tuple <double, uint, List <float> > > > > > NGFMguLossList; IVectorEvent RefguLoss; if (NGFMEventGen.GeneratePeriodLoss(i)) { NGFMPeriod = NGFMEventGen.PeriodLoss; } else { throw new InvalidOperationException("Cannot get ground-up loss for event: " + i); } //if (ReferenceEventGen.GenerateRITELoss(i)) //{ // RefguLoss = ReferenceEventGen.GULosses; //} //else // throw new InvalidOperationException("Cannot get ground-up loss for event: " + i); //RefguLoss = ReferenceEventGen.GenerateRITELoss(i); //Contract ID 11236672 hard coded.. 11324656 //double ReferencePayout = 0; ReferenceResultOutput ReferenceOutput = Reference.ExecutePeriod(conID, type, NGFMPeriod.EventLossList); double ReferencePayout = ReferenceOutput.TotalPayout; //double ReferencePayout2 = Reference.Execute(conIndex, GraphType.FixedGraph1, RefguLoss); //double NGFMpayout = NGFM.ExecuteFM(NGFMguLoss)[11324656]; List <RMS.ContractObjectModel.ResultPosition> results = NGFM.ProcessPeriod(i, NGFMPeriod.EventLossList, true, 1, conID)[conID]; double NGFMpayout = results.Select(result => result.PayOut).Sum(); //double NGFMpayout = 0; double diff = NGFMpayout - ReferencePayout; total += 1; if (Math.Abs(diff) > 0.1) { counter += 1; Console.WriteLine("Event ID: " + i + " || " + "NGFM: " + Math.Round(NGFMpayout, 5) + " || " + "Reference: " + Math.Round(ReferencePayout, 5) + " || " + Math.Round(diff, 5)); } Console.WriteLine("Event ID: " + i + " || " + "NGFM: " + Math.Round(NGFMpayout, 2) + " || " + "Reference: " + Math.Round(ReferencePayout, 2) + " || " + Math.Round(diff, 2)); } Console.WriteLine("Number of difference: " + counter); Console.WriteLine("total event = " + total); Console.WriteLine("End at: " + DateTime.Now.ToString("h:mm:ss tt")); Console.ReadLine(); }
public static void TestReferenceSpeed(GraphType type, PartitionData PD, int conIndex, COLCollection COLSet) { RAPSettings settings = new RAPSettings(COLSet.GetSubperils()); //Default SubSampling Settings SubSamplingAnalysisSetting subSamplingSettings = new SubSamplingAnalysisSetting(false, 1, 0, 250, "", ""); //NGFMPrototype NGFM = new NGFMPrototype(PD); ReferencePrototype Reference = new ReferencePrototype(PD, settings, subSamplingSettings); Reference.ReferencePrepare(GraphType.Auto); NGFMPrototype NGFM = new NGFMPrototype(); NGFM.Prepare(PD); //NGFM result is cached, so create another object for each event double MicroSecondTicks = Stopwatch.Frequency / 1000000.0; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); NGFM.Prepare(PD); //NGFM result is cached, so create another object for each event stopwatch.Stop(); double NGFMGraphTime = Convert.ToDouble(stopwatch.ElapsedTicks) / MicroSecondTicks; PartitionDataAdpator PDataAdap = new PartitionDataAdpator(PD, subSamplingSettings); ExposureDataAdaptor expData = PDataAdap.GetExposureAdaptor(conIndex); GUInputGeneratorFactory generatorFactory = new GUInputGeneratorFactory(PD, COLSet, subSamplingSettings, TimeStyle.ConstantTimeStamps, LossStyle.DamagaeRatio); GUInputGenerator NGFMEventGen = generatorFactory.GetGeneratorForContract(conIndex); VectorGUInputGeneratorFactory vectorgeneratorFactory = new VectorGUInputGeneratorFactory(PD, COLSet.GetSubperils(), TimeStyle.ConstantTimeStamps, LossStyle.GroundUp, true, subSamplingSettings); VectorGUInputGenerator ReferenceEventGen = vectorgeneratorFactory.GetGeneratorForContract(conIndex); int counter = 0; int total = 0; Console.WriteLine("State at: " + DateTime.Now.ToString("h:mm:ss tt")); //NGFMPrototype NGFM = new NGFMPrototype(PD); for (int i = 1; i < 100; i += 1) { Dictionary <string, Dictionary <int, Dictionary <long, Tuple <double, uint, List <float> > > > > NGFMguLoss; //Dictionary<string, Dictionary<int, Dictionary<long, Tuple<double, uint, List<float>>>>> RefguLoss; if (NGFMEventGen.GenerateRITELoss(i)) { NGFMguLoss = NGFMEventGen.GULosses; } else { throw new InvalidOperationException("Cannot get ground-up loss for event: " + i); } IVectorEvent RefguLoss = ReferenceEventGen.GenerateRITELoss(i); stopwatch = new Stopwatch(); stopwatch.Start(); double ReferencePayout = Reference.Execute(conIndex, type, RefguLoss).TotalPayout; stopwatch.Stop(); double ReferenceTime = Convert.ToDouble(stopwatch.ElapsedTicks) / MicroSecondTicks; stopwatch.Reset(); stopwatch.Start(); double NGFMpayout = 0; //double NGFMpayout = NGFM.ExecuteFM(NGFMguLoss)[conIndex]; RMS.ContractObjectModel.ResultPosition result = NGFM.ProcessEvent(i, NGFMguLoss, true, 1, new long[] { conIndex })[conIndex]; NGFMpayout = result.PayOut; stopwatch.Stop(); double NGFMTime = Convert.ToDouble(stopwatch.ElapsedTicks) / MicroSecondTicks; double diff = NGFMTime - ReferenceTime; Console.WriteLine("Event ID: " + i + " || " + "NGFM: " + NGFMTime + " || " + "Reference: " + ReferenceTime + " || " + diff); } Console.WriteLine("total event = " + total); Console.WriteLine("NGFM Graph Building Time = " + NGFMGraphTime); Console.WriteLine("End at: " + DateTime.Now.ToString("h:mm:ss tt")); Console.ReadLine(); }
public static void TestReference(GraphType type, PartitionData PD, int conID, COLCollection COLSet) { RAPSettings settings = new RAPSettings(COLSet.GetSubperils()); //Default SubSampling Settings SubSamplingAnalysisSetting subSamplingSettings = new SubSamplingAnalysisSetting(false, 1, 0, 250, "", ""); //NGFMPrototype NGFM = new NGFMPrototype(PD); ReferencePrototype Reference = new ReferencePrototype(PD, settings, subSamplingSettings); Reference.ReferencePrepare(GraphType.Auto); NGFMPrototype NGFM = new NGFMPrototype(); NGFM.Prepare(PD); //NGFM result is cached, so create another object for each event PartitionDataAdpator PDataAdap = new PartitionDataAdpator(PD, subSamplingSettings); ExposureDataAdaptor expData = PDataAdap.GetExposureAdaptor(conID); GUInputGeneratorFactory generatorFactory = new GUInputGeneratorFactory(PD, COLSet, subSamplingSettings, TimeStyle.RandomTimeStamps, LossStyle.DamagaeRatio); GUInputGenerator NGFMEventGen = generatorFactory.GetGeneratorForContract(conID); GUInputGenerator ReferenceEventGen = generatorFactory.GetGeneratorForContract(conID); int counter = 0; int total = 0; Console.WriteLine("State at: " + DateTime.Now.ToString("h:mm:ss tt")); //NGFMPrototype NGFM = new NGFMPrototype(PD); for (int i = 247; i < 248; i += 1) { Dictionary <string, Dictionary <int, Dictionary <long, Tuple <double, uint, List <float> > > > > NGFMguLoss; Dictionary <string, Dictionary <int, Dictionary <long, Tuple <double, uint, List <float> > > > > RefguLoss; if (NGFMEventGen.GenerateRITELoss(i)) { NGFMguLoss = NGFMEventGen.GULosses; } else { throw new InvalidOperationException("Cannot get ground-up loss for event: " + i); } if (ReferenceEventGen.GenerateRITELoss(i)) { RefguLoss = ReferenceEventGen.GULosses; } else { throw new InvalidOperationException("Cannot get ground-up loss for event: " + i); } //Contract ID 11236672 hard coded.. 11324656 double ReferencePayout = Reference.Execute(conID, type, RefguLoss).TotalPayout; //double ReferencePayout2 = Reference.Execute(conIndex, GraphType.FixedGraph1, RefguLoss); //double NGFMpayout = NGFM.ExecuteFM(NGFMguLoss)[11324656]; RMS.ContractObjectModel.ResultPosition result = NGFM.ProcessEvent(i, NGFMguLoss, true, 1, new long[] { conID })[conID]; double NGFMpayout = result.PayOut; //double NGFMpayout = 0; double diff = NGFMpayout - ReferencePayout; total += 1; if (Math.Abs(diff) > 0.1) { counter += 1; Console.WriteLine("Event ID: " + i + " || " + "NGFM: " + Math.Round(NGFMpayout, 5) + " || " + "Reference: " + Math.Round(ReferencePayout, 5) + " || " + Math.Round(diff, 5)); } Console.WriteLine("Event ID: " + i + " || " + "NGFM: " + Math.Round(NGFMpayout, 2) + " || " + "Reference: " + Math.Round(ReferencePayout, 2) + " || " + Math.Round(diff, 2)); } Console.WriteLine("Number of difference: " + counter); Console.WriteLine("total event = " + total); Console.WriteLine("End at: " + DateTime.Now.ToString("h:mm:ss tt")); Console.ReadLine(); }
private static void TestMatrixHDFM(PartitionData pd, long conID) { Stopwatch sw = new Stopwatch(); //Default SubSampling Settings SubSamplingAnalysisSetting subSamplingSettings = new SubSamplingAnalysisSetting(false, 1, 0, 250, "", ""); PartitionDataAdpator PDataAdap = new PartitionDataAdpator(pd, subSamplingSettings); ExposureDataAdaptor expData = PDataAdap.GetExposureAdaptor(conID); ISubPerilConfig subperilInfo = new RMSSubPerilConfig(); HashSet <String> subperils = new HashSet <string> { "WI" }; IRITEindexMapper mapper = new RITEmapper1(expData, new RAPSettings(subperils), subperilInfo); VectorGUInputGeneratorFactory vectorgeneratorFactory = new VectorGUInputGeneratorFactory(pd, subperils, TimeStyle.ConstantTimeStamps, LossStyle.GroundUp, true, subSamplingSettings); VectorGUInputGenerator vectorGenerator = vectorgeneratorFactory.GetGeneratorForContract(conID); FixedMatrixGraphJPTY JPTYGraph = new FixedMatrixGraphJPTY(expData); JPTYGraph.Initialize(); MatrixGraphExecuter executer = new MatrixGraphExecuter(JPTYGraph); int NumOfEvents = 100; double totalTime = 0; for (int eventId = 6; eventId < NumOfEvents; eventId++) { IVectorEvent Event = vectorGenerator.GenerateRITELoss(eventId); sw.Start(); float payout = (float)(executer.Run(Event).TotalPayOut); sw.Stop(); long test = sw.ElapsedMilliseconds; //totalTime += sw.Elapsed.TotalMilliseconds; } double avgTime = sw.Elapsed.TotalMilliseconds / NumOfEvents; double avgGraphState = executer.IniGraphState.Elapsed.TotalMilliseconds / NumOfEvents; double avgAggregation = executer.Aggregation.Elapsed.TotalMilliseconds / NumOfEvents; double avgInteraction = executer.Interaction.Elapsed.TotalMilliseconds / NumOfEvents; double avgFillARite = executer.AssignGUtoARite.Elapsed.TotalMilliseconds / NumOfEvents; double avgSumByPattern = executer.Aggregation1.Elapsed.TotalMilliseconds / NumOfEvents; double avgAllocation = executer.Allocationtimer.Elapsed.TotalMilliseconds / NumOfEvents; Console.WriteLine("For " + NumOfEvents + " Events avg execution time is " + avgTime + " Milliseconds"); Console.WriteLine("For" + NumOfEvents + "avg GraphState Instantiation is " + avgGraphState + "Milliseconds"); Console.WriteLine("For" + NumOfEvents + "avg Aggregation is " + avgAggregation + "Milliseconds"); Console.WriteLine("For" + NumOfEvents + "avg Interaction is " + avgInteraction + "Milliseconds"); Console.WriteLine("For" + NumOfEvents + "avg Assigning GU to Arites is " + avgFillARite + "Milliseconds"); Console.WriteLine("For" + NumOfEvents + "avg SumArrayByPattern is " + avgSumByPattern + "Milliseconds"); Console.WriteLine("For" + NumOfEvents + "avg allocation time is " + avgAllocation + "Milliseconds"); Console.ReadLine(); }