Post Reply 
Simple Interest
05-17-2015, 03:10 PM (This post was last modified: 05-17-2015 03:12 PM by salvomic.)
Post: #1
Simple Interest
hi all,
to try DDAYS, I'm making a program to calc simple interest.
This program works but has two problems related to DDAYS:
first: I must calc the interest both for actual period and for financial, but DDAYS (as it is) calculates only for actual period (365 days and month of various duration), not for financial year (360 days and months all of 30 days)...
Any help appreciated.

Second problem is related to input: I used dropdown menus for days and months (not for year), but if months menu has 12 items, also if days menu has 31, it shows always only 12 also: there is a limit, using more than one dropdown menu or is the problem different?

A dirty solution would be use a textbook instead, but I'm curious about that problem with dropdown...

Please, help Smile

Salvo

Code:

fin();
act();
calcd();
smenu();

EXPORT simple_interest()
BEGIN
smenu();
END;

fin(n)
BEGIN
local mesg, r, pv, I;
input ({n,r, pv}, "Interest financial year", {"n","i", "PV"}, 
{"Period (day)", "rate", "present value"},{n,0, 0} );
I:= (n/360)*pv*r/100;
mesg:= Eval(pv) +" for " + EVAL(n) + " days at " + EVAL(r) + "%" +
"
Interest (360 days) = " + EVAL(I) +
"
Total (PV + I) = " + EVAL(I+pv) + "";
PRINT;
PRINT (mesg);
WAIT (0);
smenu();
RETURN {I, I+pv};
END;

act(n)
BEGIN
local mesg, r, pv, I;
input ({n,r, pv}, "Interest financial year", {"n","i", "PV"}, 
{"Period (day)", "rate", "present value"},{n,0, 0} );
I:= (n/365)*pv*r/100;
mesg:= Eval(pv) +" for " + EVAL(n) + " days at " + EVAL(r) + "%" +
"
Interest (365 days) = " + EVAL(I) +
"
Total (PV + I) = " + EVAL(I+pv) + "";
PRINT;
PRINT (mesg);
WAIT (0);
smenu();
RETURN {I, I+pv};
END;

calcd()
BEGIN
local mesg, days1, days2, n, dd1;
local dd2, mm1, mm2, yy1, yy2;

