Exemple #1
0
        private void FillDemoPlots()
        {
            Random rand = new Random();

            if (true)
            {
                var plt = new ScottPlot.Plot(600, 400);

                int      pointCount = 51;
                double[] xs         = DataGen.Consecutive(pointCount);
                double[] sin        = DataGen.Sin(pointCount);
                double[] cos        = DataGen.Cos(pointCount);

                plt.PlotScatter(xs, sin, label: "sin");
                plt.PlotScatter(xs, cos, label: "cos");
                plt.Legend();

                plt.Title("Scatter Plot Quickstart");
                plt.YLabel("Vertical Units");
                plt.XLabel("Horizontal Units");

                var pv1 = new ScottPlot.WpfPlot();
                pv1.Height = 200;

                plt.Title("Scatter Plot Quickstart");
                plt.YLabel("Vertical Units");
                plt.XLabel("Horizontal Units");

                StackPanelCharts.Children.Add(pv1);
            }

            if (true)
            {
                var pv1 = new ScottPlot.WpfPlot();
                pv1.Height = 200;
                pv1.plt.PlotSignal(DataGen.RandomWalk(rand, 100));

                var      plt        = pv1.plt;
                int      pointCount = 51;
                double[] xs         = DataGen.Consecutive(pointCount);
                double[] sin        = DataGen.Sin(pointCount);
                double[] cos        = DataGen.Cos(pointCount);

                plt.PlotScatter(xs, sin, label: "sin");
                plt.PlotScatter(xs, cos, label: "cos");
                plt.Legend();

                plt.Title("Scatter Plot Quickstart");
                plt.YLabel("Vertical Units");
                plt.XLabel("Horizontal Units");

                StackPanelCharts.Children.Add(pv1);
            }
        }
Exemple #2
0
        public void Test_SaveFig_OutputScaling()
        {
            var plt = new ScottPlot.Plot();

            plt.AddSignal(DataGen.Sin(51), label: "sin");
            plt.AddSignal(DataGen.Cos(51), label: "cos");
            plt.Title("Scaled Figure Demo");
            plt.XLabel("Horizontal Axis");
            plt.YLabel("Vertical Axis");
            plt.Legend();

            System.Drawing.Bitmap bmpA = plt.Render(400, 300);
            Assert.AreEqual(400, bmpA.Width);
            Assert.AreEqual(300, bmpA.Height);

            System.Drawing.Bitmap bmpB = plt.Render(400, 300, scale: .5);
            Assert.AreEqual(200, bmpB.Width);
            Assert.AreEqual(150, bmpB.Height);

            System.Drawing.Bitmap bmpC = plt.Render(400, 300, scale: 2);
            Assert.AreEqual(800, bmpC.Width);
            Assert.AreEqual(600, bmpC.Height);

            System.Drawing.Bitmap bmpD = plt.Render(300, 400, scale: 2);
            Assert.AreEqual(600, bmpD.Width);
            Assert.AreEqual(800, bmpD.Height);

            System.Drawing.Bitmap legendNormal = plt.RenderLegend();
            System.Drawing.Bitmap legendBig    = plt.RenderLegend(scale: 2);
            Assert.Greater(legendBig.Width, legendNormal.Width);
            Assert.Greater(legendBig.Height, legendNormal.Height);
        }
Exemple #3
0
        public void SaveScottPlotTestFromWebsite()
        {
            string saveFileLocation = "C:\\Temp\\Quickstart_Quickstart_Scatter.png";
            var    plt = new ScottPlot.Plot(600, 400);

            int pointCount = 51;

            double[] xs  = DataGen.Consecutive(pointCount);
            double[] sin = DataGen.Sin(pointCount);
            double[] cos = DataGen.Cos(pointCount);

            plt.AddScatter(sin, cos, label: "sin");
            plt.AddScatter(xs, cos, label: "cos");
            plt.Legend();

            plt.Title("Scatter Plot Quickstart");
            plt.YLabel("Vertical Units");
            plt.XLabel("Horizontal Units");

            plt.SaveFig(saveFileLocation);

            Assert.IsTrue(System.IO.File.Exists(saveFileLocation));

            System.IO.File.Delete(saveFileLocation);
        }
