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);
        }
示例#2
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);
        }
示例#3
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);
        }
示例#4
0
        public void ExecuteRecipe(Plot plt)
        {
            OHLC[] prices = DataGen.RandomStockPrices(null, 30, TimeSpan.FromMinutes(5));
            var    fp     = plt.AddCandlesticks(prices);

            fp.WickColor = Color.Black;
        }
示例#5
0
        public void ExecuteRecipe(Plot plt)
        {
            OHLC[] prices = DataGen.RandomStockPrices(null, 60, TimeSpan.FromDays(1));

            // add the OHLCs to the plot and the horizontal axis to display DateTime tick labels
            plt.AddCandlesticks(prices);
            plt.XAxis.DateTimeFormat(true);
        }
示例#6
0
 public void Render(Plot plt)
 {
     ScottPlot.OHLC[] ohlcs = DataGen.RandomStockPrices(rand: null, pointCount: 60, deltaMinutes: 10);
     plt.Title("Open/High/Low/Close (OHLC) Chart");
     plt.YLabel("Stock Price (USD)");
     plt.PlotOHLC(ohlcs);
     plt.Ticks(dateTimeX: true);
 }
示例#7
0
 public void Render(Plot plt)
 {
     ScottPlot.OHLC[] ohlcs = DataGen.RandomStockPrices(rand: null, pointCount: 60, deltaMinutes: 10);
     plt.Title("Ten Minute Candlestick Chart");
     plt.YLabel("Stock Price (USD)");
     plt.PlotCandlestick(ohlcs);
     plt.Ticks(dateTimeX: true);
 }
示例#8
0
        public void ExecuteRecipe(Plot plt)
        {
            OHLC[] prices = DataGen.RandomStockPrices(null, 30, TimeSpan.FromMinutes(5));
            plt.AddCandlesticks(prices);
            plt.XAxis.DateTimeFormat(true);

            plt.YAxis.Ticks(false);
            plt.YAxis2.Ticks(true);
            plt.YAxis2.Label("Price (USD)");
        }
示例#9
0
        public void ExecuteRecipe(Plot plt)
        {
            OHLC[] prices = DataGen.RandomStockPrices(null, 30);
            plt.AddCandlesticks(prices);

            // manually indicate where axis ticks should be and what their labels should say
            double[] tickPositions = { 0, 6, 13, 20, 27 };
            string[] tickLabels    = { "Sep 23", "Sep 30", "Oct 7", "Oct 14", "Oct 21" };
            plt.XTicks(tickPositions, tickLabels);
        }
示例#10
0
        public void ExecuteRecipe(Plot plt)
        {
            OHLC[] ohlcs      = DataGen.RandomStockPrices(null, 100);
            var    candlePlot = plt.AddCandlesticks(ohlcs);

            var bol = candlePlot.GetBollingerBands(20);

            plt.AddScatterLines(bol.xs, bol.sma, Color.Blue);
            plt.AddScatterLines(bol.xs, bol.lower, Color.Blue, lineStyle: LineStyle.Dash);
            plt.AddScatterLines(bol.xs, bol.upper, Color.Blue, lineStyle: LineStyle.Dash);
        }
示例#11
0
        public void Test_AutoAxis_CandlestickSinglePoint()
        {
            var plt = new ScottPlot.Plot();

            plt.PlotCandlestick(DataGen.RandomStockPrices(rand: null, pointCount: 1));

            var limits = plt.GetAxisLimits();

            Assert.Greater(limits.XSpan, 0);
            Assert.Greater(limits.YSpan, 0);
        }
示例#12
0
        public void ExecuteRecipe(Plot plt)
        {
            OHLC[] ohlcs      = DataGen.RandomStockPrices(null, 75);
            var    candlePlot = plt.AddCandlesticks(ohlcs);

            var sma8 = candlePlot.GetSMA(8);

            plt.AddScatterLines(sma8.xs, sma8.ys, Color.Blue, 2);

            var sma20 = candlePlot.GetSMA(20);

            plt.AddScatterLines(sma20.xs, sma20.ys, Color.Navy, 2);
        }
