Post Reply 
Finance in Prime: odd period...
05-21-2015, 10:40 AM
Post: #1
Finance in Prime: odd period...
hi all,
I need a hint to calc "odd period" for TVM in the Prime.
(Odd period: period between the date interest begins accruing and the beginning of the first payment period, calculated generally with simple interest, but also sometime with compound...)

An example (from the HP 12C Guide):
***
«A 36-month loan for $4,500 accrues interest at a 5% annual percentage rate (APR), with the payments made at the end of each month. If interest begins accruing on this loan on February 15, 2004 (so that the first period begins on March 1, 2004), calculate the monthly payment, with the odd days counted on the basis of a 30-day month and compound interest used for the odd period.»
***
DDAYS(2004.0215, 2004.0301) = 15 (16 in a base of 30 days, "financial year"), so 36 months + 16 days to add (at beginning of the first payment) is 36.53

If I put simply 36.53 as n, I%=5, PV=-4500, FV=0, I get PMT = -133.06 (end)
The result in the 12C is pmt = -135.17...
So, TVM as is, is not the solution...

Thank you

Salvo

∫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
05-21-2015, 08:39 PM
Post: #2
RE: Finance in Prime: odd period...
(05-21-2015 10:40 AM)salvomic Wrote:  hi all,
I need a hint to calc "odd period" for TVM in the Prime.
(Odd period: period between the date interest begins accruing and the beginning of the first payment period, calculated generally with simple interest, but also sometime with compound...)

An example (from the HP 12C Guide):
***
«A 36-month loan for $4,500 accrues interest at a 5% annual percentage rate (APR), with the payments made at the end of each month. If interest begins accruing on this loan on February 15, 2004 (so that the first period begins on March 1, 2004), calculate the monthly payment, with the odd days counted on the basis of a 30-day month and compound interest used for the odd period.»
***
DDAYS(2004.0215, 2004.0301) = 15 (16 in a base of 30 days, "financial year"), so 36 months + 16 days to add (at beginning of the first payment) is 36.53

If I put simply 36.53 as n, I%=5, PV=-4500, FV=0, I get PMT = -133.06 (end)
The result in the 12C is pmt = -135.17...
So, TVM as is, is not the solution...

Thank you

Salvo

Salvo,

I do not think you are making 36.53 month's payments, but are borrowing the monies for that duration. So at the start of the 36 month period you need to add the accrued interest for 16 days which is 4500x0.05/12*16/30 -> 10

So using N=36, PV=-4510 and I=5% you arrive at PMT= 135.17

Cheers, Terje
Find all posts by this user
Quote this message in a reply
05-21-2015, 08:47 PM
Post: #3
RE: Finance in Prime: odd period...
(05-21-2015 08:39 PM)Terje Vallestad Wrote:  Salvo,

I do not think you are making 36.53 month's payments, but are borrowing the monies for that duration. So at the start of the 36 month period you need to add the accrued interest for 16 days which is 4500x0.05/12*16/30 -> 10

So using N=36, PV=-4510 and I=5% you arrive at PMT= 135.17

Cheers, Terje

hi Terje, ok, but see the example above (and here, page 64).
36.53 is a mode typic of HP 12C to tell the calc that there are odd periods, not a real period...
You're right about the calc, and in fact I would like to have the calculation made ...by the Prime Smile

∫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
05-22-2015, 01:48 PM (This post was last modified: 05-22-2015 05:36 PM by salvomic.)
Post: #4
RE: Finance in Prime: odd period...
(05-21-2015 08:39 PM)Terje Vallestad Wrote:  ... at the start of the 36 month period you need to add the accrued interest for 16 days which is 4500x0.05/12*16/30 -> 10

So using N=36, PV=-4510 and I=5% you arrive at PMT= 135.17
Cheers, Terje