Exemple #4
0
        public void Test_Bollinger_Bands()
        {
            Random rand = new Random(0);

            double[] xs    = DataGen.Consecutive(150);
            OHLC[]   ohlcs = DataGen.RandomStockPrices(rand, xs.Length);
            (var sma, var bolL, var bolU) = ScottPlot.Statistics.Finance.Bollinger(ohlcs);

            // replace timestamps with a series of numbers starting at 0
            for (int i = 0; i < ohlcs.Length; i++)
            {
                ohlcs[i].time = i;
            }

            var plt = new ScottPlot.Plot(600, 400);

            plt.PlotCandlestick(ohlcs);
            plt.PlotFill(xs, bolL, xs, bolU, fillColor: Color.Blue, fillAlpha: .1);
            plt.PlotScatter(xs, bolL, color: Color.Navy, markerSize: 0);
            plt.PlotScatter(xs, bolU, color: Color.Navy, markerSize: 0);
            plt.PlotScatter(xs, sma, color: Color.Navy, markerSize: 0, lineStyle: LineStyle.Dash);

            plt.Title("Bollinger Bands");
            plt.YLabel("Price");
            plt.XLabel("Days");
            plt.Legend();
            plt.AxisAutoX(.03);
            TestTools.SaveFig(plt);
        }
        public void Test_Bollinger_Bands()
        {
            Random rand = new Random(0);

            double[] xs    = DataGen.Consecutive(150);
            OHLC[]   ohlcs = DataGen.RandomStockPrices(rand, xs.Length);

            // calculate moving average X and Ys
            (var sma, var bolL, var bolU) = ScottPlot.Statistics.Finance.Bollinger(ohlcs, 20);
            double[] xs2 = xs.Skip(20).ToArray();

            // replace timestamps with a series of numbers starting at 0
            for (int i = 0; i < ohlcs.Length; i++)
            {
                ohlcs[i].DateTime = DateTime.FromOADate(i);
            }

            var plt = new ScottPlot.Plot(600, 400);

            plt.AddCandlesticks(ohlcs);
            plt.AddFill(xs2, bolL, xs2, bolU, color: Color.FromArgb(10, Color.Blue));
            plt.AddScatter(xs2, bolL, color: Color.Navy, markerSize: 0, label: "Bollinger Bands");
            plt.AddScatter(xs2, bolU, color: Color.Navy, markerSize: 0);
            plt.AddScatter(xs2, sma, color: Color.Navy, markerSize: 0, lineStyle: LineStyle.Dash, label: "SMA 20");

            plt.Title("Moving Average and Standard Deviation");
            plt.YLabel("Price");
            plt.XLabel("Days");
            plt.Legend();
            plt.AxisAutoX(.03);
            TestTools.SaveFig(plt);
        }
Exemple #6
0
        public void Test_SMA_Candlestick()
        {
            Random rand = new Random(0);

            double[] xs    = DataGen.Consecutive(150);
            OHLC[]   ohlcs = DataGen.RandomStockPrices(rand, xs.Length);
            double[] sma20 = ScottPlot.Statistics.Finance.SMA(ohlcs, 20);
            double[] sma50 = ScottPlot.Statistics.Finance.SMA(ohlcs, 50);

            // replace timestamps with a series of numbers starting at 0
            for (int i = 0; i < ohlcs.Length; i++)
            {
                ohlcs[i].time = i;
            }

            var plt = new ScottPlot.Plot(600, 400);

            plt.PlotCandlestick(ohlcs);
            plt.PlotScatter(xs, sma20, label: "20 day SMA",
                            color: Color.Blue, markerSize: 0, lineWidth: 2);
            plt.PlotScatter(xs, sma50, label: "50 day SMA",
                            color: Color.Maroon, markerSize: 0, lineWidth: 2);

            plt.Title("Simple Moving Average (SMA)");
            plt.YLabel("Price");
            plt.XLabel("Days");
            plt.Legend();
            plt.AxisAutoX(.03);
            TestTools.SaveFig(plt);
        }
        static public void RunJolka(List <Solver <string> > backtracks, List <Solver <string> > backtrackfws, string heuristicB = "", string heuristicBF = "", string type = "")
        {
            var           plt     = new ScottPlot.Plot(1280, 720);
            List <double> xlist   = new List <double>();
            List <double> yfwlist = new List <double>();
            List <double> ylist   = new List <double>();

            foreach (var el in backtrackfws)
            {
                xlist.Add(el.solvedPuzzle.Puzzle.id);
                if (type == "time")
                {
                    yfwlist.Add(el.solvedPuzzle.elapsed.TotalMilliseconds);
                }
                else
                {
                    yfwlist.Add(el.solvedPuzzle.Puzzle.steps);
                }
            }
            foreach (var el in backtracks)
            {
                if (type == "time")
                {
                    ylist.Add(el.solvedPuzzle.elapsed.TotalMilliseconds);
                }
                else
                {
                    ylist.Add(el.solvedPuzzle.Puzzle.steps);
                }
            }
            double[] xs = xlist.ToArray();
            ylist.Insert(2, (double)1);
            double[] dataB  = Tools.Log10(ylist.ToArray());
            double[] dataBF = Tools.Log10(yfwlist.ToArray());
            plt.PlotBar(xs, dataB, label: "Backtrack w/ " + heuristicB, barWidth: .3, xOffset: -0.2, showValues: true);
            plt.PlotBar(xs, dataBF, label: "Backtrack with forward w/ " + heuristicBF, barWidth: .3, xOffset: 0.2, showValues: true);
            plt.Title(type + " over Jolka id");
            plt.Ticks(useExponentialNotation: false, useMultiplierNotation: false, logScaleY: true);
            plt.Axis(y1: 0);
            plt.XTicks(new string[] { "0", "1", "2", "3", "4" });
            if (type == "time")
            {
                plt.YLabel("Execution time [10 ^ y ms]");
            }
            else
            {
                plt.YLabel("Steps [10 ^ y]");
            }
            plt.XLabel("Jolka ID");
            plt.Legend(location: legendLocation.upperRight);
            plt.SaveFig(heuristicB + heuristicBF + type + "JolkaBvsBF" + ".png");
        }