示例#13
0
        public void ExecuteRecipe(Plot plt)
        {
            // add some random candles
            OHLC[]   prices     = DataGen.RandomStockPrices(null, 100, TimeSpan.FromMinutes(5));
            double[] xs         = prices.Select(x => x.DateTime.ToOADate()).ToArray();
            var      candlePlot = plt.AddCandlesticks(prices);

            candlePlot.YAxisIndex = 1;

            plt.XAxis.DateTimeFormat(true);

            // add SMA indicators for 8 and 20 days
            var sma8      = candlePlot.GetSMA(8);
            var sma20     = candlePlot.GetSMA(20);
            var sma8plot  = plt.AddScatterLines(sma8.xs, sma8.ys, Color.Cyan, 2, label: "8 day SMA");
            var sma20plot = plt.AddScatterLines(sma20.xs, sma20.ys, Color.Yellow, 2, label: "20 day SMA");

            sma8plot.YAxisIndex  = 1;
            sma20plot.YAxisIndex = 1;

            // customize candle styling
            candlePlot.ColorDown = ColorTranslator.FromHtml("#00FF00");
            candlePlot.ColorUp   = ColorTranslator.FromHtml("#FF0000");

            // customize figure styling
            plt.Layout(padding: 12);
            plt.Style(figureBackground: Color.Black, dataBackground: Color.Black);
            plt.Frameless();
            plt.XAxis.TickLabelStyle(color: Color.White);
            plt.XAxis.TickMarkColor(ColorTranslator.FromHtml("#333333"));
            plt.XAxis.MajorGrid(color: ColorTranslator.FromHtml("#333333"));

            // hide the left axis and show a right axis
            plt.YAxis.Ticks(false);
            plt.YAxis.Grid(false);
            plt.YAxis2.Ticks(true);
            plt.YAxis2.Grid(true);
            plt.YAxis2.TickLabelStyle(color: ColorTranslator.FromHtml("#00FF00"));
            plt.YAxis2.TickMarkColor(ColorTranslator.FromHtml("#333333"));
            plt.YAxis2.MajorGrid(color: ColorTranslator.FromHtml("#333333"));

            // customize the legend style
            var legend = plt.Legend();

            legend.FillColor    = Color.Transparent;
            legend.OutlineColor = Color.Transparent;
            legend.Font.Color   = Color.White;
            legend.Font.Bold    = true;
        }
示例#14
0
        public void ExecuteRecipe(Plot plt)
        {
            // generate sample stock prices
            OHLC[]   ohlcs = DataGen.RandomStockPrices(null, 100);
            double[] xs    = DataGen.Consecutive(ohlcs.Length);

            // calculate the bands and the time range they cover
            double[] xs2 = xs.Skip(20).ToArray();
            (var sma, var bolL, var bolU) = Statistics.Finance.Bollinger(ohlcs, 20);

            // plot technical indicators as scatter plots above the financial chart
            plt.AddCandlesticks(ohlcs);
            plt.AddScatter(xs2, sma, markerSize: 0, color: Color.Blue);
            plt.AddScatter(xs2, bolL, markerSize: 0, color: Color.Blue, lineStyle: LineStyle.Dash);
            plt.AddScatter(xs2, bolU, markerSize: 0, color: Color.Blue, lineStyle: LineStyle.Dash);
        }
