Example #1
0
        /*public InterestTransaction AddDailyInterest()
         * {
         *  //Calculate the interest
         *  //If debt
         *  if (Balance < 0 && _debtInterest > 0)
         *  {
         *      //Yearly interest to daily interest
         *      decimal dailyInterest = (decimal)Math.Pow(1 + (double)_debtInterest / 100.0, 1.0 / 365.0) - 1;
         *
         *      //How much to remove from the account (Balance is negative => amount is negative)
         *      decimal amount = Math.Round(Balance * dailyInterest, 2);
         *
         *      //Remove the rent to the account
         *      Balance = Balance + amount;
         *
         *      Console.WriteLine("Skuldränta har tagits ifrån konto {0}.", AccountNumber);
         *
         *      InterestTransaction transaction = new InterestTransaction(DateTime.Now, AccountNumber, +amount, Balance);
         *      return transaction;
         *  }
         *
         *  //If savings
         *  if (Balance > 0 && _saveInterest > 0)
         *  {
         *      //Yearly interest to daily interest
         *      decimal dailyInterest = (decimal)Math.Pow(1 + (double)_saveInterest / 100.0, 1.0 / 365.0) - 1;
         *
         *      //How much to add
         *      decimal amount = Math.Round(Balance * dailyInterest, 2);
         *
         *      //Add the rent to the account
         *      Balance = Balance + amount;
         *
         *      Console.WriteLine("Sparränta har adderats till konto {0}.", AccountNumber);
         *
         *      InterestTransaction transaction = new InterestTransaction(DateTime.Now, AccountNumber, amount, Balance);
         *      return transaction;
         *  }
         *
         *  return null;
         * }*/

        public InterestTransaction AddDailyInterest()
        {
            decimal dailyInterest = 0;

            //Calculate the interest
            //If debt
            if (Balance < 0 && _debtInterest > 0)
            {
                dailyInterest = (decimal)Math.Pow(1 + (double)_debtInterest / 100.0, 1.0 / 365.0) - 1;
                Console.WriteLine("Skuldränta har tagits ifrån konto {0}.", AccountNumber);
            }
            //If savings
            else if (Balance > 0 && _saveInterest > 0)
            {
                dailyInterest = (decimal)Math.Pow(1 + (double)_saveInterest / 100.0, 1.0 / 365.0) - 1;
                Console.WriteLine("Sparränta har adderats till konto {0}.", AccountNumber);
            }

            if (dailyInterest != 0)
            {
                //How much to add/remove from the account (Balance is negative => amount is negative)
                decimal amount = Math.Round(Balance * dailyInterest, 2);

                Balance = Balance + amount;

                InterestTransaction transaction = new InterestTransaction(DateTime.Now, AccountNumber, +amount, Balance);
                return(transaction);
            }

            return(null);
        }
        public decimal YearToDateInterestEarned()
        {
            decimal startingBalance = 0;
            decimal interestRate    = InterestRate;
            var     intTrans        = new List <InterestTransaction>();

            foreach (var t in Transactions)
            {
                var intTx = new InterestTransaction(t.TransactionDate, t.Amount);
                intTrans.Add(intTx);
            }
            decimal interest = CompoundInterestCalculator.CalculateYearToDateInterest(startingBalance, interestRate, intTrans.ToArray());

            return(Math.Round(interest, 2));
        }