Технические индикаторы Anychart/Anystock

У меня есть линейный график ежедневных цен портфеля акций, но мы также хотим показать процент изменения дневной цены за выбранное время. Я нашел в Технические индикаторы Скорость изменения (ROC), но для этого требуется определить период, и я хочу, чтобы цена, с которой она сравнивается, самая первая цена в ряду данных. Есть ли способ сделать это? Спасибо за помощь заранее.

ОБНОВЛЕНИЕ: Итак, после некоторого просмотра документации это выглядит как comparisonMode("percent") будет делать то, что я хочу, с точки зрения математики, но я не смог придумать способ построения графика результатов вместо того, чтобы просто создавать значение оси Y.


person Aaron    schedule 01.02.2018    source источник


Ответы (1)


Да, для этого в AnyStock предусмотрен режим сравнения. Режим сравнения не влияет на форму ряда линии или что-то еще. Он обеспечивает пересчет стоимости по сравнению с первой ценой в серии, например (доступны другие режимы). Ниже вы можете найти пример, который показывает, как использовать режим сравнения. Кроме того, вы можете узнать больше о режиме сравнения в этой статье.

anychart.onDocumentReady(function () {
    
    var dataTable = anychart.data.table();
    // data comes from the function in https://cdn.anychart.com/csv-data/dji-daily-short.js
    dataTable.addData(get_dji_daily_short_data());

    var firstMapping = dataTable.mapAs({value: 1});

    var chart = anychart.stock();
    chart.padding(10, 10, 10, 50);

    var nonePlot = chart.plot(0);
    nonePlot.line(firstMapping);
    nonePlot.legend().titleFormat(function (){return "comparisonMode='none'"});
    // Set comparison mode to 'none'
    nonePlot.yScale().comparisonMode("none");

    var valuePlot = chart.plot(1);
    var valueSeries = valuePlot.line(firstMapping);
    valuePlot.legend().titleFormat(function (){return "comparisonMode='value'"});
	valuePlot.legend().itemsFormat(function () {
        return "Value: " + anychart.format.number(this.valueChange, 3, ".", "") ;
    });
  valueSeries.tooltip().format(function() {
  	return 'Value change: ' + anychart.format.number(this.valueChange, 3, ".", "") ;
  });
    // Set comparison mode 'value'
    valuePlot.yScale().comparisonMode("value");

    var percentPlot = chart.plot(2);
   var percentSeries = percentPlot.line(firstMapping);
    percentPlot.legend().titleFormat(function (){return "comparisonMode='percent'"});
  	percentPlot.legend().itemsFormat(function () {
        return "Value: " + this.valuePercentChange + '%';
    });
    percentSeries.tooltip().format(function() {
  	return 'Percent change: ' + this.valuePercentChange + '%';
  });
    percentPlot.yAxis().labels().format("{%value}%");
    // Set comparison mode to 'percent'
    percentPlot.yScale().comparisonMode("percent");

    chart.title("Stock: Different Comparison Modes");
    chart.container("container");
    chart.draw();
});
html, body, #container {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}
<script src="https://cdn.anychart.com/releases/8.1.0/js/anychart-base.min.js"></script>
<script src="https://cdn.anychart.com/releases/8.1.0/js/anychart-ui.min.js"></script>
<script src="https://cdn.anychart.com/releases/8.1.0/js/anychart-exports.min.js"></script>
<script src="https://cdn.anychart.com/releases/8.1.0/js/anychart-stock.min.js"></script>

<script src="https://cdn.anychart.com/csv-data/dji-daily-short.js"></script>
<link href="https://cdn.anychart.com/releases/8.1.0/css/anychart-ui.min.css" rel="stylesheet"/>
<div id="container"></div>

person AnyChart Support    schedule 05.02.2018