Exemple #1
0
 /// <summary>
 /// Check profits for a history dict and update if profit has been higher for required ticks or if it is lower
 /// </summary>
 private void UpdateProfits(Dictionary <AlgorithmType, AlgorithmHistory> history, int ticks, StringBuilder sb)
 {
     foreach (var algo in history.Keys)
     {
         if (NHSmaData.TryGetPaying(algo, out var paying))
         {
             history[algo].Add(paying);
             if (paying > _lastLegitPaying[algo])
             {
                 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;
             }
         }
     }
 }
        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;
            }
        }
Exemple #3
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();
        }