15.05.2020       Выпуск 334 (11.05.2020 - 17.05.2020)       Статьи

Моделирование потока денег

Читать>>




Экспериментальная функция:

Ниже вы видите текст статьи по ссылке. По нему можно быстро понять ссылка достойна прочтения или нет

Просим обратить внимание, что текст по ссылке и здесь может не совпадать.

Cash-flow Modelling

Our model calculations all use Numpy arrays — this helps in two ways; (1) calculations for all loans are done in parallel, and (2) Numpy actually compiles into C code, which is significantly faster than Python.

Initialization

Because we are using arrays, we first need to create them. There are two different types arrays that we will use here. The first containing values to be calculated. For these we simply initialize zero arrays.

The second are arrays containing data from loanbook, cpr, and erc.

From loanbook, we first build the rate array.

Then we initialize the arrays where the values from loanbook are used in month zero.

Both cpr and erc dataframes are used as lookup arrays, because of this they do not match the row-axis dimension of loanbook:

Fortunately, we can use the same code to translate both into the correct format.

Modelling

Now everything is initialized, we can move onto the actual cash-flow modelling.

The model calculates per month. We start at month one, calculate all values for that month, then increase the month. Once we reach the final month defined by m_max modelling is complete and outputs our results. This is implemented in a loop with for m in range(1, m_max).

For every month, several calculations are performed. These are:

statement_interest
cumulative_amortisation
cumulative_payment
scheduled_payment
early_repayment
early_repayment_charge
cashflow
statement_amount






First, we calculate statement_interest, cumulative_amortisation, and cumulative_payment. Note that array vectors for the current month are indicated by [:, m], whereas previous month values are indicated by [:, m-1].

For scheduled_payment, we must use an if-else statement due to additional reversion date logic. To implement this in a vectorized* fashion, we define the calculation function in scheduled_payment_calc then use np.vectorize (note that these should be defined outside of the loop).

early_repayment is another if-else statement function, albeit much simpler.

The remaining calculations are again much simpler.

Finally, we have our cash-flows! We can see the way each array evolves over time by visualizing them as line-plots, with the month number on the x-axis.






Разместим вашу рекламу

Пиши: mail@pythondigest.ru

Нашли опечатку?

Выделите фрагмент и отправьте нажатием Ctrl+Enter.

Система Orphus