Beispiel #1
0
        public static void Main(string[] args)
        {
            // Getting the time series
            TimeSeries series = CsvTradesLoader.loadBitstampSeries();
            // Building the trading strategy
            Strategy strategy = MovingMomentumStrategy.buildStrategy(series);

            /// <summary>
            /// Building chart datasets
            /// </summary>
            TimeSeriesCollection dataset = new TimeSeriesCollection();

            dataset.addSeries(buildChartTimeSeries(series, new ClosePriceIndicator(series), "Bitstamp Bitcoin (BTC)"));

            /// <summary>
            /// Creating the chart
            /// </summary>
            JFreeChart chart = ChartFactory.createTimeSeriesChart("Bitstamp BTC", "Date", "Price", dataset, true, true, false);             // generate URLs? -  generate tooltips? -  create legend? -  data -  y-axis label -  x-axis label -  title
            XYPlot     plot  = (XYPlot)chart.Plot;
            DateAxis   axis  = (DateAxis)plot.DomainAxis;

            axis.DateFormatOverride = new SimpleDateFormat("MM-dd HH:mm");

            /// <summary>
            /// Running the strategy and adding the buy and sell signals to plot
            /// </summary>
            addBuySellSignals(series, strategy, plot);

            /// <summary>
            /// Displaying the chart
            /// </summary>
            displayChart(chart);
        }
        protected override void InitExample()
        {
            var xAxis = new DateAxis(Activity)
            {
                GrowBy = new DoubleRange(0, 0.1)
            };
            var yAxis = new NumericAxis(Activity)
            {
                GrowBy = new DoubleRange(0, 0.1)
            };

            var dataSeries      = new XyzDataSeries <DateTime, double, double>();
            var tradeDataSource = DataManager.Instance.GetTradeticks().ToArray();

            dataSeries.Append(
                tradeDataSource.Select(x => x.TradeDate),
                tradeDataSource.Select(x => x.TradePrice),
                tradeDataSource.Select(x => x.TradeSize));

            var lineSeries = new FastLineRenderableSeries
            {
                DataSeries  = dataSeries,
                StrokeStyle = new SolidPenStyle(0xFFFF3333, 1.ToDip(Activity))
            };

            var bubbleSeries = new FastBubbleRenderableSeries
            {
                DataSeries       = dataSeries,
                BubbleBrushStyle = new SolidBrushStyle(0x77CCCCCC),
                StrokeStyle      = new SolidPenStyle(0xFFCCCCCC, 2f.ToDip(Activity)),
                ZScaleFactor     = 3,
                AutoZRange       = false,
            };

            using (Surface.SuspendUpdates())
            {
                Surface.XAxes.Add(xAxis);
                Surface.YAxes.Add(yAxis);
                Surface.RenderableSeries.Add(lineSeries);
                Surface.RenderableSeries.Add(bubbleSeries);
                Surface.ChartModifiers = new ChartModifierCollection
                {
                    new RubberBandXyZoomModifier(),
                    new ZoomExtentsModifier(),
                };

                new ScaleAnimatorBuilder(lineSeries, 10600d)
                {
                    Interpolator = new OvershootInterpolator(), Duration = 1000, StartDelay = 600
                }.Start();
                new ScaleAnimatorBuilder(bubbleSeries, 10600d)
                {
                    Interpolator = new OvershootInterpolator(), Duration = 1000, StartDelay = 600
                }.Start();
            }
        }
        protected override void InitExample()
        {
            var dataSeries      = new XyzDataSeries <DateTime, double, double>();
            var tradeDataSource = DataManager.Instance.GetTradeticks().ToArray();

            dataSeries.Append(
                tradeDataSource.Select(x => x.TradeDate),
                tradeDataSource.Select(x => x.TradePrice),
                tradeDataSource.Select(x => x.TradeSize));

            var xAxis = new DateAxis(Activity)
            {
                GrowBy = new DoubleRange(0, 0.1)
            };
            var yAxis = new NumericAxis(Activity)
            {
                GrowBy = new DoubleRange(0, 0.1)
            };

            var lineSeries = new FastLineRenderableSeries
            {
                DataSeries  = dataSeries,
                StrokeStyle = new PenStyle.Builder(Activity).WithColor(Color.Rgb(0xFF, 0x33, 0x33))
                              .WithThickness(1f, ComplexUnitType.Dip).Build()
            };

            var stops        = new[] { 0, 0.95f, 1 };
            var colors       = new int[] { Color.Transparent, Resources.GetColor(Resource.Color.color_primary), Color.Transparent };
            var gradientFill = new RadialGradientBrushStyle(0.5f, 0.5f, 0.5f, 0.5f, colors, stops, TileMode.Clamp);

            var bubbleSeries = new FastBubbleRenderableSeries
            {
                DataSeries       = dataSeries,
                BubbleBrushStyle = gradientFill,
                ZScaleFactor     = 3,
                AutoZRange       = false,
            };

            using (Surface.SuspendUpdates())
            {
                Surface.XAxes.Add(xAxis);
                Surface.YAxes.Add(yAxis);
                Surface.RenderableSeries.Add(lineSeries);
                Surface.RenderableSeries.Add(bubbleSeries);

                Surface.ChartModifiers = new ChartModifierCollection
                {
                    new RubberBandXyZoomModifier(),
                    new ZoomExtentsModifier(),
                };
            }
        }