Exemple #8
0
        public void Test_Layout_RotatedTicksWithRoom()
        {
            var plt = new ScottPlot.Plot(400, 300);

            plt.PlotSignal(DataGen.Sin(51), xOffset: 1e6);
            plt.PlotSignal(DataGen.Cos(51), xOffset: 1e6);

            // WARNING: this resets the layout, so you must call Layout() after this
            plt.XLabel("horizontal axis label");

            plt.Ticks(xTickRotation: 45);
            plt.Layout(xScaleHeight: 50);

            TestTools.SaveFig(plt);
        }
Exemple #9
0
        /// <summary>
        /// Method for plotting data to .png
        /// </summary>
        /// <param name="dataPoints"></param>
        public static void Graph(double[,] dataPoints)
        {
            double[] DataError    = new double[dataPoints.GetUpperBound(0) + 1];
            double[] DataAccuracy = new double[dataPoints.GetUpperBound(0) + 1];
            double[] dataXs       = new double[dataPoints.GetUpperBound(0) + 1];

            for (int i = 0; i < dataXs.Length; i++)
            {
                dataXs[i]       = i;
                DataError[i]    = dataPoints[i, 0];
                DataAccuracy[i] = dataPoints[i, 1];
            }

            /// plot the data
            ///

            var plt_acc  = new ScottPlot.Plot(800, 600);
            var plt_loss = new ScottPlot.Plot(800, 600);

            plt_acc.PlotScatter(dataXs, DataAccuracy, label: "Accuracy");
            plt_loss.PlotScatter(dataXs, DataError, label: "Error rate");

            plt_acc.Grid(xSpacing: 20, ySpacing: .1);
            plt_loss.Grid(xSpacing: 5, ySpacing: .1);

            plt_acc.Legend(location: legendLocation.upperLeft);
            plt_loss.Legend(location: legendLocation.upperLeft);

            plt_acc.Title("Accuracy");
            plt_loss.Title("Loss");

            plt_acc.XLabel("Epoch");
            plt_acc.YLabel("Accuracy");

            plt_loss.XLabel("Epoch");
            plt_loss.YLabel("Loss");

            plt_acc.SaveFig("NN_acc.png");
            plt_loss.SaveFig("NN_loss.png");
            Process.Start(new ProcessStartInfo(@"NN_acc.png")
            {
                UseShellExecute = true
            });
            Process.Start(new ProcessStartInfo(@"NN_loss.png")
            {
                UseShellExecute = true
            });
        }
Exemple #10
0
        /// <summary>
        /// Return a new Plot with all the same Plottables (and some of the styles) of this one
        /// </summary>
        public Plot Copy()
        {
            Plot plt2      = new Plot(settings.Width, settings.Height);
            var  settings2 = plt2.GetSettings(false);

            settings2.Plottables.AddRange(settings.Plottables);

            // TODO: add a Copy() method to the settings module, or perhaps Update(existingSettings).

            // copy over only the most relevant styles
            plt2.Title(settings.XAxis2.Title.Label);
            plt2.XLabel(settings.XAxis.Title.Label);
            plt2.YLabel(settings.YAxis.Title.Label);

            plt2.AxisAuto();
            return(plt2);
        }
