コード例 #1
0
        public void Test_ConfigurationJISONJS()
        {
            var ngfmPrototype = new NGFMPrototype();

            CheckIfFileExists(ngfmPrototype.grammar_ast_js, "grammar-ast.js");
            CheckIfFileExists(ngfmPrototype.underscore_js, "underscore.js");

            ngfmPrototype.Dispose();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            ProcessCommandLineArgs(args);

            NGFMPrototypeDLL_Handle = new NGFMPrototype();

            if (InputFile != null)
            {
                NGFMPrototypeDLL_Handle.UploadContractExposures(new string[] { InputFile });
            }
            else
            {
                NGFMPrototypeDLL_Handle.UploadContractExposures(Directory.GetFiles(InputDirectory, "*.dat"));
            }

            Dictionary <long, Task> tasks = null;

            NGFMPrototypeDLL_Handle.BuildParsingContext();

            tasks = NGFMPrototypeDLL_Handle.Prepare_OLDAPI();

            if (tasks != null)
            {
                Task.WaitAll(tasks.Select(kv => kv.Value).ToArray());
            }

            NGFMPrototypeDLL_Handle.DisposeParsingContext();

            // Iterate through all events

            foreach (string _GUInputFile in Directory.GetFiles(GUInputDirectory, GUInputFile))
            {
                Dictionary <string, Dictionary <int, Dictionary <long, Tuple <double, uint, List <float> > > > > dr = null;

                dr = NGFMPrototypeDLL_Handle.ReadDamageRatiosFromFile(_GUInputFile);

                NGFMPrototypeDLL_Handle.TransformDamageRatios(dr);

                Dictionary <long, ResultPosition> Results = NGFMPrototypeDLL_Handle.ProcessEvent((int)_GUInputFile.GetHashCode(),
                                                                                                 NGFMPrototypeDLL_Handle.DamageRatiosPerSubPeril, true, 1);

                string InputPrefix = (InputFile != null) ? Path.GetFileNameWithoutExtension(InputFile) : "";

                string OutputFileName = "_" + InputPrefix +
                                        Path.GetFileNameWithoutExtension(_GUInputFile) + "_Output.csv";

                Utilities.WriteResultsToCSVFile(OutputDirectory + "\\" + OutputFileName, Results);
            }
        }
コード例 #3
0
        public void TestJint()
        {
            var ngfmPrototype = new NGFMPrototype();

            Jint.Engine JintEngine = new Jint.Engine();
            JintEngine.Execute(System.IO.File.ReadAllText(ngfmPrototype.underscore_js));
            JintEngine.Execute(System.IO.File.ReadAllText(ngfmPrototype.grammar_ast_js));

            string strCDL = "Contract Declarations Subject is Loss to Acme by HU Inception is 5 Jun 2014 Expiration is 4 Jun 2015 PolicyNum is A5059-3 Covers 100% share of 10M Sublimits 10000 by Wind";

            strCDL = strCDL.Replace(System.Environment.NewLine, "     ");

            Dictionary <string, object> IR =
                (Dictionary <string, object>)(AsPOJO(JintEngine.Execute("grammarAst.parse('" + strCDL + "')").GetCompletionValue()));
        }
コード例 #4
0
        public ExposureDataAdaptor(ContractExposure contractExposure, NGFMPrototype _ParsingAPI)
        {
            ParsingAPI        = _ParsingAPI;
            _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;
            }
        }