hi Terje,
a first version of a program to calculate odd period with the Prime, giving that period and all parameters to call Finance.CalcPMT() to get TVM *with* "odd period" added, like you say...
For now the program check for Financial/Actual (360/365) year, BEGIN/END, it calculates date with DDAYS (for actual year) or my formula (financial year: 30*(mm2-mm1)+dd2-dd1; it works well in my Simple Interest program, on HP Software Library of the Forum), "odd period" only with simple interest, not still with compound option...
In the evening I hope to add this option or more.
If you want, please, check it. Any advice is welcome Smile

Salvo

Code:

EXPORT odd_period()
BEGIN
local days1, days2, n, flg, r;
local dd1, dd2, mm1, mm2, yy1, yy2;
local pv, beg, inte, pmt, anno,gg;

input ({ {dd1,[0],{15,15,1}}, 
{mm1,{"1","2","3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}, {40,15,1}}, 
{yy1,[0],{70,15,1}},
{dd2,[0],{15,15,3}}, 
{mm2,{"1","2","3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}, {40,15,3}}, 
{yy2,[0],{70,15,3}},
{pv, [0], {15,15,4}}, 
{n, [0], {40,15,4}},{r,[0],{70,15,4}},
{beg,0, {20,2,5}}, {flg,0,{80,2, 5}}
}, 
"Calc difference days", {"d1", "m1", "y1", "d2", "m2", "y2", 
"PV", "N","r%", "End","Financial"}, 
{"Day 1", "Month 1", "Year 1", "Day 2", "Month 2", "Year 2", 
"Present value", "Yearly pmt n", "Yearly rate%", 
"Begin or End", "Financial year (360)"
}, 
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0}, 
{1, 1, 2015, 1, 1, 2015, 1000, 36, 5, 1, 1} );
dd1:=EVAL(dd1); mm1:=EVAL(mm1);
dd2:=EVAL(dd2); mm2:=EVAL(mm2);
yy1:=EVAL(yy1); yy2:=EVAL(yy2);
days1 := yy1+mm1/100+dd1/10000;
days2 := yy2+mm2/100+dd2/10000;
IF (flg==0) THEN // Actual year
gg:= DDAYS(days1, days2);
anno:=365;
ELSE // Finacial year
gg:= 30*(mm2-mm1)+dd2-dd1;
anno:=360;
END; //if
inte:=(pv*(r/100)*(gg))/anno;
pmt:=Finance.CalcPMT(n, r, (-(pv+inte)),0,12,12,beg);
RETURN pmt;
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
05-22-2015, 10:06 PM (This post was last modified: 05-22-2015 10:44 PM by salvomic.)
Post: #5
RE: Finance in Prime: odd period...
This version calculates also payment for compound interest of "odd period", but I've some doubt about the results (Terje, fhub (Franz), others, please help):
the result are *about* those of 12C, but with some rounding (±0.007 or more).
odd with year=360, simple interest is the same in both calc: es. 135.1687459 (about 135.17, as first, using the above example)
odd with year=365, simple int. 12C->135.1500141, Prime->135.14616
odd with year 360, compound interest 12C->135.1684, Prime->135.16181
odd with year=365, compound int. 12C->135.1497, Prime->135.13973

Particularly, I use this formula for compound interest to add to PV to calc PMT:
inte:= pv*((r/100+1)^(gg/anno)-1)
where gg are the odd days, anno is 360 or 365, r=5 (i.e.), gg in the example is 15 (actual year) or 16 (financial year)...
then pmt:=Finance.CalcPMT(n, r, (-(pv+inte)),0,12,12,beg)
to calc PMT.
(beg is 1 for "end period", 0 for "beginning period")

HP 12C use an internal routing in this case. It's activated when the period is non integer (es. 36.5333 or 36.5, in our cases), pressing STO+EEX (to give "C" symbol)...
I would like to understand the difference and if the results in Prime are exacts or where I'm wrong...

After that, I'll complete with the calculation for rate or other things...

Thank you,
Salvo

Code:

EXPORT odd_period()
BEGIN
local days1, days2, n, flg, r;
local dd1, dd2, mm1, mm2, yy1, yy2;
local pv, beg, inte;
local comp, pmt, anno,gg;

input ({ 
{dd1,[0],{15,15,1}}, 
{mm1,{"1","2","3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}, {40,15,1}}, 
{yy1,[0],{70,15,1}},
{dd2,[0],{15,15,3}}, 
{mm2,{"1","2","3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}, {40,15,3}}, 
{yy2,[0],{70,15,3}},
{pv, [0], {15,15,4}}, 
{n, [0], {40,15,4}},{r,[0],{70,15,4}},
{beg,0, {15,2,5}}, {comp,0,{50,2,5}}, {flg,0,{80,2, 5}}
}, 
"Calc difference days", {"d1", "m1", "y1", "d2", "m2", "y2", 
"PV", "N","r%", 
"End","Compound","Financial"}, 
{"Day 1", "Month 1", "Year 1", "Day 2", "Month 2", "Year 2", 
"Present value", "Yearly pmt n", "Yearly rate%", 
"Begin or End", "Compound interest", "Financial year (360)"
}, 
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0}, 
{1, 1, 2015, 1, 1, 2015, 1000, 36, 5, 1,0, 1} );
dd1:=EVAL(dd1); mm1:=EVAL(mm1);
dd2:=EVAL(dd2); mm2:=EVAL(mm2);
yy1:=EVAL(yy1); yy2:=EVAL(yy2);
days1 := yy1+mm1/100+dd1/10000;
days2 := yy2+mm2/100+dd2/10000;
IF (flg==0) THEN // Actual year
gg:= DDAYS(days1, days2);
anno:=365;
ELSE // Financial year
gg:= 30*(mm2-mm1)+dd2-dd1;
anno:=360;
END; //if
IF (comp==0) THEN // Simple interest
inte:=(pv*(r/100)*(gg))/anno;
ELSE // Compound interest
inte:= pv*((r/100+1)^(gg/anno)-1);
END;
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);
WAIT;
RETURN pmt;
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
05-23-2015, 08:39 AM (This post was last modified: 05-23-2015 09:01 AM by salvomic.)
Post: #6
RE: Finance in Prime: odd period...
a better, neat and reordered code, with Choose menu.
It calculates payment for difference of dates or giving number of days...
More modular.
I'm going to add solving for rate of interest (APR %).

It would be better, however, to have (in a Drawmenu, maybe) a softkey "Solve", like that in the Finance App: I need help, please Smile

Code:

smenu();
diffDays();
numDays();
simpComp();

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), 25,50);
TEXTOUT_P("Interest odd period " + EVAL(inte), 25, 70);
TEXTOUT_P("Monthly payment " + EVAL(pmt), 25, 90);
WAIT;
// 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);
WAIT;
// RETURN pmt;
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);
RETURN inte;
END;
END;

smenu()
BEGIN
local ch;
CHOOSE(ch, "Odd Period", "Payment: differnce Days", "Payment: number Days", "Quit");
CASE
IF ch==1 THEN diffDays(); END;
IF ch==2 THEN numDays(); END;
IF ch==3 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
05-23-2015, 10:21 AM
Post: #7
RE: Finance in Prime: odd period...
Hi Salvo,

You sure have been burning the midnight candles on the finance programs! Your latest work has compiled without error and seems to run ok. I wanted to look through your coding to try to understand your approaches, so I took the liberty of adjusting the layout, in order for me to read through it better.

I was wondering if you would find it useful to control the number of digits in the user interface, (HDigits variable)?

When the result screens have been presented to the user, a helpful hint to let users know what to do next, might be useful. For example, "Press the Esc Key to continue..." or something.

It looks like you've figured out how to use INPUT() to your advantage. That function is not very well described in the help texts, as you might agree. It takes a little trial and error to get it working just the way a person might like!

Once a program accomplishes the basic goals, one can always tweak it for an enhanced user presentation / interface. Minimally, you've included textout_p() coding, which could also include color, and text size to help focus the user experience, for visual enhancement. The use of rectangular colored boxes for titles, and other interactions can aid visual interest. You might enjoy a little time off from the grind of getting the basic functions working, and have fun with the graphical user interface!

I hope these suggestions are useful.

-Dale-

Here's your program with formatting that makes it a bit easier for my eyes:

Code:

smenu();
diffDays();
numDays();
simpComp();

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), 25,50);
  TEXTOUT_P("Interest odd period " + EVAL(inte), 25, 70);
  TEXTOUT_P("Monthly payment " + EVAL(pmt), 25, 90);
  WAIT;
  // 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);
  WAIT;
  // RETURN pmt;
  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);
  RETURN inte;
  END;