Beispiel #4
0
        protected override void InitExample()
        {
            var xAxis = new DateAxis(Activity)
            {
                GrowBy = new DoubleRange(0.1, 0.1)
            };
            var yAxis = new NumericAxis(Activity)
            {
                GrowBy = new DoubleRange(0.1, 0.1)
            };

            var priceData  = DataManager.Instance.GetPriceDataIndu();
            var dataSeries = new XyDataSeries <DateTime, double>();

            dataSeries.Append(priceData.TimeData, priceData.CloseData);

            var rSeries = new FastMountainRenderableSeries
            {
                DataSeries  = dataSeries,
                StrokeStyle = new SolidPenStyle(0xAAFFC9A8, 2f.ToDip(Activity)),
                AreaStyle   = new LinearGradientBrushStyle(0, 0, 1, 1, 0xAAFF8D42, 0x88090E11)
            };

            using (Surface.SuspendUpdates())
            {
                Surface.XAxes.Add(xAxis);
                Surface.YAxes.Add(yAxis);
                Surface.RenderableSeries.Add(rSeries);
                Surface.ChartModifiers = new ChartModifierCollection
                {
                    new ZoomPanModifier(),
                    new PinchZoomModifier(),
                    new ZoomExtentsModifier(),
                };

                new WaveAnimatorBuilder(rSeries)
                {
                    Interpolator = new DecelerateInterpolator(), Duration = 3000, StartDelay = 350
                }.Start();
            }
        }
