17 using System.Collections.Generic;
31 private readonly SortedDictionary<TimeSpan, SimpleMovingAverage> _relativeData;
32 private readonly Dictionary<DateTime, decimal> _currentData;
33 private int _previousDay;
40 public override bool IsReady => _days >= _period;
47 : this($
"RDV({period})", period)
59 _relativeData =
new SortedDictionary<TimeSpan, SimpleMovingAverage>();
60 _currentData =
new Dictionary<DateTime, decimal>();
73 if (input.
Time.Day != _previousDay)
75 var cumulativeVolume = 0.0m;
76 foreach (var pair
in _currentData)
78 var timeBar = pair.Key.TimeOfDay;
80 cumulativeVolume += pair.Value;
81 if (!_relativeData.TryGetValue(timeBar, out daysAverage))
85 daysAverage.Update(pair.Key, cumulativeVolume);
88 _previousDay = input.
Time.Day;
99 var currentTimeBar = input.
Time.TimeOfDay;
100 var denominator = 0.0m;
103 if (_relativeData.TryGetValue(currentTimeBar, out currentAverage))
105 denominator = currentAverage.Current.Value;
111 var relativeDataKeys = _relativeData.Keys.ToList();
112 for (
int i = 1; i < relativeDataKeys.Count; i++)
114 if (relativeDataKeys[i] > currentTimeBar)
116 denominator = _relativeData[relativeDataKeys[i - 1]].Current.Value;
120 if (denominator == 0)
124 var relativeDailyVolume = _currentData.Values.Sum() / denominator;
125 return relativeDailyVolume;
133 _relativeData.Clear();
134 _currentData.Clear();