コード例 #1
0
        private static Dictionary <IAccount, List <SimulationResultItem> > RunInternal(SimulationSetup setup, Profile profile)
        {
            var state = new SimulationState(profile, setup);
            var start = setup.Start.Date;
            var end   = setup.End.Date;

            for (DateTime date = start; date <= end; date = date.AddDays(1))
            {
                // before anything else, make sure we do the events
                var events = state.Events[date];
                foreach (var item in events)
                {
                    ProcessEvent(state, date, item);
                }

                // if it is the end of the month, then interest hits
                if (date.IsEndOfMonth())
                {
                    foreach (var account in state.GetAccounts())
                    {
                        account.ProcessInterest(state, date);
                    }
                }

                // deposit any paychecks
                var paychecks = state.Paychecks.Values.Where(p => p.Due.Current == date);
                foreach (var paycheck in paychecks)
                {
                    paycheck.Process(state, date);
                    paycheck.Due.Next();
                }

                // pay the bills
                var bills = state.Bills.Values.Where(b => b.Due.Current == date);
                foreach (var bill in bills)
                {
                    bill.Process(state, date);
                    bill.Due.Next();
                }

                // pay the debts
                var debts = state.Debts.Values.Where(d => d.Due.Current == date);
                foreach (var debt in debts)
                {
                    debt.Process(state, date);
                    debt.Due.Next();
                }

                // process the transactions
                var transactions = state.Transactions.Values.Where(t => t.Due.Current == date);
                foreach (var transaction in transactions)
                {
                    transaction.Process(state, date);
                    transaction.Due.Next();
                }

                // if we get here and a debt has a zero balance, then it is paid off
                foreach (var debt in state.Debts.Values)
                {
                    if (debt.Balance <= 0)
                    {
                        state.PayOff(date, debt);
                    }
                }

                // if needed, update the snowball
                state.UpdateSnowball(date);

                // quit if we need to
                if (!state.ShouldKeepGoing())
                {
                    break;
                }
            }

            return(state.Results);
        }
コード例 #2
0
 public abstract void Deposit(SimulationState state, DateTime date, decimal amount);
コード例 #3
0
 public abstract void Withdraw(SimulationState state, DateTime date, decimal amount);
コード例 #4
0
 public override void Deposit(SimulationState state, DateTime date, decimal amount) =>
 Balance += amount;
コード例 #5
0
 public abstract void ProcessInterest(SimulationState state, DateTime date);
コード例 #6
0
 public override void Withdraw(SimulationState state, DateTime date, decimal amount) =>
 Balance += amount;
コード例 #7
0
 public void Process(SimulationState state, DateTime date)
 {
     state.Withdraw(date, FromId, Name, Amount);
     state.Deposit(date, ToId, Name, Amount);
 }
コード例 #8
0
 public void Process(SimulationState state, DateTime date)
 {
     state.Withdraw(date, AccountId, Name, Payment);
 }
コード例 #9
0
 private static void WithdrawDelegate(SimulationAccount account, SimulationState state, DateTime date, decimal amount)
 => account.Withdraw(state, date, amount);
コード例 #10
0
 private static void DepositDelegate(SimulationAccount account, SimulationState state, DateTime date, decimal amount)
 => account.Deposit(state, date, amount);