Post Reply 
PC-1211, PC-1250, etc. TVM
06-09-2024, 12:06 AM (This post was last modified: 06-09-2024 12:31 AM by robve.)
Post: #35
RE: PC-1211, PC-1250, etc. TVM
(06-08-2024 11:47 PM)Albert Chan Wrote:  
(06-08-2024 09:21 PM)robve Wrote:  If you want another bewildering TVM problem:
B=1 (begin mode)
N=40
PV=900
PMT=1000
FV=-1000
What's the interest rate?
rate (%) = -49.9999999999977262632455656115

Yes, excellent! Indeed -50% is not the exact answer beyond 12 digits. It can't be, given the TVM parameters. So is the rate you get (on a calculator) a whole number? Probably yes, but it fools you.

EDIT: With my modified TVM program when written in C using double precision:

Code:
./tvm 40 900 1000 -1000 1

TVM n=40 pv=900 pmt=1000 fv=-1000 BGN
i%=0.5    y=1007.24
1 i%=-51.3178964    y=-26.35792804 (9)
2 i%=-49.99647502    y=0.07049954146 (8)
3 i%=-50    y=-1.705302566e-13 (7)
4 i%=-50    y=1.136868377e-13 (6)
5 i%=-50    y=1.136868377e-13 (5)
i%=-49.9999999999977192%

The C program:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

double n, pv, pmt, fv, i, b = 0;

double fsign(double x) { return copysign(x != 0, x); }

double fn()
{
  double j = 0.01*i;
  double k = 1.0 + j*b;
  double l = log1p(j);
  double r = expm1(-n*l);
  double s = r + 1.0;
  return k*pmt - (pv + fv*s)*j/r;
}

void solve()
{
  int g = 9;
  int k = 0;
  double v, w, y;
  i = 1;
  y = fn();
  do {
    v = i;
    i /= 2;
    w = y;
    y = fn();
  } while (fabs(y - w) < i);
  printf("i%%=%g\ty=%g\n", i, y);
  do {
    do {
      double t = i;
      i -= (i - v)*y/(y - w);
      v = t;
      w = y;
      y = fn();
      printf("%d i%%=%.10g\ty=%.10g (%d)\n", ++k, i, y, g);
    } while (fsign(y) == fsign(w) && fabs(y) < fabs(w));
  } while (y != 0.0 && w != 0.0 && y != w && g-- > 0);
  if (fsign(y) != fsign(w))
    i = (i*fabs(w) + v*fabs(y))/(fabs(y) + fabs(w));
}

int main(int argc, char **argv)
{
  n = strtod(argv[1], NULL);
  pv = strtod(argv[2], NULL);
  pmt = strtod(argv[3], NULL);
  fv = strtod(argv[4], NULL);
  if (argc > 5)
    b = strtod(argv[5], NULL) != 0.0;
  printf("\nTVM n=%g pv=%g pmt=%g fv=%g", n, pv, pmt, fv);
  if (b)
    printf(" BGN");
  printf("\n");
  solve();
  printf("i%%=%.18g%%\n", i);
}

This uses a bunch of global variables for TVM parameters to make it easier to adapt to registers in a calculator.

- Rob

"I count on old friends to remain rational"
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
PC-1211, PC-1250, etc. TVM - Dave Britten - 03-30-2021, 04:58 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 03-30-2021, 05:07 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 04-01-2021, 05:50 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 05-29-2024, 09:17 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 05-31-2024, 01:11 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-01-2024, 01:07 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-02-2024, 09:46 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-03-2024, 06:44 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-04-2024, 12:26 AM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-04-2024, 11:35 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-05-2024, 07:16 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-05-2024, 10:06 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-06-2024, 11:02 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-08-2024, 06:19 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-08-2024, 09:21 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-09-2024 12:06 AM
RE: PC-1211, PC-1250, etc. TVM - rprosperi - 06-09-2024, 01:22 PM
RE: PC-1211, PC-1250, etc. TVM - nickapos - 06-12-2024, 05:20 AM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-06-2024, 11:34 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-07-2024, 02:30 AM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-08-2024, 08:38 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-09-2024, 10:12 AM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-11-2024, 07:13 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-11-2024, 10:32 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-12-2024, 12:29 AM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-12-2024, 12:45 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-12-2024, 04:58 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-22-2024, 12:12 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-22-2024, 08:39 PM



User(s) browsing this thread: 1 Guest(s)