TVM with odd period - salvomic - 05-23-2015 04:04 PM
A program to calculate TVM for a loan with "odd period" after the first payment.
From the HP 12C Guide: «The period from the date interest begins accruing to the date of the first payment, being not equal to the regular payment periods is sometimes referred to as an “odd first period»
The program calculates payment or rate (APR, Europe: TAEG) and interest for the days in odd period, inputting the number of days or calculating a difference between two dates.
Enjoy with it!
Salvo Micciché
Code:
export OP_pmt:=0;
export OP_rate:={0,0};
export OP_interest:=0;
smenu();
diffDays();
numDays();
simpComp();
diffRate();
numRate();
EXPORT odd_period()
// SAlvo Micciché 2015
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;
RE: TVM with odd period - salvomic - 04-23-2016 03:35 PM
New version after firmware 10077.
This version doesn't run with firmwares < 10077.
Code:
// Odd Period v 2.0 by Salvo Micciché
// this version runs only with firmware > 10077
export OP_pmt:=0;
export OP_rate:={0,0};
export OP_interest:=0;
smenu();
diffDays();
numDays();
simpComp();
diffRate();
numRate();
EXPORT odd_period()
// SAlvo Micciché 2015
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.TvmPMT(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.TvmPMT(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.TvmIPYR(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.TvmIPYR(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.TvmIPYR(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.TvmIPYR(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;
|