106 real(kind=rk),
intent(in) :: cf_vec(:)
107 real(kind=rk),
intent(in) :: i
108 integer(kind=ik) :: j
126 real(kind=rk),
intent(in) :: cf_mat(:,:)
127 real(kind=rk),
intent(in) :: i
129 integer(kind=ik) :: j, k
131 do j=1,
size(cf_mat, 1)
133 do k=2,
size(cf_mat, 2)
134 cf = cf + cf_mat(j, k)
148 real(kind=rk),
intent(in) :: cf_vec(:)
149 real(kind=rk),
intent(inout) :: irr
150 integer(kind=ik),
intent(out) :: status
154 if (status /= 0)
then
160 real(kind=rk),
intent(in) :: i
173 real(kind=rk),
intent(in) :: cf_mat(:,:)
174 real(kind=rk),
intent(inout) :: irr
175 integer(kind=ik),
intent(out) :: status
179 if (status /= 0)
then
185 real(kind=rk),
intent(in) :: i
193 character(len=5) function i2s(n)
195 integer(kind=ik),
intent(in) :: n
196 write(
i2s,
'(i5.5)') n
193 character(len=5) function i2s(n)
…
205 real(kind=rk),
intent(in) :: cf_vec(:)
206 real(kind=rk),
intent(in) :: i
207 real(kind=rk),
intent(out) :: pv_vec(:), fv_vec(:)
208 integer(kind=ik),
intent(out) :: status
218 real(kind=rk),
intent(in) :: cf_vec(:)
219 real(kind=rk),
intent(in) :: i
220 real(kind=rk),
intent(out) :: pv_vec(:), fv_vec(:)
221 integer(kind=ik),
intent(out) :: status
222 integer(kind=ik),
intent(in) :: print_out
236 real(kind=rk),
intent(in) :: cf_mat(:,:)
237 real(kind=rk),
intent(in) :: i
238 real(kind=rk),
intent(out) :: pv_vec(:), fv_vec(:)
239 integer(kind=ik),
intent(out) :: status
256 real(kind=rk),
intent(in) :: cf_mat(:,:)
257 real(kind=rk),
intent(in) :: i
258 real(kind=rk),
intent(out) :: pv_vec(:), fv_vec(:)
259 integer(kind=ik),
intent(out) :: status
260 integer(kind=ik),
intent(in) :: print_out
261 integer(kind=ik) :: num_bdrys, num_flows, j, flow
262 real(kind=rk),
allocatable :: dfactors(:), cf_aggr(:), total_pv(:), total_fv(:)
263 num_bdrys =
size(cf_mat, 1, kind=ik)
264 num_flows =
size(cf_mat, 2, kind=ik)
265 if (num_flows < 1)
then
271 else if (num_bdrys < 2)
then
274 else if (num_bdrys >
size(pv_vec))
then
277 else if (num_bdrys >
size(fv_vec))
then
286 cf_aggr = sum(cf_mat,2)
288 dfactors = [(1,j=1,num_bdrys)]
292 pv_vec = cf_aggr / dfactors
293 fv_vec = cf_aggr * dfactors(num_bdrys:1:-1)
296 print
"(a15, i25)",
"Period Count: ", (num_bdrys-1)
297 print
"(a15, f25.4)",
"Discount Rate: ", i
303 if (num_flows > 1)
then
304 print
"(a6,*("//ctfmt//
"))",
"Time", (
"CF_"//
i2s(flow), flow = 1_rk, num_flows ), &
305 "CF_Aggregate",
"PV",
"FV",
"PV_Total",
"FV_Total"
307 print
"(a6,*("//ctfmt//
"))",
"Time",
"CF",
"PV",
"FV",
"PV_Total",
"FV_Total"
312 if (num_flows > 1)
then
313 print
"(i6,*("//cnfmt//
"))", (j-1), cf_mat(j, :), cf_aggr(j), pv_vec(j), fv_vec(j), sum(pv_vec(1:j)), sum(fv_vec(1:j))
315 print
"(i6,5("//cnfmt//
"))", (j-1), cf_aggr(j), pv_vec(j), fv_vec(j), sum(pv_vec(1:j)), sum(fv_vec(1:j))
324 if (num_flows > 1)
then
325 print
"(a6,*("//ctfmt//
"))",
"", (
"CF_"//
i2s(flow), flow = 1, num_flows ),
"CF_Aggregate"
327 print
"(a6,*("//ctfmt//
"))",
"",
"CF"
330 total_pv = [(sum(cf_mat(:,flow) / dfactors), flow = 1, num_flows)]
331 total_fv = [(sum(cf_mat(:,flow) * dfactors(num_bdrys:1:-1)), flow = 1, num_flows)]
332 if (num_flows > 1)
then
333 print
"(a6,*("//cnfmt//
"))",
"PV", total_pv, sum(pv_vec)
334 print
"(a6,*("//cnfmt//
"))",
"FV", total_fv, sum(fv_vec)
336 print
"(a6,*("//cnfmt//
"))",
"PV", total_pv
337 print
"(a6,*("//cnfmt//
"))",
"FV", total_fv
359 real(kind=rk),
intent(out) :: cf_vec(:)
360 real(kind=rk),
intent(in) :: a
361 integer(kind=ik),
intent(in) :: d
362 integer(kind=ik),
intent(out) :: status
391 real(kind=rk),
intent(out) :: cf_vec(:)
392 real(kind=rk),
intent(in) :: a
393 integer(kind=ik),
intent(in) :: d, e
394 integer(kind=ik),
intent(out) :: status
407 else if ((d+e) > n)
then
411 cf_vec(1+d:1+n-e) = a
430 real(kind=rk),
intent(out) :: cf_vec(:)
431 real(kind=rk),
intent(in) :: g, a
432 integer(kind=ik),
intent(in) :: d, e
433 integer(kind=ik),
intent(out) :: status
446 else if ((d+e) > n)
then
469 real(kind=rk),
intent(out) :: cf_vec(:)
470 real(kind=rk),
intent(in) :: q, a
471 integer(kind=ik),
intent(in) :: d, e
472 integer(kind=ik),
intent(out) :: status
485 else if ((d+e) > n)
then
489 cf_vec(1+d:1+n-e) = [((a+q*j),j=0,n-e-d)]
503 real(kind=rk),
intent(out) :: cf_vec(:)
504 real(kind=rk),
intent(in) :: rate
505 integer(kind=ik),
intent(out) :: status
507 real(kind=rk) :: rsum
513 rsum = rsum + cf_vec(j)
528 real(kind=rk),
intent(out) :: cf_vec(:)
529 real(kind=rk),
intent(in) :: vrate(:)
530 integer(kind=ik),
intent(out) :: status
532 real(kind=rk) :: rsum
535 if (
size(vrate) < (nb-1))
then
541 rsum = rsum + cf_vec(j)
real(kind=rk) function irr_solve(i)
Simple sets (using the bits of an integer to indicate element existence).
logical pure function, public bitset_intersectp(bitset1, bitset2)
logical pure function, public bitset_not_subsetp(bitset1, bitset2)
logical pure function, public bitset_subsetp(bitset1, bitset2)
Tools for TVM computations with irregular/uneven cashflows.
real(kind=rk) pure function, public cashflow_vector_total_pv(cf_vec, i)
Compute pv for a cashflow vector.
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 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 bari...
subroutine, public make_cashflow_vector_delayed_arithmetic_annuity(cf_vec, q, a, d, e, status)
Create a cashflow of payments for an arithmatic annuity.
character(len=5) function i2s(n)
Convert a cashflow number into a padded string for titles.
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 cashflow_matrix_irr(cf_mat, irr, status)
Compute IRR for a cashflow matrix.
subroutine, public make_cashflow_vector_delayed_geometric_annuity(cf_vec, g, a, d, e, status)
Create a cashflow of payments for a growing annuity.
real(kind=rk) pure function, public cashflow_matrix_total_pv(cf_mat, i)
Compute pv 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 cashflow_matrix_pv_fv(cf_mat, i, pv_vec, fv_vec, status)
Compute present and future values for a cashflow matrix.
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 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 bari...
subroutine, public make_cashflow_vector_delayed_lump(cf_vec, a, d, status)
Create a cashflow with a single (lump sum) payment.
subroutine, public cashflow_vector_irr(cf_vec, irr, status)
Compute IRR for a cashflow vector.
Configuration for MRFFL (MR Fortran Finance Library).
integer, parameter, public mrfflrk
Real kind used in interfaces.
real(kind=mrfflrk), parameter, public zero_epsilon
Used to test for zero.
integer, parameter, public mrfflik
Integer kinds used in interfaces.
character(len=5), public mrfflcnfmt
Used to print cash values.
character(len=5), public mrfflctfmt
Used to print cash titles.
Simple functions for working with percentages.
elemental real(kind=rk) function, public percentage_to_fraction(p)
Convert a percentage to a fraction.
Constants to select what *_print subroutines will print.
integer(kind=ik), parameter, public prt_table
Print a table.
integer(kind=ik), parameter, public prt_param
Print parameters before the table/titles.
integer(kind=ik), parameter, public prt_total
Print totals PV & FV after the table.
integer(kind=ik), parameter, public prt_title
Print titles on the tables.
integer(kind=ik), parameter, public prt_space
Print vertical whitespace between parameters & table/titles & totals.
integer(kind=ik), parameter, public prt_none
Print nothing.
subroutine, public multi_bisection(xc, x0_init, x1_init, f, x_epsilon, y_epsilon, max_itr, status, progress)
Use bisection() to search for a root for the function f in a list of intervals returning the first ro...