示例#15
0
        public void ExecuteRecipe(Plot plt)
        {
            // generate sample stock prices
            OHLC[]   ohlcs = DataGen.RandomStockPrices(null, 75);
            double[] xs    = DataGen.Consecutive(ohlcs.Length);

            // calculate SMAs of different durations using helper methods
            double[] sma8xs  = xs.Skip(8).ToArray();
            double[] sma8ys  = Statistics.Finance.SMA(ohlcs, 8);
            double[] sma20xs = xs.Skip(20).ToArray();
            double[] sma20ys = Statistics.Finance.SMA(ohlcs, 20);

            // plot technical indicators as scatter plots above the financial chart
            plt.AddCandlesticks(ohlcs);
            plt.AddScatter(sma8xs, sma8ys, markerSize: 0, color: Color.Blue, lineWidth: 2);
            plt.AddScatter(sma20xs, sma20ys, markerSize: 0, color: Color.Navy, lineWidth: 2);
        }
示例#16
0
            public void Render(Plot plt)
            {
                Random rand = new Random(0);

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

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

                // decorate the plot
                plt.Title("Bollinger Bands");
                plt.YLabel("Stock Price (USD)");
                plt.XLabel("Day");
                plt.Legend();
            }
示例#17
0
            public void Render(Plot plt)
            {
                Random rand = new Random(0);

                ScottPlot.OHLC[] ohlcs = DataGen.RandomStockPrices(rand, 75, sequential: true);
                double[]         xs    = DataGen.Consecutive(ohlcs.Length);
                double[]         sma20 = Statistics.Finance.SMA(ohlcs, 8);
                double[]         sma50 = Statistics.Finance.SMA(ohlcs, 20);

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

                // decorate the plot
                plt.Title("Simple Moving Averages (SMA)");
                plt.YLabel("Stock Price (USD)");
                plt.XLabel("Day");
                plt.Legend();
            }
示例#18
0
            public void Render(Plot plt)
            {
                // start with stock prices which have unevenly spaced time points (weekends are skipped)
                ScottPlot.OHLC[] ohlcs = DataGen.RandomStockPrices(rand: null, pointCount: 30);

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

                // plot the candlesticks (the horizontal axis will start at 0)
                plt.Title("Daily Candlestick Chart (evenly spaced)");
                plt.YLabel("Stock Price (USD)");
                plt.PlotCandlestick(ohlcs);

                // create ticks manually
                double[] tickPositions = { 0, 6, 13, 20, 27 };
                string[] tickLabels    = { "Sep 23", "Sep 30", "Oct 7", "Oct 14", "Oct 21" };
                plt.XTicks(tickPositions, tickLabels);
            }
示例#19
0
        public MainWindow()
        {
            InitializeComponent();

            var one = new DoubleModel(
                wpfPlot1,
                DataSource.ObserveValues(),
                Observable.Interval(TimeSpan.FromMilliseconds(150)).ObserveOnDispatcher().Select(a => Unit.Default));

            var two = new OHLCModel(
                wpfPlot2,
                DataSource.ObserveOHLCValues(),
                Observable.Interval(TimeSpan.FromMilliseconds(1000)).ObserveOnDispatcher().Select(a => Unit.Default));

            var three = new DoubleModel(wpfPlot3, DataSource.ObserveValues());

            PlotView1.Data = DataGen.RandomStockPrices(new Random(), 200, sequential: true);

            wpfPlot4.Children.Add(new WpfPlot(PlotFactory.CreateHistogramPlot()));

            wpfPlot5.Children.Add(new WpfPlot(PlotFactory.CreateAdvancedStatisticsPlot()));
        }
示例#20
0
 public void ExecuteRecipe(Plot plt)
 {
     // OHLCs are open, high, low, and closing prices for a time range.
     OHLC[] prices = DataGen.RandomStockPrices(null, 60);
     plt.AddCandlesticks(prices);
 }
示例#21
0
 public DataFactory()
 {
     ohlcs = DataGen.RandomStockPrices(rand, 20000, sequential: true);
 }
示例#22
0
 public void ExecuteRecipe(Plot plt)
 {
     OHLC[] prices = DataGen.RandomStockPrices(null, 60);
     plt.AddOHLCs(prices);
 }