コード例 #1
0
        public AlgorithmSwitchingManager()
        {
            _stableHistory   = new Dictionary <AlgorithmType, AlgorithmHistory>();
            _unstableHistory = new Dictionary <AlgorithmType, AlgorithmHistory>();
            _lastLegitPaying = new Dictionary <AlgorithmType, double>();

            foreach (var kvp in NHSmaData.FilteredCurrentProfits(true))
            {
                _stableHistory[kvp.Key]   = new AlgorithmHistory(MaxHistory);
                _lastLegitPaying[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in NHSmaData.FilteredCurrentProfits(false))
            {
                _unstableHistory[kvp.Key] = new AlgorithmHistory(MaxHistory);
                _lastLegitPaying[kvp.Key] = kvp.Value;
            }
        }
コード例 #2
0
        public void ForceUpdate()
        {
            var isAllZeroPaying = _lastLegitPaying.Values.Any(paying => paying == 0);

            if (isAllZeroPaying)
            {
                foreach (var kvp in NHSmaData.FilteredCurrentProfits(true))
                {
                    _stableHistory[kvp.Key]   = new AlgorithmHistory(MaxHistory);
                    _lastLegitPaying[kvp.Key] = kvp.Value;
                }
                foreach (var kvp in NHSmaData.FilteredCurrentProfits(false))
                {
                    _unstableHistory[kvp.Key] = new AlgorithmHistory(MaxHistory);
                    _lastLegitPaying[kvp.Key] = kvp.Value;
                }
            }
            var args = new SmaUpdateEventArgs(_lastLegitPaying);

            Stop();
            SmaCheck?.Invoke(this, args);
            Start();
        }
コード例 #3
0
        /// <summary>
        /// Check profits for a history dict and update if profit has been higher for required ticks or if it is lower
        /// </summary>
        /// <returns>True iff any profits were postponed or updated</returns>
        private bool UpdateProfits(Dictionary <AlgorithmType, AlgorithmHistory> history, int ticks, StringBuilder sb)
        {
            var updated = false;

            foreach (var algo in history.Keys)
            {
                if (NHSmaData.TryGetPaying(algo, out var paying))
                {
                    history[algo].Add(paying);
                    if (paying > _lastLegitPaying[algo])
                    {
                        updated = true;
                        var i = history[algo].CountOverProfit(_lastLegitPaying[algo]);
                        if (i >= ticks)
                        {
                            _lastLegitPaying[algo] = paying;
                            sb.AppendLine($"\tTAKEN: new profit {paying:e5} after {i} ticks for {algo}");
                        }
                        else
                        {
                            sb.AppendLine(
                                $"\tPOSTPONED: new profit {paying:e5} (previously {_lastLegitPaying[algo]:e5})," +
                                $" higher for {i}/{ticks} ticks for {algo}"
                                );
                        }
                    }
                    else
                    {
                        // Profit has gone down
                        _lastLegitPaying[algo] = paying;
                    }
                }
            }

            return(updated);
        }