private DataTable GeneratePerformanceOverviewStats() { var statsDT = new DataTable(); statsDT.Columns.Add("Stat", typeof(string)); statsDT.Columns.Add("Last 30 Days", typeof(string)); statsDT.Columns.Add("YTD", typeof(string)); statsDT.Columns.Add("All Time", typeof(string)); var allEquitySummaries = Context .EquitySummaries .OrderBy(x => x.Date) .ToList(); Dictionary <DateTime, decimal> depositsWithdrawals = Context .CashTransactions .Where(x => x.Type == "Deposits & Withdrawals") .ToList() .GroupBy(x => x.TransactionDate) .ToDictionary(x => x.Key, x => x.Sum(y => y.Amount * y.FXRateToBase)); var last30DaysEC = EcFromEquitySummaries( allEquitySummaries.Where(x => x.Date >= DateTime.Now.AddMonths(-1)).ToList(), depositsWithdrawals); var ytdEC = EcFromEquitySummaries( allEquitySummaries.Where(x => x.Date.Year == DateTime.Now.Year).ToList(), depositsWithdrawals); var allTimeEC = EcFromEquitySummaries(allEquitySummaries, depositsWithdrawals); var last30DayStats = PerformanceMeasurement.EquityCurveStats(last30DaysEC, 30); var ytdStats = PerformanceMeasurement.EquityCurveStats(ytdEC, DateTime.Now.DayOfYear); var allTimeStats = PerformanceMeasurement.EquityCurveStats(allTimeEC, (int)(allEquitySummaries.Last().Date - allEquitySummaries.First().Date).TotalDays); foreach (var kvp in last30DayStats) { var dr = statsDT.NewRow(); dr["Stat"] = kvp.Key; dr["Last 30 Days"] = kvp.Value; if (ytdStats.ContainsKey(kvp.Key)) { dr["YTD"] = ytdStats[kvp.Key]; } dr["All Time"] = allTimeStats[kvp.Key]; statsDT.Rows.Add(dr); } return(statsDT); }
private DataTable GeneratePerformanceOverviewStats() { var statsDT = new DataTable(); statsDT.Columns.Add("Stat", typeof(string)); statsDT.Columns.Add("Last 30 Days", typeof(string)); statsDT.Columns.Add("YTD", typeof(string)); statsDT.Columns.Add("All Time", typeof(string)); Dictionary <DateTime, decimal> depositsWithdrawals = GetDepositsWithdrawals(); Dictionary <DateTime, decimal> totalCapital = GetTotalCapitalSeries(); if (totalCapital.Count == 0) { return(statsDT); } var last30DaysEC = EcFromEquitySummaries( totalCapital.Where(x => x.Key >= DateTime.Now.AddMonths(-1)).ToDictionary(x => x.Key, x => x.Value), depositsWithdrawals); var ytdEC = EcFromEquitySummaries( totalCapital.Where(x => x.Key.Year == DateTime.Now.Year).ToList().ToDictionary(x => x.Key, x => x.Value), depositsWithdrawals); var allTimeEC = EcFromEquitySummaries(totalCapital, depositsWithdrawals); var last30DayStats = PerformanceMeasurement.EquityCurveStats(last30DaysEC, 30); var ytdStats = PerformanceMeasurement.EquityCurveStats(ytdEC, DateTime.Now.DayOfYear); var allTimeStats = PerformanceMeasurement.EquityCurveStats(allTimeEC, (int)(totalCapital.Last().Key - totalCapital.First().Key).TotalDays); foreach (var kvp in allTimeStats) { var dr = statsDT.NewRow(); dr["Stat"] = kvp.Key; if (last30DayStats.ContainsKey(kvp.Key)) { dr["Last 30 Days"] = last30DayStats[kvp.Key]; } if (ytdStats.ContainsKey(kvp.Key)) { dr["YTD"] = ytdStats[kvp.Key]; } dr["All Time"] = allTimeStats[kvp.Key]; statsDT.Rows.Add(dr); } return(statsDT); }