END;

smenu()
BEGIN
  local ch;
  CHOOSE(ch, "Odd Period", "Payment: difference Days", "Payment: number Days", "Quit");
  CASE
    IF ch==1 THEN diffDays(); END;
    IF ch==2 THEN numDays(); END;
    IF ch==3 THEN RETURN; END;
    DEFAULT
  END; // case
END;
Find all posts by this user
Quote this message in a reply
05-23-2015, 11:33 AM
Post: #8
RE: Finance in Prime: odd period...
(05-23-2015 10:21 AM)DrD Wrote:  Hi Salvo,

You sure have been burning the midnight candles on the finance programs! Your latest work has compiled without error and seems to run ok. I wanted to look through your coding to try to understand your approaches, so I took the liberty of adjusting the layout, in order for me to read through it better.

I was wondering if you would find it useful to control the number of digits in the user interface, (HDigits variable)?

When the result screens have been presented to the user, a helpful hint to let users know what to do next, might be useful. For example, "Press the Esc Key to continue..." or something.

It looks like you've figured out how to use INPUT() to your advantage. That function is not very well described in the help texts, as you might agree. It takes a little trial and error to get it working just the way a person might like!

Once a program accomplishes the basic goals, one can always tweak it for an enhanced user presentation / interface. Minimally, you've included textout_p() coding, which could also include color, and text size to help focus the user experience, for visual enhancement. The use of rectangular colored boxes for titles, and other interactions can aid visual interest. You might enjoy a little time off from the grind of getting the basic functions working, and have fun with the graphical user interface!

