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);
            // Running the strategy
            TradingRecord tradingRecord = series.run(strategy);
            // Getting the cash flow of the resulting trades
            CashFlow cashFlow = new CashFlow(series, tradingRecord);

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

            datasetAxis1.addSeries(buildChartTimeSeries(series, new ClosePriceIndicator(series), "Bitstamp Bitcoin (BTC)"));
            TimeSeriesCollection datasetAxis2 = new TimeSeriesCollection();

            datasetAxis2.addSeries(buildChartTimeSeries(series, cashFlow, "Cash Flow"));

            /// <summary>
            /// Creating the chart
            /// </summary>
            JFreeChart chart = ChartFactory.createTimeSeriesChart("Bitstamp BTC", "Date", "Price", datasetAxis1, 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>
            /// Adding the cash flow axis (on the right)
            /// </summary>
            addCashFlowAxis(plot, datasetAxis2);

            /// <summary>
            /// Displaying the chart
            /// </summary>
            displayChart(chart);
        }
        public static void Main(string[] args)
        {
            /// <summary>
            /// Getting time series
            /// </summary>
            TimeSeries series = CsvTicksLoader.loadAppleIncSeries();

            /// <summary>
            /// Creating indicators
            /// </summary>
            // Close price
            ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
            // Bollinger bands
            BollingerBandsMiddleIndicator middleBBand = new BollingerBandsMiddleIndicator(closePrice);
            BollingerBandsLowerIndicator  lowBBand    = new BollingerBandsLowerIndicator(middleBBand, closePrice);
            BollingerBandsUpperIndicator  upBBand     = new BollingerBandsUpperIndicator(middleBBand, closePrice);

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

            dataset.addSeries(buildChartTimeSeries(series, closePrice, "Apple Inc. (AAPL) - NASDAQ GS"));
            dataset.addSeries(buildChartTimeSeries(series, lowBBand, "Low Bollinger Band"));
            dataset.addSeries(buildChartTimeSeries(series, upBBand, "High Bollinger Band"));

            /// <summary>
            /// Creating the chart
            /// </summary>
            JFreeChart chart = ChartFactory.createTimeSeriesChart("Apple Inc. 2013 Close Prices", "Date", "Price Per Unit", 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("yyyy-MM-dd");

            /// <summary>
            /// Displaying the chart
            /// </summary>
            displayChart(chart);
        }