Post Reply 
Finance in Prime: odd period...
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
Post Reply 


Messages In This Thread
Finance in Prime: odd period... - salvomic - 05-21-2015, 10:40 AM
RE: Finance in Prime: odd period... - salvomic - 05-23-2015 08:39 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



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