Beispiel #5
0
        protected override void InitExample()
        {
            var priceData = DataManager.Instance.GetPriceDataIndu();

            var dataSeries = new XyDataSeries <DateTime, double>();

            dataSeries.Append(priceData.TimeData, priceData.CloseData);

            var xAxis = new DateAxis(Activity)
            {
                GrowBy = new DoubleRange(0.1, 0.1)
            };
            var yAxis = new NumericAxis(Activity)
            {
                GrowBy = new DoubleRange(0.1, 0.1)
            };

            var renderableSeries = new FastMountainRenderableSeries
            {
                DataSeries  = dataSeries,
                StrokeStyle = new PenStyle.Builder(Activity).WithColor(Color.Argb(0xAA, 0xFF, 0xC9, 0xA8)).WithThickness(2, ComplexUnitType.Dip).Build(),
                AreaStyle   = new LinearGradientBrushStyle(0, 0, 1, 1, Color.Argb(0xAA, 0xFF, 0x8D, 0x42), Color.Argb(0x88, 0x09, 0x0E, 0x11), TileMode.Clamp)
            };

            using (Surface.SuspendUpdates())
            {
                Surface.XAxes.Add(xAxis);
                Surface.YAxes.Add(yAxis);
                Surface.RenderableSeries.Add(renderableSeries);

                Surface.ChartModifiers = new ChartModifierCollection
                {
                    new ZoomPanModifier(),
                    new PinchZoomModifier(),
                    new ZoomExtentsModifier(),
                };
            }
        }
        private void InitializeGraph(Context context)
        {
            // init shared resources
            var oxygenColor      = Android.Graphics.Color.Blue;
            var temperatureColor = Android.Graphics.Color.Red;
            var pressureColor    = Android.Graphics.Color.Teal;

            var thickness = 1.5f * Resources.DisplayMetrics.Density;
            var fontSize  = 14f * Resources.DisplayMetrics.Density;

            // init surface
            ChartSurface = new SciChartSurface(context)
            {
                RenderableSeriesAreaBorderStyle = new SolidPenStyle(Color.Black, 0)
            };

            // init axes
            var dateAxis = new DateAxis(context)
            {
                AutoRange          = NativeControl.IsZoomable ? AutoRange.Once : AutoRange.Always,
                GrowBy             = new DoubleRange(0.05, 0.05),
                DrawMinorGridLines = false,
                TickLabelStyle     = new FontStyle(fontSize, Color.Black),
                TitleStyle         = new FontStyle(fontSize, Color.Black),
                AxisId             = X_AXIS_ID
            };
            var oxygenAxis = new NumericAxis(context)
            {
                AutoRange          = NativeControl.IsZoomable ? AutoRange.Once : AutoRange.Always,
                AxisAlignment      = AxisAlignment.Left,
                GrowBy             = new DoubleRange(0.05, 0.05),
                AxisId             = OXYGEN_AXIS_ID,
                AxisTitle          = "Oxygen",
                Visibility         = ConvertBoolToInt(NativeControl.IsOxygenVisible),
                TickLabelStyle     = new FontStyle(fontSize, oxygenColor),
                TitleStyle         = new FontStyle(fontSize, oxygenColor),
                DrawMinorGridLines = false,
                IsPrimaryAxis      = true,
            };
            var temperatureAxis = new NumericAxis(context)
            {
                AutoRange          = NativeControl.IsZoomable ? AutoRange.Once : AutoRange.Always,
                AxisAlignment      = AxisAlignment.Right,
                GrowBy             = new DoubleRange(0.05, 0.05),
                AxisId             = TEMPERATURE_AXIS_ID,
                AxisTitle          = "Temperature",
                Visibility         = ConvertBoolToInt(NativeControl.IsTemperatureVisible),
                TickLabelStyle     = new FontStyle(fontSize, temperatureColor),
                TitleStyle         = new FontStyle(fontSize, temperatureColor),
                DrawMinorGridLines = false,
                IsPrimaryAxis      = false
            };
            var pressureAxis = new NumericAxis(context)
            {
                AutoRange          = NativeControl.IsZoomable ? AutoRange.Once : AutoRange.Always,
                AxisAlignment      = AxisAlignment.Right,
                GrowBy             = new DoubleRange(0.05, 0.05),
                AxisId             = PRESSURE_AXIS_ID,
                AxisTitle          = "Pressure",
                Visibility         = ConvertBoolToInt(NativeControl.IsPressureVisible),
                TickLabelStyle     = new FontStyle(fontSize, pressureColor),
                TitleStyle         = new FontStyle(fontSize, pressureColor),
                DrawMinorGridLines = false,
                IsPrimaryAxis      = false
            };

            // init data
            _oxygenData = new XyDataSeries <DateTime, double> {
                SeriesName = "Oxygen"
            };
            _temperatureData = new XyDataSeries <DateTime, double> {
                SeriesName = "Temperature"
            };
            _pressureData = new XyDataSeries <DateTime, double> {
                SeriesName = "Pressure"
            };

            // init series
            _oxygenSeries = new FastLineRenderableSeries
            {
                XAxisId     = X_AXIS_ID,
                YAxisId     = OXYGEN_AXIS_ID,
                DataSeries  = _oxygenData,
                IsVisible   = NativeControl.IsOxygenVisible,
                StrokeStyle = new SolidPenStyle(oxygenColor.ToSystemColor(), thickness)
            };
            _temperatureSeries = new FastLineRenderableSeries
            {
                XAxisId     = X_AXIS_ID,
                YAxisId     = TEMPERATURE_AXIS_ID,
                DataSeries  = _temperatureData,
                IsVisible   = NativeControl.IsTemperatureVisible,
                StrokeStyle = new SolidPenStyle(temperatureColor.ToSystemColor(), thickness)
            };
            _pressureSeries = new FastLineRenderableSeries
            {
                XAxisId     = X_AXIS_ID,
                YAxisId     = PRESSURE_AXIS_ID,
                DataSeries  = _pressureData,
                IsVisible   = NativeControl.IsPressureVisible,
                StrokeStyle = new SolidPenStyle(pressureColor.ToSystemColor(), thickness)
            };

            // add chart components to chart
            ChartSurface.XAxes.Add(dateAxis);
            ChartSurface.YAxes.Add(oxygenAxis);
            ChartSurface.YAxes.Add(temperatureAxis);
            ChartSurface.YAxes.Add(pressureAxis);
            ChartSurface.RenderableSeries.Add(_oxygenSeries);
            ChartSurface.RenderableSeries.Add(_temperatureSeries);
            ChartSurface.RenderableSeries.Add(_pressureSeries);

            // apply theme
            ChartSurface.Theme = Resource.Style.SciChart_Bright_Spark;

            // add modifiers
            if (NativeControl.IsZoomable)
            {
                ChartSurface.ChartModifiers = new ChartModifierCollection
                {
                    new ZoomPanModifier()
                    {
                        ClipModeX    = ClipMode.None,
                        ClipModeY    = ClipMode.None,
                        ZoomExtentsY = false
                    },
                    new PinchZoomModifier()
                    {
                        Direction = Direction2D.XyDirection
                    },
                    new ZoomExtentsModifier
                    {
                        IsAnimated = true
                    }
                };
            }

            // load!
            AddView(ChartSurface);
        }
 public static JFreeChart createGanttChart(string title, string categoryAxisLabel, string dateAxisLabel, IntervalCategoryDataset dataset, bool legend, bool tooltips, bool urls)
 {
   int num1 = tooltips ? 1 : 0;
   int num2 = urls ? 1 : 0;
   int num3 = legend ? 1 : 0;
   CategoryAxis domainAxis = new CategoryAxis(categoryAxisLabel);
   DateAxis dateAxis = new DateAxis(dateAxisLabel);
   GanttRenderer ganttRenderer = new GanttRenderer();
   if (num1 != 0)
     ganttRenderer.setBaseToolTipGenerator((CategoryToolTipGenerator) new IntervalCategoryToolTipGenerator("{3} - {4}", DateFormat.getDateInstance()));
   if (num2 != 0)
     ganttRenderer.setBaseItemURLGenerator((CategoryURLGenerator) new StandardCategoryURLGenerator());
   CategoryPlot categoryPlot = new CategoryPlot((CategoryDataset) dataset, domainAxis, (ValueAxis) dateAxis, (CategoryItemRenderer) ganttRenderer);
   categoryPlot.setOrientation(PlotOrientation.__\u003C\u003EHORIZONTAL);
   JFreeChart.__\u003Cclinit\u003E();
   JFreeChart jfc = new JFreeChart(title, JFreeChart.__\u003C\u003EDEFAULT_TITLE_FONT, (Plot) categoryPlot, num3 != 0);
   ChartFactory.currentTheme.apply(jfc);
   return jfc;
 }
 public static JFreeChart createXYStepChart(string title, string xAxisLabel, string yAxisLabel, XYDataset dataset, PlotOrientation orientation, bool legend, bool tooltips, bool urls)
 {
   int num1 = tooltips ? 1 : 0;
   int num2 = urls ? 1 : 0;
   int num3 = legend ? 1 : 0;
   if (orientation == null)
   {
     string str = "Null 'orientation' argument.";
     Throwable.__\u003CsuppressFillInStackTrace\u003E();
     throw new IllegalArgumentException(str);
   }
   else
   {
     DateAxis dateAxis = new DateAxis(xAxisLabel);
     NumberAxis numberAxis = new NumberAxis(yAxisLabel);
     numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
     StandardXYToolTipGenerator toolTipGenerator = (StandardXYToolTipGenerator) null;
     if (num1 != 0)
       toolTipGenerator = new StandardXYToolTipGenerator();
     StandardXYURLGenerator standardXyurlGenerator = (StandardXYURLGenerator) null;
     if (num2 != 0)
       standardXyurlGenerator = new StandardXYURLGenerator();
     XYStepRenderer xyStepRenderer = new XYStepRenderer((XYToolTipGenerator) toolTipGenerator, (XYURLGenerator) standardXyurlGenerator);
     XYPlot xyPlot = new XYPlot(dataset, (ValueAxis) dateAxis, (ValueAxis) numberAxis, (XYItemRenderer) null);
     xyPlot.setRenderer((XYItemRenderer) xyStepRenderer);
     xyPlot.setOrientation(orientation);
     xyPlot.setDomainCrosshairVisible(false);
     xyPlot.setRangeCrosshairVisible(false);
     JFreeChart.__\u003Cclinit\u003E();
     JFreeChart jfc = new JFreeChart(title, JFreeChart.__\u003C\u003EDEFAULT_TITLE_FONT, (Plot) xyPlot, num3 != 0);
     ChartFactory.currentTheme.apply(jfc);
     return jfc;
   }
 }
 public static JFreeChart createWindPlot(string title, string xAxisLabel, string yAxisLabel, WindDataset dataset, bool legend, bool tooltips, bool urls)
 {
   int num1 = tooltips ? 1 : 0;
   int num2 = urls ? 1 : 0;
   int num3 = legend ? 1 : 0;
   DateAxis dateAxis = new DateAxis(xAxisLabel);
   NumberAxis numberAxis = new NumberAxis(yAxisLabel);
   numberAxis.setRange(-12.0, 12.0);
   WindItemRenderer windItemRenderer = new WindItemRenderer();
   if (num1 != 0)
     windItemRenderer.setBaseToolTipGenerator((XYToolTipGenerator) new StandardXYToolTipGenerator());
   if (num2 != 0)
     windItemRenderer.setURLGenerator((XYURLGenerator) new StandardXYURLGenerator());
   XYPlot xyPlot = new XYPlot((XYDataset) dataset, (ValueAxis) dateAxis, (ValueAxis) numberAxis, (XYItemRenderer) windItemRenderer);
   JFreeChart.__\u003Cclinit\u003E();
   JFreeChart jfc = new JFreeChart(title, JFreeChart.__\u003C\u003EDEFAULT_TITLE_FONT, (Plot) xyPlot, num3 != 0);
   ChartFactory.currentTheme.apply(jfc);
   return jfc;
 }
 public static JFreeChart createBoxAndWhiskerChart(string title, string timeAxisLabel, string valueAxisLabel, BoxAndWhiskerXYDataset dataset, bool legend)
 {
   int num = legend ? 1 : 0;
   DateAxis dateAxis = new DateAxis(timeAxisLabel);
   NumberAxis numberAxis = new NumberAxis(valueAxisLabel);
   numberAxis.setAutoRangeIncludesZero(false);
   XYBoxAndWhiskerRenderer andWhiskerRenderer = new XYBoxAndWhiskerRenderer(10.0);
   XYPlot xyPlot = new XYPlot((XYDataset) dataset, (ValueAxis) dateAxis, (ValueAxis) numberAxis, (XYItemRenderer) andWhiskerRenderer);
   JFreeChart.__\u003Cclinit\u003E();
   JFreeChart jfc = new JFreeChart(title, JFreeChart.__\u003C\u003EDEFAULT_TITLE_FONT, (Plot) xyPlot, num != 0);
   ChartFactory.currentTheme.apply(jfc);
   return jfc;
 }
 public static JFreeChart createHighLowChart(string title, string timeAxisLabel, string valueAxisLabel, OHLCDataset dataset, Timeline timeline, bool legend)
 {
   int num = legend ? 1 : 0;
   DateAxis dateAxis = new DateAxis(timeAxisLabel);
   dateAxis.setTimeline(timeline);
   NumberAxis numberAxis = new NumberAxis(valueAxisLabel);
   HighLowRenderer highLowRenderer = new HighLowRenderer();
   highLowRenderer.setBaseToolTipGenerator((XYToolTipGenerator) new HighLowItemLabelGenerator());
   XYPlot xyPlot = new XYPlot((XYDataset) dataset, (ValueAxis) dateAxis, (ValueAxis) numberAxis, (XYItemRenderer) highLowRenderer);
   JFreeChart.__\u003Cclinit\u003E();
   JFreeChart jfc = new JFreeChart(title, JFreeChart.__\u003C\u003EDEFAULT_TITLE_FONT, (Plot) xyPlot, num != 0);
   ChartFactory.currentTheme.apply(jfc);
   return jfc;
 }
 public static JFreeChart createCandlestickChart(string title, string timeAxisLabel, string valueAxisLabel, OHLCDataset dataset, bool legend)
 {
   int num = legend ? 1 : 0;
   DateAxis dateAxis = new DateAxis(timeAxisLabel);
   NumberAxis numberAxis = new NumberAxis(valueAxisLabel);
   XYPlot xyPlot = new XYPlot((XYDataset) dataset, (ValueAxis) dateAxis, (ValueAxis) numberAxis, (XYItemRenderer) null);
   xyPlot.setRenderer((XYItemRenderer) new CandlestickRenderer());
   JFreeChart.__\u003Cclinit\u003E();
   JFreeChart jfc = new JFreeChart(title, JFreeChart.__\u003C\u003EDEFAULT_TITLE_FONT, (Plot) xyPlot, num != 0);
   ChartFactory.currentTheme.apply(jfc);
   return jfc;
 }
 public static JFreeChart createTimeSeriesChart(string title, string timeAxisLabel, string valueAxisLabel, XYDataset dataset, bool legend, bool tooltips, bool urls)
 {
   int num1 = tooltips ? 1 : 0;
   int num2 = urls ? 1 : 0;
   int num3 = legend ? 1 : 0;
   DateAxis dateAxis = new DateAxis(timeAxisLabel);
   dateAxis.setLowerMargin(0.02);
   dateAxis.setUpperMargin(0.02);
   NumberAxis numberAxis = new NumberAxis(valueAxisLabel);
   numberAxis.setAutoRangeIncludesZero(false);
   XYPlot xyPlot = new XYPlot(dataset, (ValueAxis) dateAxis, (ValueAxis) numberAxis, (XYItemRenderer) null);
   StandardXYToolTipGenerator toolTipGenerator = (StandardXYToolTipGenerator) null;
   if (num1 != 0)
     toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
   StandardXYURLGenerator standardXyurlGenerator = (StandardXYURLGenerator) null;
   if (num2 != 0)
     standardXyurlGenerator = new StandardXYURLGenerator();
   XYLineAndShapeRenderer andShapeRenderer = new XYLineAndShapeRenderer(true, false);
   andShapeRenderer.setBaseToolTipGenerator((XYToolTipGenerator) toolTipGenerator);
   andShapeRenderer.setURLGenerator((XYURLGenerator) standardXyurlGenerator);
   xyPlot.setRenderer((XYItemRenderer) andShapeRenderer);
   JFreeChart.__\u003Cclinit\u003E();
   JFreeChart jfc = new JFreeChart(title, JFreeChart.__\u003C\u003EDEFAULT_TITLE_FONT, (Plot) xyPlot, num3 != 0);
   ChartFactory.currentTheme.apply(jfc);
   return jfc;
 }