I hope these suggestions are useful.

-Dale-

Here's your program with formatting that makes it a bit easier for my eyes:...

I Dale, thank you.
You are right about the imperfect formatting and ...about midnight candles :-)
The principal reason of ugly formatting is because yesterday I worked mostly directly in the Prime, so the aim was to go new line (this is better in the calc)...
Now I'm inserting your better formatting and including it also in the new two functions I'm developing (to calc APR).
I'm going to improve TEXTOUT_P and helping, sure!

I've a question, however: what's the difference between TEXTOUT_P and TEXTOUT? the help seems to be ...the same Smile

Then I'll look at also for more graphic.

Salvo

∫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
05-23-2015, 01:00 PM
Post: #9
RE: Finance in Prime: odd period...
(05-23-2015 11:33 AM)salvomic Wrote:  I've a question, however: what's the difference between TEXTOUT_P and TEXTOUT? the help seems to be ...the same Smile

According to the USER GUIDE:

"Twenty-six functions can be used to modify graphics variables. Thirteen of them work with Cartesian
coordinates using the Cartesian plane defined in the current app by the variables Xmin, Xmax, Ymin, and
Ymax.
The remaining thirteen work with pixel coordinates where the pixel 0,0 is the top left pixel of the GROB, and
320, 240 is the bottom right. Functions in this second set have a _P suffix to the function name.
"

Since most of my graphics work uses direct pixel values, not graphics variables, I mostly use functions with the _P suffix.

-Dale-
Find all posts by this user
Quote this message in a reply
05-23-2015, 01:11 PM
Post: #10
RE: Finance in Prime: odd period...
(05-23-2015 01:00 PM)DrD Wrote:  According to the USER GUIDE:

...
Since most of my graphics work uses direct pixel values, not graphics variables, I mostly use functions with the _P suffix.

-Dale-

thank you, the Help in the Prime is not so clear.
For now I'm using mostly the "_P" set also.

Salvo

∫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
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 




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