Exemple #11
0
        public void Test_Layout_RotatedTicksWithRoom()
        {
            var plt = new ScottPlot.Plot(400, 300);
            var s1  = plt.AddSignal(DataGen.Sin(51));
            var s2  = plt.AddSignal(DataGen.Cos(51));

            s1.OffsetX = 1e6;
            s2.OffsetX = 1e6;

            // WARNING: this resets the layout, so you must call Layout() after this
            plt.XLabel("horizontal axis label");

            plt.XAxis.TickLabelStyle(rotation: 45);
            plt.Layout(bottom: 50);

            TestTools.SaveFig(plt);
        }
Exemple #12
0
        /// <summary>
        /// Return a new Plot with all the same Plottables (and some of the styles) of this one
        /// </summary>
        public Plot Copy()
        {
            Plot plt2      = new Plot(settings.figureSize.Width, settings.figureSize.Height);
            var  settings2 = plt2.GetSettings(false);

            settings2.plottables.AddRange(settings.plottables);

            // TODO: add a Copy() method to the settings module, or perhaps Update(existingSettings).

            // copy over only the most relevant styles
            plt2.Title(settings.title.text);
            plt2.XLabel(settings.xLabel.text);
            plt2.YLabel(settings.yLabel.text);

            plt2.TightenLayout();
            plt2.AxisAuto();
            return(plt2);
        }
Exemple #13
0
        /// <summary>
        /// Return a new Plot with all the same Plottables (and some of the styles) of this one.
        /// </summary>
        public Plot Copy()
        {
            // This is typically only called when you right-click a plot in a control and hit "open in new window".
            // All state from the old plot must be copied to the new plot.

            Plot plt2      = new Plot(settings.Width, settings.Height);
            var  settings2 = plt2.GetSettings(false);

            // Copying state of plottables is easy because they contain their own state.
            settings2.Plottables.AddRange(settings.Plottables);

            // TODO: copy axes, since they now carry their own state too.
            plt2.Title(settings.XAxis2.Title.Label);
            plt2.XLabel(settings.XAxis.Title.Label);
            plt2.YLabel(settings.YAxis.Title.Label);

            plt2.AxisAuto();
            return(plt2);
        }
Exemple #14
0
        public void Test_Layout()
        {
            int pointCount = 50;

            double[] dataXs  = DataGen.Consecutive(pointCount);
            double[] dataSin = DataGen.Sin(pointCount);
            double[] dataCos = DataGen.Cos(pointCount);

            var plt = new ScottPlot.Plot();

            plt.PlotScatter(dataXs, dataSin);
            plt.PlotScatter(dataXs, dataCos);

            plt.Title("Very Complicated Data");
            plt.XLabel("Experiment Duration");
            plt.YLabel("Productivity");

            TestTools.SaveFig(plt);
        }
Exemple #15
0
        /// <summary>
        /// Return a new Plot with all the same Plottables (and some of the styles) of this one.
        /// This is called when you right-click a plot in a control and hit "open in new window".
        /// </summary>
        public Plot Copy()
        {
            Settings oldSettings = settings;
            Plot     oldPlot     = this;

            Plot newPlot = new Plot(oldSettings.Width, oldSettings.Height);

            foreach (IPlottable oldPlottable in oldPlot.GetPlottables())
            {
                newPlot.Add(oldPlottable);
            }
            newPlot.AxisAuto();

            newPlot.XLabel(oldSettings.XAxis.Label());
            newPlot.YLabel(oldSettings.YAxis.Label());
            newPlot.Title(oldSettings.XAxis2.Label());

            return(newPlot);
        }
Exemple #16
0
        public void Test_SMA_DoubleArray()
        {
            Random rand = new Random(0);

            double[] xs     = DataGen.Consecutive(150);
            double[] prices = DataGen.RandomWalk(rand, xs.Length, offset: 50);
            double[] sma20  = ScottPlot.Statistics.Finance.SMA(prices, 20);
            double[] sma50  = ScottPlot.Statistics.Finance.SMA(prices, 50);

            var plt = new ScottPlot.Plot(600, 400);

            plt.PlotScatter(xs, prices, lineWidth: 0, label: "Price");
            plt.PlotScatter(xs, sma20, label: "20 day SMA", markerSize: 0, lineWidth: 2);
            plt.PlotScatter(xs, sma50, label: "50 day SMA", markerSize: 0, lineWidth: 2);

            plt.YLabel("Price");
            plt.XLabel("Days");
            plt.Legend();
            TestTools.SaveFig(plt);
        }