コード例 #5
0
        public void API_ExecuteFM()
        {
            var testCases = new Dictionary <string, Dictionary <string, string> >();

            #region Get Testing Configurations
            using (StreamReader sr = new StreamReader("TestCases_FMExecution.txt"))
            {
                string str;
                Dictionary <string, string> testContent = null;

                while ((str = sr.ReadLine()) != null)
                {
                    if (string.IsNullOrEmpty(str) || string.IsNullOrEmpty(str) || str.StartsWith("//"))//Commenting
                    {
                        continue;
                    }
                    else if (str.StartsWith("[Test"))
                    {
                        testContent = new Dictionary <string, string>();
                        testCases.Add(str, testContent);
                    }
                    else if (null != testContent)
                    {
                        string[] pair = str.Replace(" ", string.Empty)
                                        .Split(new char[] { ':' }, 2);

                        testContent.Add(pair[0], pair[1]);
                    }
                }
            }
            #endregion

            #region === Construct NGFMPrototype ===

            NGFMPrototype ngfmPrototype = new NGFMPrototype();

            #endregion

            foreach (var kv in testCases)
            {
                #region Get Expected Results

                var lossesPerSubPeril = ReadGULossFromFile(kv.Value["DR"]);

                PartitionData pData = RMS.Prototype.NGFM.Utilities.DeserializePartitionData(kv.Value["RITE"]);

                if (kv.Value.ContainsKey("CDL"))
                {
                    string cdl = ReadCDL(kv.Value["CDL"]);
                    foreach (var ce in pData.Exposures)
                    {
                        ce.Contract.CDLString = cdl;
                    }
                }

                string[] res            = kv.Value["RESULT"].Split(new char[] { ';', ',', ' ' });
                var      expectedResult = new Dictionary <long, double>();
                for (int i = 0; i < res.Length - 1; i += 2)
                {
                    long id = long.Parse(res[i]);
                    if (!expectedResult.ContainsKey(id))
                    {
                        expectedResult.Add(id, double.Parse(res[i + 1]));
                    }
                }

                #endregion

                #region === ProcessEvent() ===

                ngfmPrototype.Prepare(pData);

                // old API ----------------
                //var payOutDict = HDFM.ProcessEvent(EventOccurrenceDRs);
                //-------------------------

                // new new API ----------------
                int eventID = 0;
                ngfmPrototype.ProcessEvent_OLDNEWNEWAPI(eventID, lossesPerSubPeril);
                var payOutDict = ngfmPrototype.GetResultPositions(eventID, expectedResult.Keys.ToArray())
                                 .ToDictionary(p => p.Key, p => p.Value.PayOut);
                //-------------------------

                #endregion

                #region Comparison

                foreach (long id in expectedResult.Keys)
                {
                    double actualResult = (payOutDict.ContainsKey(id)) ? payOutDict[id] : -1;
                    Assert.AreEqual(expectedResult[id], actualResult, 0.01, "Test \"{0}\" (ID={1}) is failed.", kv.Key, id);
                    //string r = expectedResult[id];
                    //int n = r.Length - 1 - r.IndexOf('.');

                    //double payOut = (payOutDict.ContainsKey(id)) ? payOutDict[id] : -1;

                    //double d = Math.Round(payOut, n);
                    //string actualResult = d.ToString();
                    //Assert.AreEqual(expectedResult[id], actualResult, "Test \"{0}\" (ID={1}) is failed.", kv.Key, id);
                }

                #endregion
            }

            ngfmPrototype.Dispose();
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        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();
        }
コード例 #8
0
        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();
        }
コード例 #9
0
        public NGFMPrototypeDLL(PartitionData partitionData)
        {
            _handleNGFMPrototype = new NGFMPrototype();

            _handleNGFMPrototype.Prepare(partitionData);
        }
コード例 #10
0
 static PartitionDataAdpator()
 {
     NGFM_API = new NGFMPrototype();
 }
コード例 #11
0
        public void Test_ParseCDLUsingJISONJS()
        {
            string fileWithTestCases = "TestCases_ParseCDLtoJSON.txt";
            string testName          = "";

            var ngfmPrototype = new NGFMPrototype();

            using (StreamReader sr = new StreamReader(fileWithTestCases))
            {
                string str, actualOut, expectedOut;
                var    testIn  = new StringBuilder();
                var    testOut = new StringBuilder();

                bool flagIn  = false;
                bool flagOut = false;

                while ((str = sr.ReadLine()) != null)
                {
                    if (str.StartsWith("[Test"))
                    {
                        if (testName != "")
                        {
                            actualOut   = ngfmPrototype.ParseCDLUsingJISONJS_GetIR(testIn.ToString());
                            expectedOut = testOut.ToString().Trim();
                            Assert.AreEqual(expectedOut, actualOut, "Test \"{0}\" is failed.", testName);
                            testIn.Clear();
                            testOut.Clear();
                            flagIn = flagOut = false;
                        }
                        testName = str;
                    }
                    else if (str.StartsWith("[CDL]"))
                    {
                        flagIn  = true;
                        flagOut = false;
                    }
                    else if (str.StartsWith("[JSON]"))
                    {
                        flagIn  = false;
                        flagOut = true;
                    }
                    else if (flagIn)
                    {
                        if (testIn.Length > 0)
                        {
                            testIn.Append("\r\n");
                        }
                        testIn.Append(str);
                    }
                    else if (flagOut)
                    {
                        if (testOut.Length > 0)
                        {
                            testOut.Append("\r\n");
                        }
                        testOut.Append(str);
                    }
                }

                if (flagOut)
                {
                    actualOut   = ngfmPrototype.ParseCDLUsingJISONJS_GetIR(testIn.ToString());
                    expectedOut = testOut.ToString().Trim();
                    Assert.AreEqual(expectedOut, actualOut, "Test \"{0}\" is failed.", testName);
                }
            }

            ngfmPrototype.Dispose();
        }