input ({ {dd1,{"1","2","3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", 
"16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"},
{15,15,1}}, 
{mm1,{"1","2","3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}, {40,15,1}}, 
{yy1,[0],{70,20,1}},
{dd2,{"1","2","3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", 
"16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"},
{15,15,3}}, 
{mm2,{"1","2","3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}, {40,15,3}}, 
{yy2,[0],{70,20,3}} 
}, 
"Calc days (actual)", {"d1", "m1", "y1", "d2", "m2", "y2"}, 
{"Day 1", "Month 1", "Year 1", "Day 2", "Month 2", "Year 2"}, 
{0, 0, 0, 0, 0, 0 }, {0, 0, 2015, 0, 0, 2015} );
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;
n:= DDAYS(days1, days2);
mesg:="Days n = " + EVAL(n) +

from " + EVAL(dd1) + " - " + EVAL(mm1) + " - " + EVAL(yy1) +
" to " + EVAL(dd2) + " - " + EVAL(mm2) + " - " + EVAL(yy2) + 
"";
PRINT;
PRINT (mesg);
WAIT(0);
act(n);
END;

smenu()
BEGIN
local ch;
CHOOSE(ch,"Mode","Finacial year","Actual year", "Calc Date (actual)", "Quit");
CASE
IF ch==1 THEN fin(0); END;
IF ch==2 THEN act(0); END;
IF ch==3 THEN calcd(); END;
if ch==4 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-17-2015, 04:40 PM (This post was last modified: 05-17-2015 04:52 PM by salvomic.)
Post: #2
RE: Simple Interest
...a first formula per financial year could be:

30*(mm2-mm1)+dd2-dd1

is from 13 May 2015 to 21 November 2015 there are 192 actual days (DDAYS(2015.0513, 2015.1121)), but only 188 "financial" days: 30*(11-5)+21-13

This formula *should* works independently of leap year...

to be continued...

∫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-17-2015, 07:48 PM (This post was last modified: 05-17-2015 09:51 PM by salvomic.)
Post: #3
RE: Simple Interest
this version works better:
changed type of input for days: no more checkbox, but textbox; added a function to calculate financial difference of dates (360 days/year): 30*(mm2-mm1)+dd2-dd1
It set Fixed 2 Digits format (almost a standard in Finance).

I need still a better control of error, as i.e. DDAYS gives error with non existent days (try DDAYS(2015.0201, 2015.0229) for example: 29 Feb doesn't exist, and the function gives error, so the program exit with "Error: Invalid input"...

Another thing a bit strange: if the order of input is:
dd1 (textbox), mm1 (checkbox), yy1 (textbox) ...
why the cursor goes from dd1 to yy1 and then to mm1 (in the same line)?

Code:

fin();
act();
calcd();
smenu();

EXPORT simple_interest()
BEGIN
// Set to Fixed 2 Mode
HFormat:=1;
HDigits:=2;
smenu();
END;

fin(n)
BEGIN
local mesg, r, pv, I;
input ({n,r, pv}, "Interest financial year", {"n","i", "PV"}, 
{"Period (day)", "rate%", "present value"},{n,0, 0} );
I:= (n/360)*pv*r/100;
mesg:= Eval(pv) +" for " + EVAL(n) + " days at " + EVAL(r) + "%" +
"
Interest (360 days) = " + EVAL(I) +
"
Total (PV + I) = " + EVAL(I+pv) + "";
PRINT;
PRINT (mesg);
WAIT (0);
smenu();
RETURN {I, I+pv, 360};
END;

act(n)
BEGIN
local mesg, r, pv, I;
input ({n,r, pv}, "Interest actual year", {"n","i", "PV"}, 
{"Period (day)", "rate%", "present value"},{n,0, 0} );
I:= (n/365)*pv*r/100;
mesg:= Eval(pv) +" for " + EVAL(n) + " days at " + EVAL(r) + "%" +
"
Interest (365 days) = " + EVAL(I) +
"
Total (PV + I) = " + EVAL(I+pv) + "";
PRINT;
PRINT (mesg);
WAIT (0);
smenu();
RETURN {I, I+pv, 365};
END;

calcd()
BEGIN
local mesg, days1, days2, n, flg;
local dd1, dd2, mm1, mm2, yy1, yy2;
HFormat:=0;
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,20,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,20,3}},{flg,2,{85,2, 4}}
}, 
"Calc difference days", {"d1", "m1", "y1", "d2", "m2", "y2", "Financial"}, 
{"Day 1", "Month 1", "Year 1", "Day 2", "Month 2", "Year 2", "Financial year (360)"}, 
{1, 0, 0, 1, 0, 0, 0 }, {1, 0, 2015, 1, 0, 2015, 0} );

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
n:= DDAYS(days1, days2);
ELSE
n:= 30*(mm2-mm1)+dd2-dd1;
END; // if
mesg:="Days n = " + EVAL(n) +

from " + STRING(dd1) + "-" + STRING(mm1) + "-" + STRING(yy1) +
" to " + STRING(dd2) + "-" + STRING(mm2) + "-" + STRING(yy2) + 
"";
PRINT;
PRINT (mesg);
WAIT(0);
// Set to Fixed 2 Mode
HFormat:=1;
HDigits:=2;
IF (flg==1) THEN fin(n); ELSE act(n); END;

END;

smenu()
BEGIN
local ch;
CHOOSE(ch,"Simple Interest","n actual year","n finacial year", "Calc Date difference", "Quit");
CASE
IF ch==1 THEN act(0); END;
IF ch==2 THEN fin(0); END;
IF ch==3 THEN calcd(); END;
if ch==4 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-18-2015, 01:59 PM (This post was last modified: 05-19-2015 03:33 PM by salvomic.)
Post: #4
RE: Simple Interest
A relative complete version (that has also the inverse formulas for n, r, PV) in the HP Prime Software Library of the Forum.

∫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: 2 Guest(s)