RE: Depreciation (SL, DB, SOYD)
With this news version now it's possible to calculate the depreciation tables (SL, DB, SOYD) also for partial year (i.e. in the first year the asset is bought only for 6 months).
With the DB method is now also possible to calculate the " crossover" or authomatically switching to SL (to switch from declining balance to straight-line depreciation at some point).
The program, like the HP 12C, calculates the optimum crossover point and automatically switches to straight-line depreciation at the appropriate time ( the crossover point is the end of the year in which the declining-balance depreciation last exceeds or equals the amount of straight-line depreciation..., Font: HP 12C User Guide)
Code:
#pragma mode(separator(.,;) integer(h32))
export D_SLmat:=[0,0,0,0];
export D_DBmat:=[0,0,0,0,0];
export D_SOYDmat:=[0,0,0,0,0,0];
export D_DBendRate:=0;
smenu();
sl();
dbal();
soyd();
ins_data();
cfa; rv; ula, mm;
EXPORT Depreciation()
BEGIN
ins_data();
// Depreciation with method of Straight Line, Declining Balance, Sum of the Year Digits
// Ammortamento con metodi Lineare, A quote proporzionali e Somma delle cifre dell'anno (americano)
smenu();
END;
ins_data()
BEGIN
local mt, lab1:=" ", lab2:=" ";
input ({ {cfa, [0], {15,15,1}},
{rv, [0], {50,15,1}}, {ula, [0], {80,15,1}},
{mm, [0], {20,10,3}},
{mt, {"SL ", "DB ", "SOYD"}, {75,20,3}}, {lab1,[2], {15, 80, 4}}, {lab2,[2], {15, 80, 5}} },
"Depreciation",
{"Cost", "ResVal", "Years", "Mth 1y", "Method", "SL DB", "SOYD" },
{"Cost of fixed asset", "Residual value",
"Useful life of asset (year)", "Months of first year", "Method of depreciation",
"Methods to calculate depreciation","Methods to calculate depreciation" },
{0,0,1,12, 0, "", ""},
{1000, 100, 5, 12, 3, "Straight Line - Declining Balance", "Sum of the Year Digits"} );
IF mm<0 THEN mm:=12; END; IF mm>12 THEN mm:=12; END;
CASE
IF mt==1 THEN sl(); END;
IF mt==2 THEN dbal(); END;
IF mt==3 THEN soyd(); END;
DEFAULT
END; // case
RETURN;
END;
EXPORT labelmat()
BEGIN
RECT_P();
TEXTOUT_P("Labels of the tables", 85, 10, 5, RGB(255, 0, 0));
LINE_P(10,35,300,35, RGB(0,0,255));
TEXTOUT_P("SL: Straight Line method", 10, 45, 3, RGB(0,0,0),210, RGB(0,255,0));
TEXTOUT_P("| Depr. expence | Accumul. dep. at year-end |", 5, 65);
TEXTOUT_P("| Book value at year-end | Remaining value |", 5, 80);
TEXTOUT_P("DB: Declining Balance method", 10, 100, 3, RGB(0,0,0),210, RGB(0,255,0));
TEXTOUT_P("| Dep. rate | D. expence | Accum. d. y-end |", 5, 115);
TEXTOUT_P("| Book value at year-end | Remaining value |", 5, 130);
TEXTOUT_P("SOYD: Sum of the Years Digits method", 10, 150, 3, RGB(0,0,0),250, RGB(0,255,0));
TEXTOUT_P("| Depreciation Base | Dep. rate | D. expence |", 5, 165);
TEXTOUT_P("| Accumulated dep. y-end | Book val y-end |", 5, 180);
TEXTOUT_P("| Remaining value |", 5, 195);
BLIT_P(G1);
WAIT;
smenu();
END;
sl()
BEGIN
// Straight Line
// cfa = cost of fix assets, rv = residual value, ula = useful life of assets (years)
// ade = annual depreciation expence, dr = depreciation rate
// adye = accumulated depreciation at year-end, bvye = book value at year-end
local ade, dr, j;
local slmat;
slmat:= MAKEMAT(0,1,4);
ade:= (cfa-rv)/ula;
dr:= ade/(cfa-rv);
slmat(1,1):=ROUND(ade*mm/12, 3); slmat(1,2):=ROUND(ade*mm/12, 3);
slmat(1,3):=ROUND(cfa-ade*mm/12, 3); slmat(1,4):= slmat(1,3) - rv;
FOR j FROM 2 TO ula DO
slmat(j,1):= ade;
slmat(j,2):= slmat(j-1,2) + ade;
slmat(j,3):= cfa - slmat(j,2);
slmat(j,4):= slmat(j,3) - rv;
END; // for
IF mm<12 THEN
slmat(ula+1,1):= ade - slmat(1,1); slmat(ula+1,2):= slmat(ula,2) + slmat(ula+1,1);
slmat(ula+1,3):= slmat(ula,3) - slmat(ula+1,1); slmat(ula+1,4):= slmat(ula,4) - slmat(ula+1,1);
END;
sto(slmat, D_SLmat);
RECT_P();
TEXTOUT_P("Depreciation w/ Straight Line method ", 25, 20, 3, RGB(255,0,0));
TEXTOUT_P("Depreciation expence " + EVAL(ade), 25, 50);
TEXTOUT_P("Depreciation expence 1st year " + (ROUND(ade*mm/12, 3)), 25, 70);
TEXTOUT_P("Depreciation rate " + EVAL(dr*100) + "%", 25, 90);
TEXTOUT_P("Table esported in matrix D_SLmat ", 25, 120, 3, RGB(0,0, 255));
TEXTOUT_P("Press ESC key to continue", 25, 140, 3);
WAIT;
RETURN;
END;
dbal()
BEGIN
// Declining Balance
// drate = depreciation rate for full depreciation by the end
local ade, adesl, dr, drsl, dbr, j, k;
local dbmat, drate, pass, passover, temp;
INPUT({ {dbr,[0],{15,15,1}}, {pass,0, {80,2,1}} }, "Pass from DB to SL at ending",
{"DBr%", "DB-SL"}, {"DB rate (default 200%)", "DB pass to SL at ending"}, {200,0}, {200,0} );
dbmat:= MAKEMAT(0,1,5);
dr:=((dbr/100)*(cfa-rv)/ula)/(cfa-rv);
drate:= 1- (rv/cfa)^(1/ula);
ade:=cfa*dr;
dbmat(1,1):=dr*100; dbmat(1,2):= ade*mm/12; dbmat(1,3):= dbmat(1,2);
dbmat(1,4):= cfa-ade*mm/12; dbmat(1,5):= dbmat(1,4) - rv;
FOR j FROM 2 TO ula DO
dbmat(j,1):= dr*100;
dbmat(j,2):= dbmat(j-1,4) * dr;
dbmat(j,3):= dbmat(j-1,3) + dbmat(j,2);
dbmat(j,4):= dbmat(j-1,4) - dbmat(j,2);
dbmat(j,5):= dbmat(j,4) - rv;
dbmat(j,1):= ROUND(dbmat(j,1),2);
dbmat(j,2):= ROUND(dbmat(j,2),3);
dbmat(j,3):= ROUND(dbmat(j,3),3);
dbmat(j,4):= ROUND(dbmat(j,4),3);
dbmat(j,5):= ROUND(dbmat(j,5),3);
IF pass==1 THEN temp:= (dbmat(j,4)/(ula-j+(12-mm)/12))>=dbmat(j,2); ELSE temp:=1; END;
// temp to avoid division by 0
IF pass==(1 AND temp) THEN
passover:=j;
adesl:= dbmat(j,5)/(ula-passover+(12-mm)/12);
drsl:= ROUND(100*(adesl/dbmat(j,5)),2);
FOR k FROM passover+1 TO ula DO
dbmat(k,1):= drsl;
dbmat(k,2):= adesl;
dbmat(k,3):= dbmat(k-1,3) + adesl;
dbmat(k,4):= cfa - dbmat(k,3);
dbmat(k,5):= dbmat(k,4) - rv;
END; // for
dbmat(ula+1,1):= drsl;
dbmat(ula+1,2):= dbmat(ula,5);
dbmat(ula+1,3):= dbmat(ula,3) + dbmat(ula+1,2);
dbmat(ula+1,4):= dbmat(ula,4) - dbmat(ula+1,2);
dbmat(ula+1,5):= dbmat(ula+1,4) - rv;
BREAK (1);
END; // if
END; // for
dbmat(1,1):=ROUND(dbmat(1,1),2); dbmat(1,2):=ROUND(dbmat(1,2),3);
dbmat(1,3):=ROUND(dbmat(1,3),3); dbmat(1,4):=ROUND(dbmat(1,4),3);
dbmat(1,5):=ROUND(dbmat(1,5),3);
IF pass==0 THEN // normal case (no passover)
dbmat(ula,1):= ROUND(((dbmat(ula-1,4) - rv)/dbmat(ula-1,4))*100,2);
dbmat(ula,2):= dbmat(ula-1,4) - rv;
dbmat(ula,3):= dbmat(ula-1,3) + dbmat(ula,2);
dbmat(ula,4):= rv;
dbmat(ula,5):= dbmat(ula,4) - rv;
END; // if
sto(dbmat, D_DBmat);
sto(drate, D_DBendRate);
RECT_P();
TEXTOUT_P("Depreciation w/ Declining Balance method ", 25, 20, 3, RGB(255,0,0));
TEXTOUT_P("Depreciation expense " + EVAL(ade), 25, 50);
TEXTOUT_P("Depreciation rate " + EVAL(dr*100) + "%", 25, 70);
IF pass==1 THEN
TEXTOUT_P("Depr. expense w/ SL " + adesl, 25, 90);
TEXTOUT_P("Passover DB->SL at " + EVAL(passover) + "th year", 25, 110);
END;
TEXTOUT_P("Table esported in matrix D_DBmat", 25, 150, 3, RGB(0,0, 255));
TEXTOUT_P("Press ESC key to continue", 25, 170, 3);
WAIT;
RETURN;
END;
soyd()
BEGIN
// Sum of the Year Digits, "Ammortamento americano"
local ade, dr, soyd;
local sdmat, dbs, j;
sdmat:= MAKEMAT(0,1,6);
soyd:= ((ula^2)+ula)/2;
dbs:= cfa-rv;
sdmat(1,1):= dbs; sdmat(1,2):= (ula/soyd)*mm/12; sdmat(1,3):= sdmat(1,1)*sdmat(1,2);
sdmat(1,4):= sdmat(1,3); sdmat(1,5):= cfa - sdmat(1,4);
sdmat(1,6):= sdmat(1,5) - rv;
FOR j FROM 2 to ula DO
sdmat(j,1):= dbs;
sdmat(j,2):= (((ula+1-j)/soyd)*mm/12)+(((12-mm)/12)*(ula+2-j)/soyd);
sdmat(j,3):= sdmat(j,1)*sdmat(j,2);
sdmat(j,4):= sdmat(j-1,4)+sdmat(j,3);
sdmat(j,5):= sdmat(j-1,5)-sdmat(j,3);
sdmat(j,6):= sdmat(j,5) - rv;
sdmat(j,2):= ROUND(sdmat(j,2),2);
sdmat(j,3):= ROUND(sdmat(j,3),3);
sdmat(j,4):= ROUND(sdmat(j,4),3);
sdmat(j,5):= ROUND(sdmat(j,5),3);
sdmat(j,6):= ROUND(sdmat(j,6),3);
END; // for
IF mm<12 THEN
sdmat(ula+1,1):=dbs;
sdmat(ula+1,2):= (((ula+1-j)/soyd)*mm/12)+(((12-mm)/12)*(ula+2-j)/soyd);
sdmat(ula+1,3):= sdmat(ula+1,1)*sdmat(ula+1,2);
sdmat(ula+1,4):= sdmat(ula,4)+sdmat(ula+1,3);
sdmat(ula+1,5):= sdmat(ula,5)-sdmat(ula+1,3);
sdmat(ula+1,6):= sdmat(ula+1,5) - rv;
sdmat(ula+1,1):= ROUND(sdmat(ula+1,1),2); sdmat(ula+1,2):=ROUND(sdmat(ula+1,2),2);
sdmat(ula+1,3):= ROUND(sdmat(ula+1,3),3); sdmat(ula+1,4):=ROUND(sdmat(ula+1,4),3);
sdmat(ula+1,5):= ROUND(sdmat(ula+1,5),3); sdmat(ula+1,6):=ROUND(sdmat(ula+1,6),3);
END;
sdmat(1,1):= ROUND(sdmat(1,1),2); sdmat(1,2):=ROUND(sdmat(1,2),2);
sdmat(1,3):= ROUND(sdmat(1,3),3); sdmat(1,4):=ROUND(sdmat(1,4),3);
sdmat(1,5):= ROUND(sdmat(1,5),3); sdmat(1,6):=ROUND(sdmat(1,6),3);
sto(sdmat, D_SOYDmat);
RECT_P();
TEXTOUT_P("Depreciation Sum of the Year Digits method ", 25, 20, 3, RGB(255,0,0));
TEXTOUT_P("Sum of the year digits " + EVAL(soyd), 25, 50);
TEXTOUT_P("Depreciation rate " + EVAL(ula) + "/" + EVAL(soyd) + " ∷ 1/" + EVAL(soyd) , 25, 70);
TEXTOUT_P("Table esported in matrix D_SOYDmat", 25, 100, 3, RGB(0,0, 255));
TEXTOUT_P("Press ESC key to continue", 25, 120, 3);
WAIT;
RETURN;
END;
smenu()
BEGIN
local ch;
CHOOSE(ch, "Method of Depreciation", "Labels of tables", "Another calculation?", "Quit");
CASE
IF ch==1 THEN labelmat(); END;
IF ch==2 THEN Depreciation(); 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
|