Exemple #1
0
        public static Dictionary <DateTime, Dictionary <string, Dictionary <string, decimal?> > > BuildValues(
            List <DataPoint> lines)
        {
            // Distinct
            var times      = lines.Select(x => x.Time).Distinct().ToList();
            var targets    = lines.Select(x => x.TargetId).Distinct().ToList();
            var indicators = lines.Select(x => x.IndicatorId).Distinct().ToList();

            // Loop
            var level1 = new Dictionary <DateTime, Dictionary <string, Dictionary <string, decimal?> > >();

            foreach (var time in times)
            {
                var level2 = new Dictionary <string, Dictionary <string, decimal?> >();
                foreach (var indicator in indicators)
                {
                    var level3 = new Dictionary <string, decimal?>();
                    foreach (var target in targets)
                    {
                        var line = lines.FirstOrDefault(LineExpression.Line(time, target, indicator).Compile());
                        level3.Add(target, line?.Value);
                    }
                    level2.Add(indicator, level3);
                }
                level1.Add(time, level2);
            }

            // Return
            return(level1);
        }
Exemple #2
0
        public static void BuildLines(List <Currency> currencies, List <Indicator> indicators, List <Watcher> watchers, List <DataPoint> lines, int dependencyLevel, int stopAt)
        {
            foreach (var currency in currencies)
            {
                foreach (var indicator in indicators)
                {
                    if (indicator.DependencyLevel == dependencyLevel) // We set the consecutive ones
                    {
                        // Get latest line for this currency indicator pair
                        var line = lines.FirstOrDefault(LineExpression.Line(lines[0].Time, currency.CurrencyId, indicator.IndicatorId).Compile());
                        // Get all watchers for this currency indicator pair
                        var filteredWatchers = watchers.Where(WatcherExpression.WatcherFilter(null, currency.CurrencyId, indicator.IndicatorId).Compile()).ToList();
                        // Build
                        var value       = IndicatorBuilder.BuildValue(currency, indicator, lines);
                        var averageBuy  = IndicatorBuilder.BuildAverageBuy(filteredWatchers);
                        var averageSell = IndicatorBuilder.BuildAverageSell(filteredWatchers);
                        // Set
                        line?.Set(value, averageBuy, averageSell);
                    }
                }
            }

            // Do the same with the next level recursively
            if (dependencyLevel < stopAt)
            {
                BuildLines(currencies, indicators, watchers, lines, dependencyLevel + 1, stopAt);
            }
        }