Exemplo n.º 1
0
        private const int InitialMaturityLoan = 1;         // 20 years is more realistic.

        private void InitLoans(double totalDebt)
        {
            _loanPortfolio = new LoanPortfolio();
            var valueOfSingleLoan = totalDebt / InitialMaturityLoan;

            for (var maturity = 1; maturity <= InitialMaturityLoan; maturity++)
            {
                var interestRate = Economy.GetInterestRate(maturity);
                _loanPortfolio.AddNewLoan(valueOfSingleLoan, interestRate, maturity);
            }

            Debug.Assert(Math.Abs(_loanPortfolio.Debt - totalDebt) < 0.01);
        }
Exemplo n.º 2
0
        public void EndOfYear()
        {
            var expensesHouses = RealEstatePortfolio.EndOfYear();
            var earningsSales  = SellHouses();

            foreach (var newDevelopmentProjectType in NewDevelopmentProjectType.GetAll())
            {
                newDevelopmentProjectType.EndOfYear();
            }

            var expensesNewDevelopment = ExecuteNewDevelopmentProjects();

            foreach (var renovationProjectProjectType in RenovationProjectType.GetAll())
            {
                renovationProjectProjectType.EndOfYear();
            }

            var expensesRenovation = ExecuteRenovations();

            var expensesLoans = _loanPortfolio.EndOfYear();

            // If we have spent money we need to attract a new loan.
            var totalExpenses = expensesLoans + expensesHouses + AnnualCosts - _loanPortfolio.Cash - earningsSales + expensesNewDevelopment + expensesRenovation;

            if (totalExpenses > 0)
            {
                var previousDebt = _loanPortfolio.Debt;
                AttractLoan(totalExpenses);
                _loanPortfolio.Cash = 0;

                // Assert that a loan really has been attracted.
                Debug.Assert(Math.Abs(previousDebt + totalExpenses - _loanPortfolio.Debt) < 0.01);
            }
            else
            {
                _loanPortfolio.Cash = -totalExpenses;
            }

            CumulativeInflation *= Economy.Get(Series.PriceInflation) + 1;

            IsBankrupt |= SolvencyRatio < BankruptcyThreshold;
        }
Exemplo n.º 3
0
        public Dictionary <OutputType, double[][]> Run()
        {
            Console.Write(@"Simulating scenario ");

            for (var scenario = 0; scenario < NumberOfScenarios; scenario++)
            {
                Console.Write($@"{scenario + 1}");
                Console.SetCursorPosition(20, 1);

                Economy.Read(scenario);

                var association = new HousingAssociation(0);
                GatherData(association, scenario, 0);

                for (var t = 0; t <= Horizon; t++)
                {
                    Economy.CurrentYear = t;
                    association.EndOfYear();
                    GatherData(association, scenario, t + 1);
                }
            }

            return(_results);
        }