MRFFL: MR Fortran Finance Library 2024-12-28
Computational Tools For Finance
|
Tools for TVM computations with irregular/uneven cashflows. More...
Functions/Subroutines | |
real(kind=rk) pure function, public | cashflow_vector_total_pv (cf_vec, i) |
Compute pv for a cashflow vector. | |
real(kind=rk) pure function, public | cashflow_matrix_total_pv (cf_mat, i) |
Compute pv for a cashflow matrix. | |
subroutine, public | cashflow_vector_irr (cf_vec, irr, status) |
Compute IRR for a cashflow vector. | |
subroutine, public | cashflow_matrix_irr (cf_mat, irr, status) |
Compute IRR for a cashflow matrix. | |
character(len=5) function | i2s (n) |
Convert a cashflow number into a padded string for titles. | |
subroutine, public | cashflow_vector_pv_fv (cf_vec, i, pv_vec, fv_vec, status) |
Compute present and future values for a cashflow vector. | |
subroutine, public | cashflow_vector_pv_fv_print (cf_vec, i, pv_vec, fv_vec, status, print_out) |
Compute present and future values for a cashflow vector. | |
subroutine, public | cashflow_matrix_pv_fv (cf_mat, i, pv_vec, fv_vec, status) |
Compute present and future values for a cashflow matrix. | |
subroutine, public | cashflow_matrix_pv_fv_print (cf_mat, i, pv_vec, fv_vec, status, print_out) |
Compute present and future values for a cashflow matrix. | |
subroutine, public | make_cashflow_vector_delayed_lump (cf_vec, a, d, status) |
Create a cashflow with a single (lump sum) payment. | |
subroutine, public | make_cashflow_vector_delayed_level_annuity (cf_vec, a, d, e, status) |
Create a cashflow of payments for a fixed annuity. | |
subroutine, public | make_cashflow_vector_delayed_geometric_annuity (cf_vec, g, a, d, e, status) |
Create a cashflow of payments for a growing annuity. | |
subroutine, public | make_cashflow_vector_delayed_arithmetic_annuity (cf_vec, q, a, d, e, status) |
Create a cashflow of payments for an arithmatic annuity. | |
subroutine, public | add_intrest_to_cashflow_vector (cf_vec, rate, status) |
Add interest cashflows to a cashflow sequence as if the sequence were being added to an interest baring account over time. | |
subroutine, public | add_multi_intrest_to_cashflow_vector (cf_vec, vrate, status) |
Add interest cashflows to a cashflow sequence as if the sequence were being added to an interest baring account over time. | |
Tools for TVM computations with irregular/uneven cashflows.
The traditional definition of a cashflow is money received (positive) or paid (negative). A cashflow stream or series (or sequence) is one or more cashflows received over a period of time. Time up into a series of discreet "periods" corresponding naturally to the problem at hand. Each cashflow occurs at the beginning or ending of one of these periods. For example, we might break time up into months to model the cashflows related to a loan. Software approaches vary with regard to how cashflows are entered, stored, and processed.
In this library the time of a cashflow is specified by the period boundary on which it occurs – i.e. we say "boundary 1" instead of the equivalent possibilities of "the end of period 1" or "the beginning of period 2". An n period cashflow is stored in a simple array (or a column of a matrix) with capacity for n+1 elements (one for each boundary) – note that is one more than the number of periods. The first element of a cash flow array represents time zero and is the beginning of time period 1. The second element of the array represents the end of time period 1 or the beginning of time period 2. The last element represents the end of the final period – i.e. period n.
Consider an example. We get a loan for 1000 over 6 months with a monthly interest rate of 1%. This is a 6 period cash flow with the principal received at the beginning of period 1. Conventionally we think of the first payment occurring at the end of period 1; however, we could think of this payment as occurring at the beginning of period 2. For this example, th cashflow array would be: [1000, -172.55, -172.55, -172.55, -172.55, -172.55, -172.55]. In tabular form:
Array Index Cashflow 1 1000.00 ==> Time 0 (start of 1st period) 2 -172.55 3 -172.55 4 -172.55 5 -172.55 6 -172.55 7 -172.55 ==> Time 6 (end of 6th period)
This library encourages the use of multiple cashflow series for problem solving. Each cashflow sequence is stored as the column of a matrix. The entire matrix may then be used for TVM calculations.
real(kind=rk) pure function, public mrffl_cashflows::cashflow_vector_total_pv | ( | real(kind=rk), dimension(:), intent(in) | cf_vec, |
real(kind=rk), intent(in) | i ) |
Compute pv for a cashflow vector.
See: cashflow_matrix_total_pv()
Definition at line 105 of file mrffl_cashflows.f90.
References cashflow_vector_total_pv(), and mrffl_percentages::percentage_to_fraction().
Referenced by cashflow_vector_total_pv(), and irr_solve().
real(kind=rk) pure function, public mrffl_cashflows::cashflow_matrix_total_pv | ( | real(kind=rk), dimension(:,:), intent(in) | cf_mat, |
real(kind=rk), intent(in) | i ) |
Compute pv for a cashflow matrix.
In this library, initial cashflows are simply at time 0. NPV and PV are the same value in this context. The value returned by this function is identical to summing the pv_vec returned by cashflow_matrix_pv_fv; however, this function is much faster and requires no temporary arrays.
cf_mat | Matrix of cashflows (one cashflow sequence per column) |
i | Interest/Rate/Growth |
Definition at line 125 of file mrffl_cashflows.f90.
References cashflow_matrix_total_pv(), and mrffl_percentages::percentage_to_fraction().
Referenced by cashflow_matrix_irr(), and cashflow_matrix_total_pv().
subroutine, public mrffl_cashflows::cashflow_vector_irr | ( | real(kind=rk), dimension(:), intent(in) | cf_vec, |
real(kind=rk), intent(inout) | irr, | ||
integer(kind=ik), intent(out) | status ) |
Compute IRR for a cashflow vector.
cf_vec | Vector of cashflows |
irr | If the solver is successful, this will be the irr on return. |
status | Returns status of computation. 0 if everything worked. Range: 0 & 4193-4224 |
Definition at line 147 of file mrffl_cashflows.f90.
References irr_solve(), mrffl_solver::multi_bisection(), and mrffl_config::zero_epsilon.
subroutine, public mrffl_cashflows::cashflow_matrix_irr | ( | real(kind=rk), dimension(:,:), intent(in) | cf_mat, |
real(kind=rk), intent(inout) | irr, | ||
integer(kind=ik), intent(out) | status ) |
Compute IRR for a cashflow matrix.
cf_mat | Matrix of cashflows (one cashflow sequence per column) |
irr | If the solver is successful, this will be the irr on return. |
status | Returns status of computation. 0 if everything worked. Range: 0 & 4193-4224 |
Definition at line 172 of file mrffl_cashflows.f90.
References cashflow_matrix_total_pv(), irr_solve(), mrffl_solver::multi_bisection(), and mrffl_config::zero_epsilon.
|
private |
Convert a cashflow number into a padded string for titles.
Definition at line 193 of file mrffl_cashflows.f90.
References i2s().
Referenced by cashflow_matrix_pv_fv_print(), and i2s().
subroutine, public mrffl_cashflows::cashflow_vector_pv_fv | ( | real(kind=rk), dimension(:), intent(in) | cf_vec, |
real(kind=rk), intent(in) | i, | ||
real(kind=rk), dimension(:), intent(out) | pv_vec, | ||
real(kind=rk), dimension(:), intent(out) | fv_vec, | ||
integer(kind=ik), intent(out) | status ) |
Compute present and future values for a cashflow vector.
Definition at line 204 of file mrffl_cashflows.f90.
References cashflow_matrix_pv_fv_print(), and mrffl_prt_sets::prt_none.
subroutine, public mrffl_cashflows::cashflow_vector_pv_fv_print | ( | real(kind=rk), dimension(:), intent(in) | cf_vec, |
real(kind=rk), intent(in) | i, | ||
real(kind=rk), dimension(:), intent(out) | pv_vec, | ||
real(kind=rk), dimension(:), intent(out) | fv_vec, | ||
integer(kind=ik), intent(out) | status, | ||
integer(kind=ik), intent(in) | print_out ) |
Compute present and future values for a cashflow vector.
See: cashflow_matrix_pv_fv_print()
Definition at line 217 of file mrffl_cashflows.f90.
References cashflow_matrix_pv_fv_print().
subroutine, public mrffl_cashflows::cashflow_matrix_pv_fv | ( | real(kind=rk), dimension(:,:), intent(in) | cf_mat, |
real(kind=rk), intent(in) | i, | ||
real(kind=rk), dimension(:), intent(out) | pv_vec, | ||
real(kind=rk), dimension(:), intent(out) | fv_vec, | ||
integer(kind=ik), intent(out) | status ) |
Compute present and future values for a cashflow matrix.
cf_mat | Matrix of cashflows (one cashflow sequence per column) |
i | Interest/Rate/Growth |
pv_vec | Returns the present value vector |
fv_vec | Returns the future value vector |
status | Returns status of operation. 0 if everything worked. See: cashflow_matrix_pv_fv_print() for range. |
Definition at line 235 of file mrffl_cashflows.f90.
References cashflow_matrix_pv_fv_print(), and mrffl_prt_sets::prt_none.
subroutine, public mrffl_cashflows::cashflow_matrix_pv_fv_print | ( | real(kind=rk), dimension(:,:), intent(in) | cf_mat, |
real(kind=rk), intent(in) | i, | ||
real(kind=rk), dimension(:), intent(out) | pv_vec, | ||
real(kind=rk), dimension(:), intent(out) | fv_vec, | ||
integer(kind=ik), intent(out) | status, | ||
integer(kind=ik), intent(in) | print_out ) |
Compute present and future values for a cashflow matrix.
As a side effect, the cashflows may be printed.
cf_mat | Matrix of cashflows (one cashflow sequence per column) |
i | Interest/Rate/Growth |
pv_vec | Returns the present value vector |
fv_vec | Returns the future value vector |
status | Returns status of operation. 0 if everything worked. Range: 0 & 2129-2160. |
print_out | Bitset built from the following constants prt_param, prt_title, prt_table, prt_total, & prt_space |
Definition at line 255 of file mrffl_cashflows.f90.
References mrffl_bitset::bitset_intersectp(), mrffl_bitset::bitset_not_subsetp(), mrffl_bitset::bitset_subsetp(), i2s(), mrffl_percentages::percentage_to_fraction(), mrffl_prt_sets::prt_param, mrffl_prt_sets::prt_space, mrffl_prt_sets::prt_table, mrffl_prt_sets::prt_title, mrffl_prt_sets::prt_total, and mrffl_config::zero_epsilon.
Referenced by cashflow_matrix_pv_fv(), cashflow_vector_pv_fv(), and cashflow_vector_pv_fv_print().
subroutine, public mrffl_cashflows::make_cashflow_vector_delayed_lump | ( | real(kind=rk), dimension(:), intent(out) | cf_vec, |
real(kind=rk), intent(in) | a, | ||
integer(kind=ik), intent(in) | d, | ||
integer(kind=ik), intent(out) | status ) |
Create a cashflow with a single (lump sum) payment.
The number of periods is assumed from the size of the cashflow vector at size(cashflow)-1. All payments other than the lump sum payment are set to zero.
cf_vec | The resulting cashflow vector. |
a | The cashflow amount. |
d | Delay from time zero. i.e. d=0 is the beginning of period 1 otherwise d=j is the end if period j. |
status | Returns status of computation. 0 if everything worked. Range: 0 & 2097-2128. |
Definition at line 357 of file mrffl_cashflows.f90.
subroutine, public mrffl_cashflows::make_cashflow_vector_delayed_level_annuity | ( | real(kind=rk), dimension(:), intent(out) | cf_vec, |
real(kind=rk), intent(in) | a, | ||
integer(kind=ik), intent(in) | d, | ||
integer(kind=ik), intent(in) | e, | ||
integer(kind=ik), intent(out) | status ) |
Create a cashflow of payments for a fixed annuity.
The number of periods is assumed from the size of the cashflow vector at size(cashflow)-1. All payments other than the annuity payments are set to zero.
cf_vec | The resulting cashflow vector. |
a | Annuity payment. |
d | Delay from time zero. i.e. d=0 is the beginning of period 1 otherwise d=j is the end if period j. |
e | Early end counted from time end (t=n). i.e. e=0 means the last payment is at end of period n. |
status | Returns status of computation. 0 if everything worked. Range: 0 & 2065-2096. |
Definition at line 390 of file mrffl_cashflows.f90.
subroutine, public mrffl_cashflows::make_cashflow_vector_delayed_geometric_annuity | ( | real(kind=rk), dimension(:), intent(out) | cf_vec, |
real(kind=rk), intent(in) | g, | ||
real(kind=rk), intent(in) | a, | ||
integer(kind=ik), intent(in) | d, | ||
integer(kind=ik), intent(in) | e, | ||
integer(kind=ik), intent(out) | status ) |
Create a cashflow of payments for a growing annuity.
The number of periods is assumed from the size of the cashflow vector at size(cashflow)-1. All payments other than the annuity payments are set to zero.
cf_vec | The resulting cashflow vector. |
g | Growth rate as a percentage. |
a | First annuity payment. |
d | Delay from time zero. i.e. d=0 is the beginning of period 1 otherwise d=j is the end if period j. |
e | Early end counted from time end (t=n). i.e. e=0 means the last payment is at end of period n. |
status | Returns status of computation. 0 if everything worked. Range: 0 & 2033-2064. |
Definition at line 429 of file mrffl_cashflows.f90.
References mrffl_percentages::percentage_to_fraction().
subroutine, public mrffl_cashflows::make_cashflow_vector_delayed_arithmetic_annuity | ( | real(kind=rk), dimension(:), intent(out) | cf_vec, |
real(kind=rk), intent(in) | q, | ||
real(kind=rk), intent(in) | a, | ||
integer(kind=ik), intent(in) | d, | ||
integer(kind=ik), intent(in) | e, | ||
integer(kind=ik), intent(out) | status ) |
Create a cashflow of payments for an arithmatic annuity.
The number of periods is assumed from the size of the cashflow vector at size(cashflow)-1. All payments other than the annuity payments are set to zero.
cf_vec | The resulting cashflow vector. |
q | Amount added at each payment. |
a | First annuity payment. |
d | Delay from time zero. i.e. d=0 is the beginning of period 1 otherwise d=j is the end if period j. |
e | Early end counted from time end (t=n). i.e. e=0 means the last payment is at end of period n. |
status | Returns status of computation. 0 if everything worked. Range: 0 & 2001- 2032. |
Definition at line 468 of file mrffl_cashflows.f90.
subroutine, public mrffl_cashflows::add_intrest_to_cashflow_vector | ( | real(kind=rk), dimension(:), intent(out) | cf_vec, |
real(kind=rk), intent(in) | rate, | ||
integer(kind=ik), intent(out) | status ) |
Add interest cashflows to a cashflow sequence as if the sequence were being added to an interest baring account over time.
cf_vec | The cashflow vector to modify (one cashflow per period boundary). |
rate | The rate |
status | Returns status of computation. 0 if everything worked. Range: 0 & 4033-4064. |
Definition at line 501 of file mrffl_cashflows.f90.
References mrffl_percentages::percentage_to_fraction().
subroutine, public mrffl_cashflows::add_multi_intrest_to_cashflow_vector | ( | real(kind=rk), dimension(:), intent(out) | cf_vec, |
real(kind=rk), dimension(:), intent(in) | vrate, | ||
integer(kind=ik), intent(out) | status ) |
Add interest cashflows to a cashflow sequence as if the sequence were being added to an interest baring account over time.
cf_vec | The cashflow vector to modify (one cashflow per period boundary). |
vrate | A vector of rates (one rate per period). |
status | Returns status of computation. 0 if everything worked. Range: 0 & 4065-4096. |
Definition at line 526 of file mrffl_cashflows.f90.
References mrffl_percentages::percentage_to_fraction().