public Object GetTotalInvestment(InputModel input) { List <MonthlyOutputModel> completeInvest = new List <MonthlyOutputModel>(); decimal monthSubscription = input.subscription; decimal rate = input.rate; int tenor = input.months; decimal balance = input.balance; decimal interestEarned = 0.00m; decimal expectedMonthly = 0.00m; decimal TotalSubscription = 0.00m; decimal TotalInterest = 0.00m; decimal TotalInvestment = 0.00m; for (int i = 0; i < input.months; i++) { rate = input.rate; tenor = input.months; interestEarned = calculateMonthlyInterest(monthSubscription, rate, balance); expectedMonthly = calculateMonthlyBalance(monthSubscription, tenor, rate, balance); MonthlyOutputModel investment = new MonthlyOutputModel() { balance = balance, subscription = monthSubscription, interestEarned = interestEarned, closingBalance = expectedMonthly }; completeInvest.Add(investment); balance = expectedMonthly; } foreach (var element in completeInvest) { TotalSubscription += element.subscription; TotalInterest += element.interestEarned; } TotalInvestment = TotalSubscription + TotalInterest; TotalOutputModel totalOutput = new TotalOutputModel() { TotalSubscription = Math.Round(TotalSubscription, 2), TotalInterest = Math.Round(TotalInterest, 2), TotalInvestment = Math.Round(TotalInvestment, 2) }; return(totalOutput); }
public IEnumerable <MonthlyOutputModel> GetCompleteInvestment(InputModel input) { List <MonthlyOutputModel> completeInvest = new List <MonthlyOutputModel>(); decimal monthSubscription = input.subscription + 0.00m; decimal rate = input.rate; int tenor = input.months; decimal balance = input.balance + 0.00m; decimal interestEarned = 0.00m; decimal expectedMonthly = 0.00m; for (int i = 0; i < input.months; i++) { rate = input.rate; tenor = input.months; interestEarned = calculateMonthlyInterest(monthSubscription, rate, balance); expectedMonthly = calculateMonthlyBalance(monthSubscription, tenor, rate, balance); MonthlyOutputModel investment = new MonthlyOutputModel() { balance = Math.Round(balance, 2), subscription = Math.Round(monthSubscription, 2), interestEarned = Math.Round(interestEarned, 2), closingBalance = Math.Round(expectedMonthly, 2) }; completeInvest.Add(investment); balance = expectedMonthly; } return(completeInvest); }