a program to calculate Simple Interest (with inverse formulas) both for actual year and financial year (365 or 360 days).
The program can calculates even a difference within two dates and use it (as n) to calculate interest...
Code:
fin();
act();
calcd();
prd();
rate();
prval();
simp_comp();
comp_simp();
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:= "A Present Value of " + EVAL(pv) +" for " + EVAL(n) + " days at rate " + EVAL(r) + "%" +
"
is an Interest (360 days) of " + EVAL(I) +
"
the Total (PV + I) is " + 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:= "A Present Value of " + EVAL(pv) +" for " + EVAL(n) + " days at rate " + EVAL(r) + "%" +
"
is an Interest (365 days) of " + EVAL(I) +
"
the Total (PV + I) is " + EVAL(I+pv) + "";
PRINT;
PRINT (mesg);
WAIT (0);
smenu();
RETURN {I, I+pv, 365};
END;
prd()
BEGIN
local mesg, r, pv, I, n1, n2;
input ({r,I, pv}, "Interest: calc n", {"r","Int", "PV"},
{"rate%", "Interest", "Present value"},{0,0, 0} );
n1:= I*365/(pv*r/100);
n2:= I*360/(pv*r/100);
mesg:= "With Present value of " + EVAL(pv) + " at rate " + EVAL(r) + "%, interest of " + EVAL(I)
+
"
is in a period of
"
+ EVAL(n1) + " days (actual year)
or
"
+ EVAL(n2) + " days (finacial year)";
PRINT;
PRINT (mesg);
WAIT (0);
smenu();
RETURN {n1, 365, n2, 360};
END;
rate()
BEGIN
local mesg, n, pv, I, r1, r2;
input ({n,I, pv}, "Interest: calc rate", {"n","Int", "PV"},
{"Period (n)", "Interest", "Present value"},{0,0, 0} );
r1:= I*365/(pv*n);
r2:= I*360/(pv*n);
mesg:= "With Present value of " + EVAL(pv) + " and an interest of " + EVAL(I) +
" in a period of " + EVAL(n) + " days
The rate% is " + EVAL(r1*100) + "% (actual year)
and " +
EVAL(r2*100) + "% (finacial year)" ;
PRINT;
PRINT (mesg);
WAIT (0);
smenu();
RETURN {r1*100, 365, r2*100, 360};
END;
prval()
BEGIN
local mesg, r, n, I, pv1, pv2;
input ({r,n, I}, "Interest: calc PV", {"r","n", "I"},
{"rate%", "Period (n)", "Interest"},{0,0, 0} );
pv1:= I*365/(n*r/100);
pv2:= I*360/(n*r/100);
mesg:= "With Interest of " + EVAL(I) + " at rate " + EVAL(r) + "%
in period (n) of " + EVAL(n)
+ " days
Present Value is " + EVAL(pv1) + " (actual year) or
" +
EVAL(pv2) + " (finacial year)";
PRINT;
PRINT (mesg);
WAIT (0);
smenu();
RETURN {pv1, 365, pv2, 360};
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;
simp_comp()
BEGIN
local si, ci, t;
INPUT ({ si, t },"Simple Interest to Compound", {"i%", "t"}, {"Simple interest", "Period"},{0,0}, {0.05, 2});
ci:= ((1+si*t)^(1/t))-1;
END;
comp_simp()
BEGIN
local si, ci, t;
INPUT ({ ci, t },"Compound Interest to Simple", {"i%", "t"}, {"Compound interest", "Period"},{0,0}, {0.05, 2});
si:= ((1+ci)^t-1)/t;
END;
smenu()
BEGIN
local ch;
CHOOSE(ch,"Simple Interest","Int actual year","Int finacial year",
"Int Date difference", "Period (n)", "Rate", "Present Value", "Simple Interest → Compound",
"Compound Interest → Simple", "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 prd(); END;
IF ch==5 THEN rate(); END;
IF ch==6 THEN prval(); END;
IF ch==7 THEN simp_comp(); END;
IF ch==8 THEN comp_simp(); END;
if ch==9 THEN return; END;
DEFAULT
END; //case
END;