94 subroutine tvm12_solve(n, i, pv, pmt, fv, pmt_time, unknown, status)
95 integer(kind=ik),
intent(inout) :: n
96 real(kind=rk),
intent(inout) :: i, pv, pmt, fv
97 integer(kind=ik),
intent(in) :: pmt_time, unknown
98 integer(kind=ik),
intent(out) :: status
99 real (kind=rk) :: ip1tn, tmp1, tmp2, islvivl0(3), islvivl1(3), r_dat(4)
100 integer(kind=ik) :: i_dat(2)
101 if (unknown /=
var_n)
then
111 if (unknown /=
var_i)
then
120 r_dat = [ i, pv, pmt, fv ]
121 i_dat = [ n, pmt_time ]
127 pmt = i * (fv + ip1tn * pv) / (i + 1 - (1+i) * ip1tn)
129 else if (unknown ==
var_i)
then
132 if (status /= 0)
then
135 else if (unknown ==
var_n)
then
136 tmp1 = ((-1 - i) * pmt - pv * i) / ((-1 - i) * pmt + fv * i)
141 n = nint(-log(tmp1) / log(tmp2), kind=ik)
144 else if (unknown ==
var_pv)
then
145 pv = ((pmt * (1 + i) - fv * i) * (1 + i) ** (-n) - pmt * (1 + i)) / i
147 else if (unknown ==
var_fv)
then
148 fv = (((-1 - i) * pmt - pv * i) * ip1tn + pmt * (1 + i)) / i
153 pmt = -i / (ip1tn - 1) * (fv + ip1tn * pv)
155 else if (unknown ==
var_i)
then
158 if (status /= 0)
then
161 else if (unknown ==
var_n)
then
162 tmp1 = (-pv * i - pmt) / (fv * i - pmt)
167 n = nint(-log(tmp1) / log(tmp2), kind=ik)
170 else if (unknown ==
var_pv)
then
171 pv = ((-fv * i + pmt) / ip1tn - pmt) / i
173 else if (unknown ==
var_fv)
then
174 fv = ((-pv * i - pmt) * ip1tn + pmt) / i
185 real(kind=rk),
intent(in) :: x
186 i_slv_func = (((-pmt_time * pmt + fv) * x - pmt) * (1 + x) ** (-n) + (pmt_time * pmt + pv) * x + pmt) / x
94 subroutine tvm12_solve(n, i, pv, pmt, fv, pmt_time, unknown, status)
…
220 integer(kind=ik),
intent(in) :: n, pmt_time, print_out
221 real(kind=rk),
intent(in) :: i, pv, fv, pmt
222 real (kind=rk) :: tot_pmt, cur_pv
223 integer(kind=ik) :: k
226 stop
"ERROR(tvm_solve): Unsupported value for pmt_time (must be one of pmt_at_beginning or pmt_at_end)"
232 print
"(a20,i30)",
"n:", n
233 print
"(a20,f30.8)",
"i:", i
234 print
"(a20,f30.8)",
"pv:", pv
235 print
"(a20,f30.8)",
"fv:", fv
236 print
"(a20,f30.8)",
"pmt:", pmt
238 print
"(a20,a30)",
"pmt_time:",
"BEGIN"
240 print
"(a20,a30)",
"pmt_time:",
"END"
252 print
"(i8,2(1x,"//cnfmt//
"))", k, cur_pv, tot_pmt
253 tot_pmt = tot_pmt + pmt
254 cur_pv = cur_pv + pmt
255 cur_pv = cur_pv + cur_pv * i
257 print
"(i8,2(1x,"//cnfmt//
"))", k, cur_pv, tot_pmt
258 cur_pv = cur_pv + cur_pv * i
259 tot_pmt = tot_pmt + pmt
260 cur_pv = cur_pv + pmt
real(kind=rk) function i_slv_func(x)
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_subsetp(bitset1, bitset2)
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.
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_title
Print titles on the tables.
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...
Provides a TVM solver with functionality similar to modern financial calculators.
subroutine, public tvm12_print(n, i, pv, pmt, fv, pmt_time, print_out)
Print TVM Problem (variables and/or table)
integer(kind=ik), parameter, public pmt_at_beginning
subroutine, public tvm12_solve(n, i, pv, pmt, fv, pmt_time, unknown, status)
Solve TVM Equation.
integer(kind=ik), parameter, public pmt_at_end
Constants to to identify TVM variables.
integer(kind=ik), parameter, public var_pv
Present value.
integer(kind=ik), parameter, public var_fv
Future value.
integer(kind=ik), parameter, public var_n
Number of periods.
integer(kind=ik), parameter, public var_pmt
Currently this is only used by the tvm12 module.
integer(kind=ik), parameter, public var_i
Interest/rate (First rate for geometric annuity)