Post Reply 
Finance in Prime: odd period...
05-23-2015, 02:41 PM (This post was last modified: 05-23-2015 03:47 PM by salvomic.)
Post: #11
RE: Finance in Prime: odd period...
Almost complete (for now) version: I've added calculation of APR rate (in Italy TAEG).
But, please, control the formulas, as I get still results that differs from those on HP 12C about 0.01-0.03 (with these new formulas), few for % but not indifferent...
I'm following this example: «A 42-month loan of $3,950 for a used car began accruing interest on July 19, 2004, so that the first period began on August 1, 2004. Payments of $120 are made at the end of each month. Calculate the annual percentage rate (APR), using the actual number of odd days and simple interest for the odd period.»

Having not an amount of interest to reverse the formula and get the rate, I presumed to get the interest (then the rate) in this way: I calculate the compound rate with Finance.CalcIPYR() for the integer periods (42), then I convert it (effective?) to nominal rate, at the end I get interest, add it to PV and recalculate with Finance.CalcIPYR() the presumed rate.
This one is "about" the calculations made by 12C, with a little difference (i.e. for the example above -year 365, simple interest- 12C-> 13.947814, Prime->13.96389).
If you have another (and better method), please, advice...

A last thing: for now the rate (simple and compound) are compounded always 12 times per year. Sure, it would be better to give more control in that, but...
User can choose from END and BEGINNING mode of payment.
Now they are been exported three variables: OP_pmt and OP_rate (payment, APR rate -with monthly rate- and interest of odd period).

Code:

export OP_pmt:=0;
export OP_rate:={0,0};
export OP_interest:=0;

smenu();
diffDays();
numDays();
simpComp();
diffRate();
numRate();

EXPORT odd_period()
BEGIN
smenu();
END;