Exemple #17
0
        public void Test_Layout_LabelsWithLineBreaks()
        {
            int pointCount = 50;

            double[] dataXs  = DataGen.Consecutive(pointCount);
            double[] dataSin = DataGen.Sin(pointCount);
            double[] dataCos = DataGen.Cos(pointCount);

            var plt = new ScottPlot.Plot();

            plt.PlotScatter(dataXs, dataSin);
            plt.PlotScatter(dataXs, dataCos);

            string labelWithLineBreak = "Line One\nLine Two";

            plt.Title(labelWithLineBreak, fontSize: 30);
            plt.XLabel(labelWithLineBreak);
            plt.YLabel(labelWithLineBreak);

            TestTools.SaveFig(plt);
        }
        static public void RunSudoku(double[] difficulty, double[] dataB, double[] dataBF, string heuristicB = "", string heuristicBF = "", string type = "")
        {
            var plt        = new ScottPlot.Plot(1280, 720);
            int pointCount = dataB.Length;

            plt.PlotBar(difficulty, dataB, label: "Backtrack w/ " + heuristicB, barWidth: .3, xOffset: -0.2);
            plt.PlotBar(difficulty, dataBF, label: "Backtrack with forward w/ " + heuristicBF, barWidth: .3, xOffset: 0.2);
            plt.Title("Average " + type + " over sudoku difficulty");
            plt.Axis(y1: 0);
            if (type == "time")
            {
                plt.YLabel("Execution time [ms]");
            }
            else
            {
                plt.YLabel("Steps");
            }
            plt.XLabel("Difficulty");
            plt.Legend(location: legendLocation.upperRight);
            plt.Ticks(useExponentialNotation: false, useMultiplierNotation: false);
            plt.SaveFig(heuristicB + heuristicBF + type + "BvsBF" + ".png");
        }
