예제 #1
0
        public ValueExtractor(IRuntimeMetricManager manager, string expression, Func <string, IRuntimeMetric> creator = null)
        {
            if (manager == null)
            {
                throw new ArgumentNullException();
            }

            if (string.IsNullOrWhiteSpace(expression))
            {
                throw new ArgumentNullException(expression);
            }

            double constantValue;

            if (!double.TryParse(expression, out constantValue))
            {
                _isConstant = false;
                _proxy      = creator == null ? new RuntimeMetricProxy(manager, expression) : new RuntimeMetricProxy(manager, expression, creator);
                _constant   = double.NaN;
            }
            else
            {
                _proxy      = null;
                _constant   = constantValue;
                _isConstant = true;
            }
        }
예제 #2
0
        public StandardGroupRuntimeMetricManager(IRuntimeMetricManager manager)
        {
            if (manager == null)
            {
                throw new ArgumentNullException();
            }

            _manager = manager;
        }
예제 #3
0
        public RuntimeMetricProxy(IRuntimeMetricManager manager, string metricName, Func <string, IRuntimeMetric> metricCreator)
        {
            if (string.IsNullOrWhiteSpace(metricName) || manager == null || metricCreator == null)
            {
                throw new ArgumentNullException();
            }

            _manager     = manager;
            _metricIndex = manager.RegisterMetric(metricName, metricCreator);
        }
예제 #4
0
        public void Observe(IRuntimeMetricManager manager)
        {
            if (manager == null)
            {
                throw new ArgumentNullException();
            }

            var metrics = _rocMetricProxy.GetMetrics();

            _sorter.OrderByDescending(metrics);
        }
예제 #5
0
        public void Initialize(IRuntimeMetricManager manager)
        {
            if (manager == null)
            {
                throw new ArgumentNullException();
            }

            _leftValueExtractor = new ValueExtractor(manager, _leftExpression, _metricCreator1);

            _operator = ComparisonOperatorHelper.Parse(_operatorString);

            _rightValueExtractor = new ValueExtractor(manager, _rightExpression, _metricCreator2);
        }
예제 #6
0
        public void Initialize(IRuntimeMetricManager manager)
        {
            if (manager == null)
            {
                throw new ArgumentNullException();
            }

            _expression1.Initialize(manager);

            if (_expression2 != null)
            {
                _expression2.Initialize(manager);
            }
        }
        public void Observe(IRuntimeMetricManager manager)
        {
            if (manager == null)
            {
                throw new ArgumentNullException();
            }

            var metrics = manager.GetMetrics(_metricIndex);

            foreach (var sorter in _blockToMetricSorterMap.Values)
            {
                var subMetrics = sorter.TradingObjects.Select(o => metrics[o.Index]).ToArray();

                sorter.OrderBy(subMetrics, _comparer);
            }
        }
        public StandardEvaluationContext(
            ITradingDataProvider provider,
            EquityManager equityManager,
            ILogger logger,
            TradingSettings settings    = null,
            StreamWriter dumpDataWriter = null,
            StockBlockRelationshipManager relationshipManager = null)
        {
            if (equityManager == null || provider == null || logger == null)
            {
                throw new ArgumentNullException();
            }

            _provider      = provider;
            _equityManager = equityManager;
            _logger        = logger;
            _settings      = settings;

            _relationshipManager = relationshipManager;

            var metricManager      = new StandardRuntimeMetricManager(_provider.GetAllTradingObjects().Length);
            var groupMetricManager = new StandardGroupRuntimeMetricManager(metricManager);

            // register the group metric manager as observer of metric manager.
            metricManager.RegisterAfterUpdatedMetricsObserver(groupMetricManager);

            _metricManager      = metricManager;
            _groupMetricManager = groupMetricManager;

            _boardIndexTradingObjects = new Dictionary <string, ITradingObject>();

            var boards = new StockBoard[]
            {
                StockBoard.GrowingBoard,
                StockBoard.MainBoard,
                StockBoard.SmallMiddleBoard
            };

            foreach (var board in boards)
            {
                string         boardIndex    = StockName.GetBoardIndex(board);
                ITradingObject tradingObject = GetTradingObject(boardIndex);
                _boardIndexTradingObjects.Add(boardIndex, tradingObject);
            }

            _dumper = dumpDataWriter == null ? null : new StreamDataDumper(dumpDataWriter, 8, 3, _settings.DumpMetrics, this, _provider);
        }
예제 #9
0
        /// <summary>
        /// Update all registered group runtime metric according to the value of depended metric value
        /// </summary>
        /// <param name="manager">the runtime metric manager which manages all metrics depended by the group runtime metrics</param>
        private void UpdateMetrics(IRuntimeMetricManager manager)
        {
            if (manager != _manager)
            {
                throw new InvalidProgramException();
            }

            for (int i = 0; i < _metrics.Count; ++i)
            {
                IGroupRuntimeMetric metric  = _metrics[i];
                int[] tradingObjectIndices  = _tradingObjects[i];
                int[] dependedMetricIndices = _dependedMetrics[i];

                if (dependedMetricIndices.Length == 0)
                {
                    continue;
                }

                IRuntimeMetric[][] runtimeMetrics = new IRuntimeMetric[dependedMetricIndices.Length][];
                for (int j = 0; j < runtimeMetrics.Length; ++j)
                {
                    IRuntimeMetric[] fullMetrics = manager.GetMetrics(dependedMetricIndices[j]);

                    IRuntimeMetric[] subMetrics = new IRuntimeMetric[tradingObjectIndices.Length];

                    for (int k = 0; k < tradingObjectIndices.Length; ++k)
                    {
                        subMetrics[k] = fullMetrics[tradingObjectIndices[k]];
                    }

                    runtimeMetrics[j] = subMetrics;
                }

                // update metric
                metric.Update(runtimeMetrics);
            }

            // call observers if any
            foreach (var observer in _observers)
            {
                observer.Observe(this);
            }
        }
예제 #10
0
        public MovingAverageTrendDetector(IRuntimeMetricManager manager, IEnumerable <int> periods)
        {
            if (manager == null)
            {
                throw new ArgumentNullException("manager");
            }

            if (periods == null)
            {
                throw new ArgumentNullException("periods");
            }

            var dedupPeriods = periods.GroupBy(i => i);

            periods = dedupPeriods.Select(g => g.Key).ToList();

            if (periods.Count() < 1)
            {
                throw new ArgumentException("Need at least 1 MA periods for trend detection");
            }

            // for single period that is not 1, we need to add 1 in periods.
            var tempPeriods = periods.ToList();

            if (periods.Count() == 1 && periods.First() != 1)
            {
                tempPeriods.Add(1);
            }

            _periods = tempPeriods.OrderBy(i => i).ToArray();

            _movingAverages = _periods
                              .Select(i => new RuntimeMetricProxy(manager, string.Format("MA[{0}]", i)))
                              .ToArray();

            _trendDetectors = _periods
                              .Select(i => new RuntimeMetricProxy(manager, string.Format("TD[5](MA[{0}])", i)))
                              .ToArray();
        }
예제 #11
0
 public void Observe(IRuntimeMetricManager manager)
 {
     UpdateMetrics(manager);
 }