private static List <PerformanceCycle> BuildAllList(TradingAccount tradingAccount)
        {
            Dictionary <String, List <Trade> > roughCycles = new Dictionary <string, List <Trade> > {
                { "All", tradingAccount.Trades.ToList() }
            };

            return(BuildList(tradingAccount.InitialCapital, roughCycles, PerformanceCycleTypes.All));
        }
        private static List <PerformanceCycle> BuildSecurityList(TradingAccount tradingAccount)
        {
            Dictionary <String, List <Trade> > roughCycles = (from t in tradingAccount.Trades
                                                              group t by t.Market.Symbol into g
                                                              select new { key = g.Key, trades = g.OrderBy(x => x.EntryDate).ToList() })
                                                             .OrderBy(x => x.key).ToDictionary(x => x.key, x => x.trades);

            return(BuildList(tradingAccount.InitialCapital, roughCycles, PerformanceCycleTypes.Security));
        }
        private static List <PerformanceCycle> BuildHourList(TradingAccount tradingAccount)
        {
            Dictionary <String, List <Trade> > roughCycles = (from t in tradingAccount.Trades
                                                              group t by t.EntryDate.Hour into g
                                                              select new { key = g.Key, trades = g.OrderBy(x => x.EntryDate).ToList() })
                                                             .OrderBy(x => x.key).ToDictionary(x => $"{x.key}:00 - {x.key + 1}:00", x => x.trades);

            return(BuildList(tradingAccount.InitialCapital, roughCycles, PerformanceCycleTypes.Hour));
        }
        private static List <PerformanceCycle> BuildDayOfWeekList(TradingAccount tradingAccount)
        {
            Dictionary <String, List <Trade> > roughCycles = (from t in tradingAccount.Trades
                                                              group t by t.EntryDate.DayOfWeek into g
                                                              select new { key = g.Key, trades = g.OrderBy(x => x.EntryDate).ToList() })
                                                             .OrderBy(x => x.key).ToDictionary(x => x.key.ToString(), x => x.trades);

            return(BuildList(tradingAccount.InitialCapital, roughCycles, PerformanceCycleTypes.DayOfWeek));
        }
        private static List <PerformanceCycle> BuildMonthList(TradingAccount tradingAccount)
        {
            Dictionary <String, List <Trade> > roughCycles = (from t in tradingAccount.Trades
                                                              group t by new { t.EntryDate.Year, t.EntryDate.Month } into g
                                                              select new { year = g.Key.Year, month = g.Key.Month, trades = g.OrderBy(x => x.EntryDate).ToList() })
                                                             .OrderBy(x => x.year).ThenBy(x => x.month).ToDictionary(x => $"{x.month}/{x.year}", x => x.trades);

            return(BuildList(tradingAccount.InitialCapital, roughCycles, PerformanceCycleTypes.Month));
        }
        //Weekly,
        //Block,
        //Security,
        //Day,
        //Hour

        public static List <PerformanceCycle> BuildLists(TradingAccount tradingAccount)
        {
            List <PerformanceCycle> cycles = new List <PerformanceCycle>();

            cycles.AddRange(BuildWeeklyList(tradingAccount));
            cycles.AddRange(BuildSecurityList(tradingAccount));
            cycles.AddRange(BuildMonthList(tradingAccount));
            cycles.AddRange(BuildDayOfWeekList(tradingAccount));
            cycles.AddRange(BuildHourList(tradingAccount));
            cycles.AddRange(BuildDayList(tradingAccount));
            cycles.AddRange(BuildAllList(tradingAccount));

            return(cycles);
        }
        private static List <PerformanceCycle> BuildWeeklyList(TradingAccount tradingAccount)
        {
            DateTime startOfWeek = tradingAccount.InceptionDate.Date;
            DateTime endOfWeek   = startOfWeek.AddDays(6);
            Dictionary <String, List <Trade> > roughCycles = new Dictionary <string, List <Trade> >();

            while (tradingAccount.Trades.Any(x => x.ExitDate > startOfWeek && x.ExitDate < endOfWeek))
            {
                roughCycles.Add($"{startOfWeek:M/d} - {endOfWeek:M/d}", tradingAccount.Trades.Where(x => x.ExitDate > startOfWeek && x.ExitDate < endOfWeek).OrderBy(x => x.ExitDate).ToList());
                startOfWeek = startOfWeek.AddDays(7);
                endOfWeek   = endOfWeek.AddDays(7);
            }

            return(BuildList(tradingAccount.InitialCapital, roughCycles, PerformanceCycleTypes.Weekly));
        }
        private static List <PerformanceCycle> BuildDayList(TradingAccount tradingAccount)
        {
            Dictionary <String, List <Trade> > roughCycles = new Dictionary <string, List <Trade> >();

            //roughCycles.Add($"{tradingAccount.InceptionDate:M/d/yyyy}", new List<Trade>());

            foreach (var pair in (from t in tradingAccount.Trades
                                  group t by new { t.EntryDate.Year, t.EntryDate.Month, t.EntryDate.Day } into g
                                  select new { year = g.Key.Year, month = g.Key.Month, day = g.Key.Day, trades = g.OrderBy(x => x.EntryDate).ToList() })
                     .OrderBy(x => x.year).ThenBy(x => x.month).ThenBy(x => x.day).ToDictionary(x => $"{x.month}/{x.day}/{x.year}", x => x.trades))
            {
                roughCycles.Add(pair.Key, pair.Value);
            }

            return(BuildList(tradingAccount.InitialCapital, roughCycles, PerformanceCycleTypes.Day));
        }