Exemple #19
0
        public void Test_scatter_10kPoints()
        {
            double[]  pointCounts = { 10, 100, 1000, 10000 };
            const int REPS        = 10;

            double[] speeds = new double[pointCounts.Length];

            for (int i = 0; i < pointCounts.Length; i++)
            {
                int      pointCount = (int)pointCounts[i];
                var      plt        = new ScottPlot.Plot();
                Random   rand       = new Random(0);
                double[] xs         = DataGen.Random(rand, pointCount);
                double[] ys         = DataGen.RandomWalk(rand, pointCount);
                plt.AddScatter(xs, ys);
                plt.Render(lowQuality: true);

                List <double> times = new List <double>();
                for (int j = 0; j < REPS; j++)
                {
                    plt.Render(lowQuality: true);
                    times.Add(plt.GetSettings(false).BenchmarkMessage.MSec);
                }

                var stats = new ScottPlot.Statistics.Population(times.ToArray());
                speeds[i] = stats.mean;
                Console.WriteLine($"Rendered {pointCount} points in {stats.mean} ms");
            }

            var plt2 = new ScottPlot.Plot(400, 300);

            plt2.Title("Scatter Plot Benchmark");
            plt2.YLabel("Time (ms)");
            plt2.XLabel("Number of Points");
            plt2.AddScatter(pointCounts, speeds);
            TestTools.SaveFig(plt2);
        }
        private void MakeAPlot(double[,] data, double[,] dataEmp)
        {
            var plt = new ScottPlot.Plot(1000, 800);

            double[] x, y1, y2, y3, y4, empX, empY1, empY2, empY3, empY4;
            int      linewidth = 2, markersize = 0;

            x  = GetColumn(data, 0);
            y1 = GetColumn(data, 1);
            y2 = GetColumn(data, 2);
            y3 = GetColumn(data, 3);
            y4 = GetColumn(data, 4);

            empX  = GetRow(dataEmp, 0);
            empY1 = GetRow(dataEmp, 1);
            empY2 = GetRow(dataEmp, 2);
            empY3 = GetRow(dataEmp, 3);
            empY4 = GetRow(dataEmp, 4);

            plt.PlotScatter(x, y1, markerSize: markersize, lineWidth: linewidth, color: System.Drawing.Color.Green, label: "Susceptible", lineStyle: LineStyle.Dot);
            plt.PlotScatter(x, y2, markerSize: markersize, lineWidth: linewidth, color: System.Drawing.Color.Red, label: "Infected", lineStyle: LineStyle.Dot);
            plt.PlotScatter(x, y3, markerSize: markersize, lineWidth: linewidth, color: System.Drawing.Color.Gray, label: "Vaccinated", lineStyle: LineStyle.Dot);
            plt.PlotScatter(x, y4, markerSize: markersize, lineWidth: linewidth, color: System.Drawing.Color.Blue, label: "Recovered", lineStyle: LineStyle.Dot);

            plt.PlotScatter(empX, empY1, markerSize: markersize, lineWidth: linewidth, color: System.Drawing.Color.Green, label: "Susceptible emp");
            plt.PlotScatter(empX, empY2, markerSize: markersize, lineWidth: linewidth, color: System.Drawing.Color.Red, label: "Infected emp");
            plt.PlotScatter(empX, empY3, markerSize: markersize, lineWidth: linewidth, color: System.Drawing.Color.Gray, label: "Vaccinated emp");
            plt.PlotScatter(empX, empY4, markerSize: markersize, lineWidth: linewidth, color: System.Drawing.Color.Blue, label: "Recovered emp");


            //plt.PlotAnnotation("Population: " + N + "\nβ = " + beta + "\nγ = " + gamma, 10, 10);
            plt.Legend();
            plt.XLabel("Time");
            plt.YLabel("Population");

            image.Source = CreateBitmapSourceFromGdiBitmap(plt.GetBitmap());
        }
        static void Main(string[] args)
        {
            //Read data
            var USDataReader = new USYieldDataXMLReader();

            USDataReader.filepath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\", "Data\\USDYieldCurveDailyData2020.xml"));
            var Data = USDataReader.GetFullTimeSeriesData();

            var yields = Data["2020-02-11"];
            var tau    = new double[12] {
                (double)1 / 12, (double)2 / 12, (double)3 / 12, (double)6 / 12, 1, 2, 3, 5, 7, 10, 20, 30
            };

            //// Test--------------------------------------- Static NS 3 factors model------------------------------------------------//
            //var NS3factorCalibration = new StaticNS3FactorModelCalibration();
            //NS3factorCalibration.yields = yields;
            //NS3factorCalibration.maturities = tau;
            //var optimziedpara = NS3factorCalibration.Calibration();
            //var modeloutput = NS3factorCalibration.CalculateModelOutput(tau, optimziedpara);
            //Console.WriteLine("NS 3 Factor Model Is Calibrated.");
            ////Plot
            //var plt = new ScottPlot.Plot(600, 400);
            //plt.PlotSignalXY(tau, yields, color: Color.Red, label: "Market Data");
            //plt.PlotSignalXY(tau, modeloutput, color: Color.Blue, label: "Model Output");
            //plt.Legend();
            //plt.XLabel("Time to maturity");
            //plt.YLabel("Annualized yields (%)");
            //var savepath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\", "Pictures\\NS3FactorModelEmpiricalResult.png"));
            //plt.SaveFig(savepath);
            //Process.Start(savepath);

            //// Test--------------------------------------- Static NS 4 factors model------------------------------------------------//
            //var NS4factorCalibration = new StaticNS4FactorModelCalibration();
            //NS4factorCalibration.yields = yields;
            //NS4factorCalibration.maturities = tau;
            //var optimziedpara2 = NS4factorCalibration.Calibration();
            //var modeloutput2 = NS4factorCalibration.CalculateModelOutput(tau, optimziedpara2);
            //Console.WriteLine("NS 4 Factor Model Is Calibrated.");
            ////Plot
            //var plt2 = new ScottPlot.Plot(600, 400);
            //plt2.PlotSignalXY(tau, yields, color: Color.Red, label: "Market Data");
            //plt2.PlotSignalXY(tau, modeloutput2, color: Color.Blue, label: "Model Output");
            //plt2.Legend();
            //plt2.XLabel("Time to maturity");
            //plt2.YLabel("Annualized yields (%)");
            //var savepath2 = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\", "Pictures\\NS4FactorModelEmpiricalResult.png"));
            //plt2.SaveFig(savepath2);
            //Process.Start(savepath2);
            //// Test--------------------------------------- Static Vasicek Two factors model------------------------------------------------//
            //var V2FactorCal = new StaticVasicekTwoFactorModelCalibration();
            //V2FactorCal.yields = yields;
            //V2FactorCal.maturities = tau;
            //var V2FactorOptPara = V2FactorCal.Calibration();
            //var V2Factor = new StaticVasicekTwoFactorModel();
            //V2Factor.maturities = tau;
            //var modeloutputV2 = V2FactorCal.CalcualteModelOutput(V2FactorOptPara);
            //Console.WriteLine("Vasicek 2 Factor Model Is Calibrated.");
            ////Plot
            //var pltv2 = new ScottPlot.Plot(600, 400);
            //pltv2.PlotSignalXY(tau, yields, color: Color.Red, label: "Market Data");
            //pltv2.PlotSignalXY(tau, modeloutputV2, color: Color.Blue, label: "Model Output");
            //pltv2.Legend();
            //pltv2.XLabel("Time to maturity");
            //pltv2.YLabel("Annualized yields (%)");
            //var savepathV2 = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\", "Pictures\\VasicekTwoFactorModelEmpiricalResult.png"));
            //pltv2.SaveFig(savepathV2);
            //Process.Start(savepathV2);
            // Test--------------------------------------- Static Longstaff Schwartz Two factors model------------------------------------------------//
            var LS2FactorCal = new StaticTwoFactorLongstaffSchwartzModelCalibration();

            LS2FactorCal.yields     = yields;
            LS2FactorCal.maturities = tau;
            var LS2FactorOptPara = LS2FactorCal.Calibration();
            var LS2Factor        = new StaticTwoFactorLongstaffSchwartzModel();

            LS2Factor.maturities = tau;
            var modeloutputLS2 = LS2FactorCal.CalcualteModelOutput(LS2FactorOptPara);

            Console.WriteLine("Longstaff Schwartz 2 Factor Model Is Calibrated.");
            //Plot
            var pltls2 = new ScottPlot.Plot(600, 400);

            pltls2.PlotSignalXY(tau, yields, color: Color.Red, label: "Market Data");
            pltls2.PlotSignalXY(tau, modeloutputLS2, color: Color.Blue, label: "Model Output");
            pltls2.Legend();
            pltls2.XLabel("Time to maturity");
            pltls2.YLabel("Annualized yields (%)");
            var savepathls2 = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\", "Pictures\\LongstaffSchwartzTwoFactorModelEmpiricalResult.png"));

            pltls2.SaveFig(savepathls2);
            Process.Start(savepathls2);

            ////Test dynamic NS3 factor model
            //var DynaimcNS3factor = new DynamicNS3FactorModelCalibration();
            //DynaimcNS3factor.yields = Data;
            //DynaimcNS3factor.maturities = tau;
            //var optimziedpara=DynaimcNS3factor.Optimize();
            //(var tvbeta1, var tvbeta2, var tvbeta3) = DynaimcNS3factor.GetDynamicBetas(optimziedpara);
            ////Plot
            //// Beta1
            //var pltbeta1 = new ScottPlot.Plot(600, 400);
            //pltbeta1.PlotSignal(tvbeta1, color: Color.Red, label: "Time-varying Beta1");
            //pltbeta1.Legend();
            //pltbeta1.XLabel("History Time");
            //pltbeta1.YLabel("Beta1");
            //var savepathbeta1 = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\", "Pictures\\DynamicNS3FactorModelBeta1.png"));
            //pltbeta1.SaveFig(savepathbeta1);
            //Process.Start(savepathbeta1);
            //// Beta2
            //var pltbeta2 = new ScottPlot.Plot(600, 400);
            //pltbeta2.PlotSignal(tvbeta2, color: Color.Red, label: "Time-varying Beta2");
            //pltbeta2.Legend();
            //pltbeta2.XLabel("History Time");
            //pltbeta2.YLabel("Beta2");
            //var savepathbeta2 = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\", "Pictures\\DynamicNS3FactorModelBeta2.png"));
            //pltbeta2.SaveFig(savepathbeta2);
            //Process.Start(savepathbeta2);
            //// Beta3
            //var pltbeta3 = new ScottPlot.Plot(600, 400);
            //pltbeta3.PlotSignal(tvbeta3, color: Color.Red, label: "Time-varying Beta3");
            //pltbeta3.Legend();
            //pltbeta3.XLabel("History Time");
            //pltbeta3.YLabel("Beta3");
            //var savepathbeta3 = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\", "Pictures\\DynamicNS3FactorModelBeta3.png"));
            //pltbeta3.SaveFig(savepathbeta3);
            //Process.Start(savepathbeta3);

            ////Test dynamic NS4 factor model
            //var DynaimcNS4factor = new DynamicNS4FactorModelCalibration();
            //DynaimcNS4factor.yields = Data;
            //DynaimcNS4factor.maturities = tau;
            //var optimziedpara = DynaimcNS4factor.Optimize();
            //(var tvbeta1, var tvbeta2, var tvbeta3, var tvbeta4) = DynaimcNS4factor.GetDynamicBetas(optimziedpara);
            ////Plot
            //// Beta1
            //var pltbeta1 = new ScottPlot.Plot(600, 400);
            //pltbeta1.PlotSignal(tvbeta1, color: Color.Red, label: "Time-varying Beta1");
            //pltbeta1.Legend();
            //pltbeta1.XLabel("History Time");
            //pltbeta1.YLabel("Beta1");
            //var savepathbeta1 = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\", "Pictures\\DynamicNS3FactorModelBeta1.png"));
            //pltbeta1.SaveFig(savepathbeta1);
            //Process.Start(savepathbeta1);
            //// Beta2
            //var pltbeta2 = new ScottPlot.Plot(600, 400);
            //pltbeta2.PlotSignal(tvbeta2, color: Color.Red, label: "Time-varying Beta2");
            //pltbeta2.Legend();
            //pltbeta2.XLabel("History Time");
            //pltbeta2.YLabel("Beta2");
            //var savepathbeta2 = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\", "Pictures\\DynamicNS3FactorModelBeta2.png"));
            //pltbeta2.SaveFig(savepathbeta2);
            //Process.Start(savepathbeta2);
            //// Beta3
            //var pltbeta3 = new ScottPlot.Plot(600, 400);
            //pltbeta3.PlotSignal(tvbeta3, color: Color.Red, label: "Time-varying Beta3");
            //pltbeta3.Legend();
            //pltbeta3.XLabel("History Time");
            //pltbeta3.YLabel("Beta3");
            //var savepathbeta3 = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\", "Pictures\\DynamicNS3FactorModelBeta3.png"));
            //pltbeta3.SaveFig(savepathbeta3);
            //Process.Start(savepathbeta3);
            //// Beta3
            //var pltbeta4 = new ScottPlot.Plot(600, 400);
            //pltbeta4.PlotSignal(tvbeta4, color: Color.Red, label: "Time-varying Beta4");
            //pltbeta4.Legend();
            //pltbeta4.XLabel("History Time");
            //pltbeta4.YLabel("Beta4");
            //var savepathbeta4 = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\", "Pictures\\DynamicNS3FactorModelBeta4.png"));
            //pltbeta4.SaveFig(savepathbeta4);
            //Process.Start(savepathbeta4);


            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
        private void btnSubmitHilos_Click(object sender, EventArgs e)
        {
            txtResFact.Clear();
            lblResponse.Text = "";
            BigInteger numero      = 0;
            int        iteraciones = 0;

            try
            {
                numero      = int.Parse(numeroFact.Text);
                iteraciones = int.Parse(numItera.Text);
            }
            catch (Exception)
            {
                numero      = 0;
                iteraciones = 0;
            }
            if (numero > 0 && iteraciones > 0)
            {
                txtResFact.Visible = false;
                Dictionary <double[], string> response = new Dictionary <double[], string>();
                lblError.Visible = false;
                string formated = string.Format("{0}", numero);
                //OBTENER Numero Hilos, Tiempo en ms , y el string con info completa
                response = Principal.ObtenerFactoriales(numero, iteraciones);
                //PARA GRAFICA
                var      plt     = new ScottPlot.Plot(600, 400);
                double[] tiempos = new double[response.Count];
                double[] hilos   = new double[response.Count];
                int      i       = 0;
                foreach (double[] val in response.Keys)
                {
                    hilos[i]   = val[0];
                    tiempos[i] = val[1];
                    i++;
                }
                plt.PlotScatter(hilos, tiempos);
                plt.Legend();

                plt.Title("Hilos vs Tiempo de Obtener Factorial");
                plt.YLabel("Tiempo(ms)");
                plt.XLabel("Hilos");
                string nombreImagen = string.Format("../../{0}_{1}_Grafica.png", numero, iteraciones);
                try
                {
                    plt.SaveFig(nombreImagen);
                    lblConfirmed.Text = "Se ha guardado la gráfica en png";
                }
                catch (Exception)
                {
                    lblConfirmed.Text = "No se ha podido guardar la información";
                }
                lblConfirmed.Visible = true;
                //IMPRIMIR EN FORMS
                foreach (string val in response.Values)
                {
                    lblResponse.Text += string.Format($"{val} \n");
                    Console.WriteLine(val);
                }
            }
            else
            {
                lblError.Visible = true;
            }
        }