diffDays()
 BEGIN
   local day1, day2, n, fin, r;
   local dd1, dd2, mm1, mm2, yy1, yy2;
   local pv, beg, inte;
   local comp, pmt, anno,gg;

   input ({ {pv, [0], {15,15,1}}, 
            {n, [0], {40,15,1}},{r,[0],{70,15,1}},
            {beg,0, {15,2,2}}, {comp,0,{50,2,2}},
            {fin,0,{80,2, 2}},
            {dd1,[0],{15,15,4}}, 
            {mm1,{"1","2","3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}, {40,15,4}}, 
            {yy1,[0],{70,15,4}},
            {dd2,[0],{15,15,5}}, 
            {mm2,{"1","2","3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}, {40,15,5}}, 
            {yy2,[0],{70,15,5}} }, 
            "Calc payment with Δdays", 
            {"PV", "N","r%","End","Compound","Financial", "d1", "m1", "y1", "d2", "m2", "y2"}, 
            {"Present value (loan)", "Yearly pmt number", "APR Yearly rate%", "Begin or End", "Compound interest",
            "Financial year (360)", "Day 1", "Month 1", "Year 1", "Day 2", "Month 2", "Year 2"}, 
            {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0}, 
            {1000, 36, 5, 1, 0, 1, 1, 1, 2015, 1, 1, 2015});

   dd1:=EVAL(dd1); mm1:=EVAL(mm1);
   dd2:=EVAL(dd2); mm2:=EVAL(mm2);
   yy1:=EVAL(yy1); yy2:=EVAL(yy2);
   day1 := yy1+mm1/100+dd1/10000;
   day2 := yy2+mm2/100+dd2/10000;

   IF (fin==0) THEN // Actual year
     gg:= DDAYS(day1, day2);
     anno:=365;
   ELSE // Financial year
     gg:= 30*(mm2-mm1)+dd2-dd1;
     anno:=360;
   END; //if

   inte:= simpComp(comp, pv, r, gg, anno);
   pmt:=Finance.CalcPMT(n, r, (-(pv+inte)),0,12,12,beg);
   RECT_P();
   TEXTOUT_P("Odd period " + EVAL(gg) + "days", 25,50);
   TEXTOUT_P("Interest odd period " + EVAL(inte), 25, 70);
   TEXTOUT_P("Monthly payment " + EVAL(pmt), 25, 90);
   TEXTOUT_P("Press ESC key to continue", 25, 110, 3, RGB(0,0,255));
   WAIT;
sto(pmt, OP_pmt);
sto(inte, OP_interest);
   // RETURN pmt;
   smenu();
 END;


numDays()
 BEGIN
   local day1, day2, n, fin, r;
   local dd1, dd2, mm1, mm2, yy1, yy2;
   local pv, beg, inte;
   local comp, pmt, anno,gg;

   input ({ {pv, [0], {15,15,1}}, 
            {n, [0], {40,15,1}},{r,[0],{70,15,1}},
            {beg,0, {15,2,2}}, 
            {comp,0, {50,2,2}}, 
            {fin,0,{80,2, 2}},
            {gg, [0], {70,15,3}} }, 
            "Calc payment with num days", 
            {"PV", "N","r%","End","Compound","Financial","num Days"}, 
            {"Present value (loan)", "Yearly pmt number", "APR Yearly rate%", 
             "Begin or End", "Compound interest", "Financial year (360)", "Number of Days" }, 
            {0, 0, 0, 0, 0, 0, 0}, 
            {1000, 36, 5, 1, 0, 1, 20} );

         IF (fin==0) THEN // Actual year
           anno:=365;
         ELSE // Financial year
           anno:=360;
         END; //if

   inte:= simpComp(comp, pv, r, gg, anno);
   pmt:=Finance.CalcPMT(n, r, (-(pv+inte)),0,12,12,beg);
   RECT_P();
   TEXTOUT_P("Odd period " + EVAL(gg), 25,50);
   TEXTOUT_P("Interest odd period " + EVAL(inte), 25, 70);
   TEXTOUT_P("Monthly payment " + EVAL(pmt), 25, 90);
   TEXTOUT_P("Press ESC key to continue", 25, 110, 3, RGB(0,0,255));
   WAIT;
sto(pmt, OP_pmt);
sto(inte, OP_interest);
   smenu();
 END;


diffRate()
BEGIN
  local day1, day2, n, fin, r;
  local dd1, dd2, mm1, mm2, yy1, yy2;
  local pv, beg, inte, reff;
  local comp, pmt, anno,gg;

  input ({ {pv, [0], {15,15,1}}, 
    {pmt, [0], {40,15,1}},{n,[0],{70,15,1}},
      {beg,0, {15,2,2}}, {comp,0,{50,2,2}}, {fin,0,{80,2, 2}},
      {dd1,[0],{15,15,4}}, 
      {mm1,{"1","2","3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}, {40,15,4}}, 
      {yy1,[0],{70,15,4}},
      {dd2,[0],{15,15,5}}, 
      {mm2,{"1","2","3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}, {40,15,5}}, 
      {yy2,[0],{70,15,5}}  }, 
      "Calc APR rate with Δdays", 
      {"PV", "PMT","N", "End","Compound","Financial", "d1", "m1", "y1", "d2", "m2", "y2" }, 
      {"Present value (loan)", "Monthly payment", "Yearly payments number", 
      "Begin or End", "Compound interest", "Financial year (360)",
      "Day 1", "Month 1", "Year 1", "Day 2", "Month 2", "Year 2" }, 
      {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0}, 
      {1000, 100, 42, 1, 0, 1, 1, 1, 2015, 1, 1, 2015} );
   dd1:=EVAL(dd1); mm1:=EVAL(mm1);
   dd2:=EVAL(dd2); mm2:=EVAL(mm2);
   yy1:=EVAL(yy1); yy2:=EVAL(yy2);
   day1 := yy1+mm1/100+dd1/10000;
   day2 := yy2+mm2/100+dd2/10000;
   IF (fin==0) THEN // Actual year
  gg:= DDAYS(day1, day2);
  anno:=365;
   ELSE // Financial year
  gg:= 30*(mm2-mm1)+dd2-dd1;
  anno:=360;
   END; //if
   reff:=Finance.CalcIPYR(n,pv,-pmt,0,12,12,1); // effective rate
   r:= 100*((reff/100 + 1)^(1/12)-1)*12; // nominal rate (12 compounding period yearly)
   inte:= simpComp(comp, pv, r, gg, anno);
   r:=Finance.CalcIPYR(n, (-(pv+inte)),pmt, 0,12,12,beg);
   RECT_P();
   TEXTOUT_P("Odd period " + EVAL(gg), 25,50);
   TEXTOUT_P("Interest odd period " + EVAL(inte), 25, 70);
   TEXTOUT_P("Monthly rate " + EVAL(r/12), 25, 90);
   TEXTOUT_P("APR yearly rate (TAEG) " + EVAL(r), 25, 110);
   TEXTOUT_P("Press ESC key to continue", 25, 130, 3, RGB(0,0,255));
   WAIT;
sto({r/12, r}, OP_rate);
sto(inte, OP_interest);
   smenu();
END;

numRate()
BEGIN
  local day1, day2, n, fin, r;
  local dd1, dd2, mm1, mm2, yy1, yy2;
  local pv, beg, inte, reff;
  local comp, pmt, anno,gg;

  input ({ {pv, [0], {15,15,1}}, 
      {pmt, [0], {40,15,1}},
    {n,[0],{70,15,1}},
      {beg,0, {15,2,2}}, 
    {comp,0,{50,2,2}}, 
    {fin,0,{80,2, 2}}, 
    {gg, [0], {70,15,3}} }, 
      "Calc APR rate with num days", 
      {"PV", "PMT","N", "End","Compound","Financial", "Num days" }, 
      {"Present value (loan)", "Monthly payment", "Yearly payments number", 
      "Begin or End", "Compound interest", "Financial year (360)", "Number of Days"}, 
      {0, 0, 0, 0, 0, 0, 0}, {1000, 100, 42, 1, 0, 1, 15} );

   IF (fin==0) THEN // Actual year
      anno:=365;
   ELSE // Financial year
      anno:=360;
   END; //if
   reff:= Finance.CalcIPYR(n,pv,-pmt,0,12,12,1); // effective rate
   r:= 100*((reff/100 + 1)^(1/12)-1)*12; // nominal rate (12 compounding period yearly)
   inte:= simpComp(comp, pv, r, gg, anno);
   r:=Finance.CalcIPYR(n, (-(pv+inte)),pmt, 0,12,12,beg);
   RECT_P();
   TEXTOUT_P("Odd period " + EVAL(gg), 25,50);
   TEXTOUT_P("Interest odd period " + EVAL(inte), 25, 70);
   TEXTOUT_P("Monthly rate " + EVAL(r/12), 25, 90);
   TEXTOUT_P("APR yearly rate (TAEG) " + EVAL(r), 25, 110);
   TEXTOUT_P("Press ESC key to continue", 25, 130, 3, RGB(0,0,255));
   WAIT;
sto({r/12, r}, OP_rate);
sto(inte, OP_interest);
   smenu();
END;

simpComp(comp, pv, r, gg, anno)
BEGIN
   local inte;
   IF (comp==0) THEN // Simple interest
  inte:=(pv*(r/100)*(gg))/anno;
   ELSE // Compound interest
  inte:= pv*((r/100+1)^(gg/anno)-1);
   END;
RETURN inte;
END;

smenu()
BEGIN
local ch;
  CHOOSE(ch, "TVM with Odd Period", "Payment: difference days", "Payment: number days", "APR rate: diff days", 
  "APR rate: num days", "Quit");
  CASE
   IF ch==1 THEN diffDays(); END;
   IF ch==2 THEN numDays(); END;
   IF ch==3 THEN diffRate(); END;
   IF ch==4 THEN numRate(); END;
   IF ch==5 THEN RETURN; END;
  DEFAULT
  END; // case
END;

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Finance in Prime: odd period... - salvomic - 05-21-2015, 10:40 AM
RE: Finance in Prime: odd period... - DrD - 05-23-2015, 10:21 AM
RE: Finance in Prime: odd period... - DrD - 05-23-2015, 01:00 PM
RE: Finance in Prime: odd period... - salvomic - 05-23-2015 02:41 PM



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