예제 #1
0
        public override void Calculate()
        {
            var holdingPeriodReturn = 0.00m;

            var index = 0;

            foreach (var period in Periods)
            {
                var periodFrom = period.DateFrom;
                var periodTo   = period.DateTo;

                var incomeForPeriod = Incomes.Where(i => i.Timestamp >= periodFrom && i.Timestamp <= periodTo)
                                      .Select(i => i.Amount)
                                      .Sum();

                var periodicReturn = CalculatePeriodicReturn(periodFrom, periodTo, incomeForPeriod);

                if (index == 0)
                {
                    holdingPeriodReturn = periodicReturn;
                }
                else
                {
                    holdingPeriodReturn = holdingPeriodReturn * (1 + periodicReturn);
                }
                index++;
            }

            CalculatedTime = DateTime.Now;
            Rate           = holdingPeriodReturn - 1;
        }
        private void LoadIncomes()
        {
            int minYear = Incomes.Select(income => income.Date.Year).Min();
            int maxYear = Incomes.Select(income => income.Date.Year).Max();

            for (int i = minYear; i <= maxYear; i++)
            {
                decimal yearIncome = 0;
                monthIncomes[i] = new List <IncomeModel>();
                for (int j = 1; j <= 12; j++)
                {
                    var month = Incomes
                                .Where(income => income.Date.Year == i && income.Date.Month == j)
                                .Select(income => income.Money)
                                .Sum();

                    monthIncomes[i].Add(new IncomeModel
                    {
                        Date   = j,
                        Income = month
                    });

                    yearIncome += month;
                }

                yearIncomes.Add(new IncomeModel
                {
                    Date   = i,
                    Income = yearIncome
                });
            }
        }
        public void UpdateIncome()
        {
            var month = CurrentIncome.Date.Month;
            var year  = CurrentIncome.Date.Year;

            var date = DateTime.Now;

            if (date.Day != 1)
            {
                return;
            }

            CurrentIncome = new Income
            {
                Date         = DateTime.Now,
                EnterpriseId = Id
            };

            CurrentIncome = Manager.mobiMarket.Incomes.Add(CurrentIncome);

            var monthIncome = Incomes
                              .Where(income => income.Date.Month == month && income.Date.Year == year)
                              .Union(new[] { CurrentIncome })
                              .Select(x => x.Money)
                              .Sum();

            monthIncomes[year].Add(new IncomeModel
            {
                Date   = month,
                Income = monthIncome
            });

            if (date.Month != 1)
            {
                return;
            }

            var yearIncome = Incomes.Where(income => income.Date.Year == year)
                             .Select(x => x.Money)
                             .Sum();

            yearIncomes.Add(new IncomeModel
            {
                Date   = year,
                Income = yearIncome
            });
        }
예제 #4
0
 public decimal CalculateLeftToReceive() => Incomes.Where(i => !i.Received).Sum(i => i.Amount);
 public List <Income> GetMonthIncomes(int year, int month)
 {
     return(Incomes.Where(income => income.Date.Year == year && income.Date.Month == month).ToList());
 }