Loading [MathJax]/extensions/tex2jax.js
MRFFL: MR Fortran Finance Library 2024-12-28
Computational Tools For Finance
All Namespaces Files Functions Variables
mrffl_cashflows Module Reference

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.
 

Detailed Description

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.

Function/Subroutine Documentation

◆ cashflow_vector_total_pv()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cashflow_matrix_total_pv()

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.

Parameters
cf_matMatrix of cashflows (one cashflow sequence per column)
iInterest/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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cashflow_vector_irr()

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.

Parameters
cf_vecVector of cashflows
irrIf the solver is successful, this will be the irr on return.
statusReturns 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.

Here is the call graph for this function:

◆ cashflow_matrix_irr()

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.

Parameters
cf_matMatrix of cashflows (one cashflow sequence per column)
irrIf the solver is successful, this will be the irr on return.
statusReturns 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.

Here is the call graph for this function:

◆ i2s()

character(len=5) function mrffl_cashflows::i2s ( integer(kind=ik), intent(in) n)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cashflow_vector_pv_fv()

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.

See: cashflow_matrix_pv_fv()

Definition at line 204 of file mrffl_cashflows.f90.

References cashflow_matrix_pv_fv_print(), and mrffl_prt_sets::prt_none.

Here is the call graph for this function:

◆ cashflow_vector_pv_fv_print()

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().

Here is the call graph for this function:

◆ cashflow_matrix_pv_fv()

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.

Parameters
cf_matMatrix of cashflows (one cashflow sequence per column)
iInterest/Rate/Growth
pv_vecReturns the present value vector
fv_vecReturns the future value vector
statusReturns 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.

Here is the call graph for this function:

◆ cashflow_matrix_pv_fv_print()

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.

Parameters
cf_matMatrix of cashflows (one cashflow sequence per column)
iInterest/Rate/Growth
pv_vecReturns the present value vector
fv_vecReturns the future value vector
statusReturns status of operation. 0 if everything worked. Range: 0 & 2129-2160.
print_outBitset 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_cashflow_vector_delayed_lump()

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.

Parameters
cf_vecThe resulting cashflow vector.
aThe cashflow amount.
dDelay from time zero. i.e. d=0 is the beginning of period 1 otherwise d=j is the end if period j.
statusReturns status of computation. 0 if everything worked. Range: 0 & 2097-2128.

Definition at line 357 of file mrffl_cashflows.f90.

◆ make_cashflow_vector_delayed_level_annuity()

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.

Parameters
cf_vecThe resulting cashflow vector.
aAnnuity payment.
dDelay from time zero. i.e. d=0 is the beginning of period 1 otherwise d=j is the end if period j.
eEarly end counted from time end (t=n). i.e. e=0 means the last payment is at end of period n.
statusReturns status of computation. 0 if everything worked. Range: 0 & 2065-2096.

Definition at line 390 of file mrffl_cashflows.f90.

◆ make_cashflow_vector_delayed_geometric_annuity()

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.

Parameters
cf_vecThe resulting cashflow vector.
gGrowth rate as a percentage.
aFirst annuity payment.
dDelay from time zero. i.e. d=0 is the beginning of period 1 otherwise d=j is the end if period j.
eEarly end counted from time end (t=n). i.e. e=0 means the last payment is at end of period n.
statusReturns 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().

Here is the call graph for this function:

◆ make_cashflow_vector_delayed_arithmetic_annuity()

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.

Parameters
cf_vecThe resulting cashflow vector.
qAmount added at each payment.
aFirst annuity payment.
dDelay from time zero. i.e. d=0 is the beginning of period 1 otherwise d=j is the end if period j.
eEarly end counted from time end (t=n). i.e. e=0 means the last payment is at end of period n.
statusReturns status of computation. 0 if everything worked. Range: 0 & 2001- 2032.

Definition at line 468 of file mrffl_cashflows.f90.

◆ add_intrest_to_cashflow_vector()

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.

Parameters
cf_vecThe cashflow vector to modify (one cashflow per period boundary).
rateThe rate
statusReturns 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().

Here is the call graph for this function:

◆ add_multi_intrest_to_cashflow_vector()

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.

Parameters
cf_vecThe cashflow vector to modify (one cashflow per period boundary).
vrateA vector of rates (one rate per period).
statusReturns 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().

Here is the call graph for this function: