protected override void Calculate(bool isNewBar)
        {
            var res = double.NaN;

            if (_currencyId != -1)
            {
                if (_lastSearchTime + _delay < DateTime.Now)
                {
                    var graphSnapshot = _symbolGraph.GetSnapshot(edge => double.IsNaN(edge.ReverseWeight) ? null : new Edge <CurrencyNode>(edge.From, edge.To, edge.ReverseWeight));
                    _lastSearch = BellmanFord <CurrencyNode, Edge <CurrencyNode> > .CalculateShortestPaths(graphSnapshot, _pathLogic, _currencyId);

                    _lastSearchTime = DateTime.Now;
                }

                res = 0;
                foreach (var nodeId in _currencyListIds)
                {
                    res += !_lastSearch.Distance[nodeId].E(_pathLogic.UnreachableValue)
                        ? -_lastSearch.Distance[nodeId]
                        : double.NaN;
                }
            }

            Output[0] = res;
        }
示例#2
0
        protected override void Calculate(bool isNewBar)
        {
            var res = double.NaN;

            if (_currencyId != -1 && Account.Type == AccountTypes.Cash)
            {
                if (_lastSearchTime + _delay < DateTime.Now)
                {
                    var graphSnapshot = _symbolGraph.GetSnapshot(edge => double.IsNaN(edge.ReverseWeight) ? null : new Edge <CurrencyNode>(edge.From, edge.To, edge.ReverseWeight));
                    _lastSearch = BellmanFord <CurrencyNode, Edge <CurrencyNode> > .CalculateShortestPaths(graphSnapshot, _pathLogic, _currencyId);

                    _lastSearchTime = DateTime.Now;
                }

                res = 0;
                foreach (var asset in Account.Assets)
                {
                    var node = _symbolGraph[asset.Currency];
                    res += (node != null && !_lastSearch.Distance[node.Id].E(_pathLogic.UnreachableValue))
                        ? asset.Volume * Math.Exp(-_lastSearch.Distance[node.Id])
                        : double.NaN;
                }
            }

            Output[0] = res;
        }