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); } }
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"); }
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); }
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); }
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_PlottablePopulations_Series() { // This example will display age, grouped by location. // This example has 1 series that contains 5 population objects. // for this example we will simulate countries by creating random data Random rand = new Random(0); var ages = new Population[] { new Population(rand, 54, 53, 5), // africa new Population(rand, 35, 72, 3), // americas new Population(rand, 48, 72, 4), // asia new Population(rand, 44, 78, 2), // europe new Population(rand, 14, 81, 1), // oceania }; var customPlottable = new PlottablePopulations(ages, color: System.Drawing.Color.CornflowerBlue); // plot the multi-series var plt = new ScottPlot.Plot(); plt.Add(customPlottable); plt.XTicks(labels: new string[] { "Africas", "Americas", "Asia", "Europe", "Oceania" }); plt.Ticks(fontSize: 18); // additional plot styling plt.Title("Life Expectancy in 2007", fontSize: 26); plt.YLabel("Age (years)", fontSize: 18); plt.Legend(location: legendLocation.lowerRight); plt.Grid(lineStyle: LineStyle.Dot, enableVertical: false); 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); }
public void Test_PlottablePopulations_Population() { // This example will display a single population: mean age of every country in europe in 2007 // This example has 1 series that contains 1 population. // for this example we will simulate countries by creating random data Random rand = new Random(0); var ages = new Population(rand, 44, 78, 2); var customPlottable = new PopulationPlot(ages); // plot the multi-series var plt = new ScottPlot.Plot(400, 300); plt.Add(customPlottable); plt.XAxis.Ticks(false); // additional plot styling plt.Title("Life Expectancy in European Countries in 2007"); plt.YLabel("Age (years)"); plt.Legend(location: Alignment.LowerRight); plt.Grid(lineStyle: LineStyle.Dot); plt.XAxis.Grid(false); TestTools.SaveFig(plt); }
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 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"); }
/// <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 }); }
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); }
public void GenerateMultipleBoxAndWhiskers(List <List <ResultModel> > allResults, List <int> xValues, string plotTitle, string plotName = "results") { var plt = new ScottPlot.Plot(600, 400); var poulations = new ScottPlot.Statistics.Population[allResults.Count]; var p = 0; foreach (var results in allResults) { var ys = new double[results.Count]; var i = 0; foreach (var r in results) { ys[i] = r.Fitness; i++; } var pop = new ScottPlot.Statistics.Population(ys); poulations[p] = pop; p++; } var popSeries = new ScottPlot.Statistics.PopulationSeries(poulations); plt.PlotPopulations(popSeries, "scores"); // improve the style of the plot plt.Title(plotTitle); plt.YLabel("Solution energy"); var ticks = new string[xValues.Count]; var j = 0; foreach (var iterations in xValues) { ticks[j] = iterations.ToString(); j++; } plt.XTicks(ticks); plt.Legend(); plt.Grid(lineStyle: LineStyle.Dot, enableVertical: false); plt.SaveFig($"{plotName}.png"); }
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); }
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); }
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()); }
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 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; } }
public void Test_PlottablePopulations_MultiSeries() { // This example will display age, grouped by location, and by year. // This example has 3 series (years), each of which has 5 population objects (locations). // for this example we will simulate countries by creating random data Random rand = new Random(0); // start by collecting series data as Population[] arrays var ages1957 = new Population[] { new Population(rand, 54, 42, 4), // africa new Population(rand, 35, 56, 6), // americas new Population(rand, 48, 47, 5), // asia new Population(rand, 44, 66, 2), // europe new Population(rand, 14, 70, 1), // oceania }; var ages1987 = new Population[] { new Population(rand, 54, 52, 8), // africa new Population(rand, 35, 70, 3), // americas new Population(rand, 48, 66, 3), // asia new Population(rand, 44, 75, 2), // europe new Population(rand, 14, 75, 1), // oceania }; var ages2007 = new Population[] { new Population(rand, 54, 53, 5), // africa new Population(rand, 35, 72, 3), // americas new Population(rand, 48, 72, 4), // asia new Population(rand, 44, 78, 2), // europe new Population(rand, 14, 81, 1), // oceania }; // now create a PopulationSeries object for each series string[] groupLabels = new string[] { "Africa", "Americas", "Asia", "Europe", "Oceania" }; var series1957 = new PopulationSeries(ages1957, "1957", color: System.Drawing.Color.Red); var series1987 = new PopulationSeries(ages1987, "1987", color: System.Drawing.Color.Green); var series2007 = new PopulationSeries(ages2007, "2007", color: System.Drawing.Color.Blue); // now collect all the series into a MultiSeries var multiSeries = new PopulationSeries[] { series1957, series1987, series2007 }; var plottableMultiSeries = new PopulationMultiSeries(multiSeries); var customPlottable = new PlottablePopulations(plottableMultiSeries); // plot the multi-series var plt = new ScottPlot.Plot(); plt.Add(customPlottable); plt.XTicks(labels: groupLabels); plt.Ticks(fontSize: 18); // additional plot styling plt.Title("Life Expectancy", fontSize: 26); plt.YLabel("Age (years)", fontSize: 18); plt.Legend(location: legendLocation.lowerRight); plt.Grid(lineStyle: LineStyle.Dot, enableVertical: false); TestTools.SaveFig(plt); }
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(); }
public static string chart(string pair) { List <string> pena = new List <string>(); System.Net.WebClient wc1 = new System.Net.WebClient(); int sum_chart = 150; double last_price = 0; String link_Response = wc1.DownloadString("https://www.binance.com/api/v1/klines?symbol=" + pair + "&interval=15m&limit=" + sum_chart); MatchCollection matchList = System.Text.RegularExpressions.Regex.Matches(link_Response, @"(\d+.\d+)|\d+\d+|\d"); pena = matchList.Cast <Match>().Select(match => match.Value).ToList(); System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); int count = 0; int count_draw = 0; //Оишбка в апи hbc в конце несколкьо нулей 0 0 0 0 0 //введен костыль-переменная ScottPlot.OHLC[] ohlcs = new ScottPlot.OHLC[sum_chart]; var plt = new ScottPlot.Plot(800, 400); for (int i = 0; i < sum_chart; i++) { double Open = Convert.ToDouble(pena[count_draw + 1]); double High = Convert.ToDouble(pena[count_draw + 2]); double Low = Convert.ToDouble(pena[count_draw + 3]); double Close = Convert.ToDouble(pena[count_draw + 4]); double Opentime = ((Convert.ToDouble(pena[count_draw])) / 1000) + (3600 * 3); ohlcs[count] = new ScottPlot.OHLC(Open, High, Low, Close, ConvertFromUnixTimestamp(Opentime), 1); count_draw = count_draw + 12; count++; last_price = Close; } plt.Title("15 Minute Chart"); plt.YLabel("Stock Price (" + pair + ")"); plt.Ticks(dateTimeX: true, dateTimeFormatStringX: "HH:mm:ss", numericFormatStringY: "n"); plt.PlotCandlestick(ohlcs); plt.Style(tick: Color.White, label: Color.White, title: Color.White, dataBg: Color.FromArgb(255, 36, 43, 60), grid: Color.FromArgb(255, 36, 43, 60), figBg: Color.FromArgb(255, 36, 43, 60)); DateTime date1 = new DateTime(); date1 = DateTime.Now; string name = "PlotTypes" + pair + "№" + date1.Ticks + ".png"; string name_file = name; string label_name = Convert.ToString(last_price); plt.PlotHLine(y: last_price, color: Color.Green, lineWidth: 0.5, label: label_name); plt.Legend(backColor: Color.FromArgb(255, 36, 43, 60), location: legendLocation.upperCenter); plt.SaveFig(name_file); return(name_file); }