Post Reply 
Leasing: advance payments
05-20-2015, 09:18 PM (This post was last modified: 05-21-2015 10:22 AM by salvomic.)
Post: #1
Leasing: advance payments
hi all,
this program calculates leasing with advanced payments (i.e duration: 60 months, 3 advanced payments (or at the end)...), giving monthly payment (less the advanced...) and calculating the monthly and annual yield (rate).
The program calculate also the payment of a Leasing with residual value (for payment and yield, with the IRR method).
Theese functions are similar to those in the HP 12C calculator.

Menu: Leasing_advpmt() - Leasing_yield() - Leasing_residual() - Leasing_res_yield()

Enjoy!

Salvo Micciché

EDIT: new version with a choose menu

Code:

Menu();

Leasing()
BEGIN
// by Salvo Micciché 2015
Menu();
END;

EXPORT Leasing_advpmt()
// solve for monthly payment
BEGIN
LOCAL r, n, fpmt, val;
INPUT ({r, n, fpmt, val},"Leasing: advance payments", {"yield%", "n lease", "n pmt advance", "value"}, 
{"Yield (rate)%", "Duration of lease", "Num of advance payments", "Value of Leasing"}, {0,0, 0, 0},{0,12, 3,0});
LOCAL npmt, pv;
npmt:= n - fpmt;
pv:= Finance.CalcPV(npmt, r, -1, 0, 12, 12, 1);
PRINT;
PRINT(
"Leasing with advanced payments

Value of lease: " + EVAL(val) + "
Duration of lease: " + EVAL(n) + "
Advanced payments n.: " + EVAL(fpmt) + "
Periodic payments n.: " + EVAL(npmt) + "
Yield (rate): " + EVAL(r) + "% 
Monthly payment: " + EVAL(val/(pv+fpmt))
);
WAIT (0);
Menu();
RETURN val/(pv+fpmt);
END;

EXPORT Leasing_yield()
// solve for yield
BEGIN
LOCAL n, fpmt, val, pmt, yield, npmt, pv;
INPUT ({n, fpmt, val, pmt},"Leasing: calc yield", {"n lease", "n pmt advance", "value", "payment"}, 
{"Duration of lease", "Num of advance payments", "Value of Leasing", "Monthly payment"}, {0,0, 0, 0},{12,3, 0, 0});
npmt:= n - fpmt;
pv:= fpmt*pmt-val;
yield:= Finance.CalcIPYR(npmt, pv, pmt, 0, 12, 12, 1);
PRINT;
PRINT ("Leasing: solving for Yield

Value of lease (loan): " + EVAL(val) + "
Duration of lease: " + EVAL(n) + "
Advanced payments n.: " + EVAL(fpmt) + "
Periodic payments n.: " + EVAL(npmt) + "
Monthly Payment: " + EVAL(pmt) + "
Monthly yield: " + EVAL(yield/12) + "% 
Yearly yield: " + EVAL(yield) + "%"
);
WAIT (0);
Menu();
RETURN yield;
END;

EXPORT Leasing_residual()
// Leasing with residual value, solve for monthly payment
BEGIN
LOCAL n, r, val, resval, fpmt, att, pv;
LOCAL npmt, pv2;
INPUT ({n, fpmt, r, val, resval},"Leasing with residual", {"n lease", "n adv pmt", "yield%", "value", "res value"}, 
{"Duration of lease", "Num advanced payments", "Yield (rate)%", "Value of Leasing (loan)", "Residual value"}, 
{0,0, 0, 0, 0},{12, 3, 0, 0, 0});
pv:= Finance.CalcPV(n, r,0, resval, 12, 12, 1);
att:= pv + val;
npmt:= n - fpmt;
pv2:= Finance.CalcPV(npmt, r, -1, 0, 12, 12, 1);
pv2:= pv2 + fpmt;
PRINT;
PRINT ("Leasing with residual 

Value of lease (loan): " + EVAL(val) + "
Residual value: " + EVAL(resval) + "
Duration of lease: " + EVAL(n) + "
Advanced payments n.: " + EVAL(fpmt) + "
Periodic payments n.: " + EVAL(npmt) + "
Yield (rate): " + EVAL(r) + "% 
Monthly payment: " + EVAL(att/pv2)
);
WAIT (0);
Menu();
RETURN att/pv2;
END;

EXPORT Leasing_res_yield()
// Leasing with residual value, solve for yield (rate)
BEGIN
LOCAL n, fpmt, val, pmt, resval, j, irr;
LOCAL flows:={}, yield, npmt, netamt;
INPUT ({n, fpmt, val, resval, pmt},"Leasing: calc yield", {"n lease", "n pmt advance", "value", "res val", "payment"}, 
{"Duration of lease", "Num of advance payments", "Value of Leasing", "REsidual value", "Monthly payment"},
{0,0, 0, 0, 0},{36,2, 0, 0, 0});
npmt:= n - fpmt;
netamt:= -val+pmt*fpmt; // net amount (-value + payment*advanced num pmt)
flows:= append(flows, netamt); // create list, append net amount
FOR j FROM 1 TO npmt DO
flows:= append (flows, pmt); // append payment, (num pmt - advanced pmt) times
END; // for
FOR j  FROM 1 TO (fpmt-1) DO
flows:= append (flows, 0);  // append 0, (mum advanced pmt minus 1)
END; // for
flows:= append(flows, resval); // append residual value
L1:= flows;
irr:= Solve.SOLVE(ΣLIST(MAKELIST((L1(I)/X^(I-1)),I,1,SIZE(L1))),X)-1;
// Solve.SOLVE() could not always work, but give only a secure value, solve() works better, butr gives more values
PRINT;
PRINT ("Leasing with advanced payments and residual value: yield 
Solved for IRR

Value of lease (loan): " + EVAL(val) + "
Residual value: " + EVAL(resval) + "
Duration of lease: " + EVAL(n) + "
Advanced payments n.: " + EVAL(fpmt) + "
Periodic payments n.: " + EVAL(npmt) + "
Monthly Payment: " + EVAL(pmt) + "
Net amount of cash advanced: " + EVAL(netamt) + "
Monthly yield: " + EVAL(irr*100) + "% 
Yearly yield: " + EVAL(12*irr*100) + "%"

);
WAIT (0);
Menu();
RETURN 12*irr; // yearly yield (IRR) in decimal
END;

EXPORT Menu()
BEGIN
LOCAL ch;
CHOOSE(ch, "Leasing", "Leasing with advanced payments", "Leasing: solving for Yield", 
"Leasing with residual", "Leasing residual: yield", "Quit");

CASE
IF ch==1 THEN Leasing_advpmt(); END;
IF ch==2 THEN Leasing_yield(); END;
IF ch==3 THEN Leasing_residual(); END;
IF ch==4 THEN Leasing_res_yield(); END;
IF ch==5 THEN RETURN; END;
DEFAULT 
KILL;
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
Leasing: advance payments - salvomic - 05-20-2015 09:18 PM
RE: Leasing: advance payments - salvomic - 05-21-2015, 04:04 PM
RE: Leasing: advance payments - salvomic - 04-23-2016, 05:14 PM



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