Пример #1
0
        public void UpdateMetrics(ITradingObject tradingObject, Bar bar)
        {
            if (tradingObject == null)
            {
                throw new ArgumentNullException();
            }

            if (bar.Time == Bar.InvalidTime)
            {
                return;
            }

            unchecked
            {
                int tradingObjectIndex = tradingObject.Index;
                for (int metricIndex = 0; metricIndex < _metrics.Count; ++metricIndex)
                {
                    var currentMetricColumn = _metrics[metricIndex];

                    IRuntimeMetric metric = currentMetricColumn[tradingObjectIndex];
                    if (metric == null)
                    {
                        var metricCreator = _metricCreators[metricIndex];
                        var metricName    = _metricNames[metricIndex];

                        metric = metricCreator(metricName);
                        currentMetricColumn[tradingObjectIndex] = metric;
                    }

                    metric.Update(bar);
                }
            }
        }
Пример #2
0
        public void UpdateMetrics(ITradingObject[] tradingObjects, StockAnalysis.Share.Bar[] bars)
        {
            if (tradingObjects.Length != bars.Length ||
                tradingObjects.Length != _maxTradingObjectNumber)
            {
                throw new ArgumentException("unexpected number of input data");
            }

            unchecked
            {
                for (int metricIndex = 0; metricIndex < _metrics.Count; ++metricIndex)
                {
                    var currentMetricColumn = _metrics[metricIndex];
                    var metricCreator       = _metricCreators[metricIndex];
                    var metricName          = _metricNames[metricIndex];

                    for (int barIndex = 0; barIndex < bars.Length; ++barIndex)
                    {
                        var bar = bars[barIndex];
                        if (bar.Time == Bar.InvalidTime)
                        {
                            continue;
                        }

                        IRuntimeMetric metric = currentMetricColumn[barIndex];
                        if (metric == null)
                        {
                            metric = metricCreator(metricName);
                            currentMetricColumn[barIndex] = metric;
                        }

                        metric.Update(bar);
                    }
                }
            }
        }